[mammoth] Create a method for getting initial caps.

This commit is contained in:
Drew Galbraith 2023-06-16 23:51:49 -07:00
parent 4c936623b5
commit 528723e490
15 changed files with 108 additions and 22 deletions

View file

@ -1,4 +1,5 @@
#include <zcall.h>
#include <zinit.h>
#include "stdlib.h"

View file

@ -1,8 +1,10 @@
add_library(mammoth_lib STATIC
src/channel.cpp
src/debug.cpp
src/init.cpp
src/memory_region.cpp
src/process.cpp
src/port.cpp
src/thread.cpp
)

View file

@ -0,0 +1,11 @@
#pragma once
#include <stdint.h>
#include <zerrors.h>
extern uint64_t gSelfProcCap;
extern uint64_t gSelfVmasCap;
extern uint64_t gBootDenaliVmmoCap;
z_err_t ParseInitPort(uint64_t init_port_cap);

View file

@ -0,0 +1,14 @@
#pragma once
#include <stdint.h>
#include <zerrors.h>
class Port {
public:
Port(uint64_t port_cap);
z_err_t PollForIntCap(uint64_t* msg, uint64_t* cap);
private:
uint64_t port_cap_;
};

38
lib/mammoth/src/init.cpp Normal file
View file

@ -0,0 +1,38 @@
#include "mammoth/init.h"
#include <zinit.h>
#include "mammoth/debug.h"
#include "mammoth/port.h"
uint64_t gSelfProcCap = 0;
uint64_t gSelfVmasCap = 0;
uint64_t gBootDenaliVmmoCap = 0;
z_err_t ParseInitPort(uint64_t init_port_cap) {
Port port(init_port_cap);
z_err_t ret;
uint64_t init_sig, init_cap;
while ((ret = port.PollForIntCap(&init_sig, &init_cap)) != Z_ERR_EMPTY) {
RET_ERR(ret);
switch (init_sig) {
case Z_INIT_PROC_SELF:
dbgln("received proc");
gSelfProcCap = init_cap;
break;
case Z_INIT_VMAS_SELF:
dbgln("received vmas");
gSelfVmasCap = init_cap;
break;
case Z_BOOT_DENALI_VMMO:
dbgln("received denali");
gBootDenaliVmmoCap = init_cap;
break;
default:
dbgln("Unexpected init type %x, continuing.", init_sig);
}
}
return Z_OK;
}

View file

@ -1,6 +1,7 @@
#include "mammoth/memory_region.h"
#include <zcall.h>
#include <zinit.h>
#include "mammoth/debug.h"

22
lib/mammoth/src/port.cpp Normal file
View file

@ -0,0 +1,22 @@
#include "mammoth/port.h"
#include <zcall.h>
#include "mammoth/debug.h"
Port::Port(uint64_t port_cap) : port_cap_(port_cap) {}
z_err_t Port::PollForIntCap(uint64_t *msg, uint64_t *cap) {
uint64_t bytes, caps, type;
RET_ERR(ZPortPoll(port_cap_, sizeof(uint64_t),
reinterpret_cast<uint8_t *>(msg), /* num_caps= */ 1, cap,
&type, &bytes, &caps));
if (bytes != sizeof(uint64_t)) {
return Z_ERR_INVALID;
}
if (caps != 1) {
return Z_ERR_INVALID;
}
return Z_OK;
}

View file

@ -2,6 +2,7 @@
#include <zcall.h>
#include <zerrors.h>
#include <zinit.h>
#include "mammoth/channel.h"
#include "mammoth/debug.h"

View file

@ -1,6 +1,7 @@
#include "mammoth/thread.h"
#include <zcall.h>
#include <zinit.h>
#include "mammoth/debug.h"