[mammoth] Create a method for getting initial caps.
This commit is contained in:
parent
4c936623b5
commit
528723e490
|
@ -1,4 +1,5 @@
|
|||
#include <zcall.h>
|
||||
#include <zinit.h>
|
||||
|
||||
#include "stdlib.h"
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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);
|
|
@ -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_;
|
||||
};
|
|
@ -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;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#include "mammoth/memory_region.h"
|
||||
|
||||
#include <zcall.h>
|
||||
#include <zinit.h>
|
||||
|
||||
#include "mammoth/debug.h"
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <zcall.h>
|
||||
#include <zerrors.h>
|
||||
#include <zinit.h>
|
||||
|
||||
#include "mammoth/channel.h"
|
||||
#include "mammoth/debug.h"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "mammoth/thread.h"
|
||||
|
||||
#include <zcall.h>
|
||||
#include <zinit.h>
|
||||
|
||||
#include "mammoth/debug.h"
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <mammoth/debug.h>
|
||||
#include <zcall.h>
|
||||
#include <zinit.h>
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
|
@ -1,27 +1,19 @@
|
|||
#include <denali/denali.h>
|
||||
#include <mammoth/channel.h>
|
||||
#include <mammoth/debug.h>
|
||||
#include <mammoth/init.h>
|
||||
#include <mammoth/process.h>
|
||||
#include <zcall.h>
|
||||
#include <zinit.h>
|
||||
|
||||
#include "hw/pcie.h"
|
||||
|
||||
uint64_t main(uint64_t port_cap) {
|
||||
dbgln("Yellowstone Initializing.");
|
||||
uint64_t msg_type, type, cap, bytes, caps;
|
||||
check(ZPortRecv(port_cap, 8, reinterpret_cast<uint8_t*>(&msg_type), 1, &cap,
|
||||
&type, &bytes, &caps));
|
||||
uint64_t vmmo_cap = 0;
|
||||
if (bytes != 8 || caps != 1) {
|
||||
crash("Invalid boot msg", Z_ERR_INVALID);
|
||||
}
|
||||
if (msg_type == Z_INIT_BOOT_VMMO) {
|
||||
vmmo_cap = cap;
|
||||
} else {
|
||||
crash("Missing vmmo cap", Z_ERR_UNIMPLEMENTED);
|
||||
}
|
||||
check(ParseInitPort(port_cap));
|
||||
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, vmmo_cap, &vaddr));
|
||||
check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, gBootDenaliVmmoCap, &vaddr));
|
||||
|
||||
Channel local;
|
||||
check(SpawnProcessFromElfRegion(vaddr, local));
|
||||
|
@ -35,7 +27,7 @@ uint64_t main(uint64_t port_cap) {
|
|||
reinterpret_cast<uint8_t*>(&read), 0, nullptr));
|
||||
|
||||
DenaliReadResponse resp;
|
||||
uint64_t mem_cap;
|
||||
uint64_t mem_cap, type, bytes, caps;
|
||||
|
||||
check(ZChannelRecv(local.cap(), sizeof(resp),
|
||||
reinterpret_cast<uint8_t*>(&resp), 1, &mem_cap, &type,
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
#define ZC_PROC_SPAWN_PROC 0x100
|
||||
#define ZC_PROC_SPAWN_THREAD 0x101
|
||||
|
||||
#define Z_INIT_PROC_SELF 0x1
|
||||
|
||||
// Thread Calls.
|
||||
#define Z_THREAD_CREATE 0x10
|
||||
#define Z_THREAD_START 0x11
|
||||
|
@ -28,15 +26,11 @@
|
|||
#define Z_ADDRESS_SPACE_MAP 0x21
|
||||
#define Z_ADDRESS_SPACE_UNMAP 0x22
|
||||
|
||||
#define Z_INIT_VMAS_SELF 0x20
|
||||
|
||||
#define Z_MEMORY_OBJECT_CREATE 0x30
|
||||
#define Z_MEMORY_OBJECT_CREATE_PHYSICAL 0x31
|
||||
|
||||
#define Z_TEMP_PCIE_CONFIG_OBJECT_CREATE 0x3F
|
||||
|
||||
#define Z_INIT_BOOT_VMMO 0x31
|
||||
|
||||
// IPC Calls
|
||||
#define Z_CHANNEL_CREATE 0x40
|
||||
#define Z_CHANNEL_SEND 0x41
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#define Z_INIT_PROC_SELF 0x00
|
||||
#define Z_INIT_VMAS_SELF 0x01
|
||||
|
||||
#define Z_BOOT_DENALI_VMMO 0x1000
|
|
@ -3,6 +3,7 @@
|
|||
#include "boot/boot_info.h"
|
||||
#include "debug/debug.h"
|
||||
#include "include/zcall.h"
|
||||
#include "include/zinit.h"
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "memory/paging_util.h"
|
||||
#include "object/process.h"
|
||||
|
@ -71,7 +72,7 @@ uint64_t LoadElfProgram(Process& dest_proc, uint64_t base, uint64_t offset) {
|
|||
program.type, program.flags, program.offset, program.vaddr,
|
||||
program.paddr, program.filesz, program.memsz, program.align);
|
||||
#endif
|
||||
auto mem_obj = MakeRefCounted<MemoryObject>(program.filesz);
|
||||
auto mem_obj = MakeRefCounted<MemoryObject>(program.memsz);
|
||||
mem_obj->CopyBytesToObject(base + program.offset, program.filesz);
|
||||
dest_proc.vmas()->MapInMemoryObject(program.vaddr, mem_obj);
|
||||
}
|
||||
|
@ -137,7 +138,7 @@ void LoadInitProgram() {
|
|||
auto port = MakeRefCounted<Port>();
|
||||
uint64_t port_cap = proc->AddNewCapability(port, ZC_READ | ZC_WRITE);
|
||||
|
||||
uint64_t vmmo_id = Z_INIT_BOOT_VMMO;
|
||||
uint64_t vmmo_id = Z_BOOT_DENALI_VMMO;
|
||||
ZMessage vmmo_msg{
|
||||
.type = 0,
|
||||
.num_bytes = 8,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "debug/debug.h"
|
||||
#include "include/zcall.h"
|
||||
#include "include/zinit.h"
|
||||
#include "memory/paging_util.h"
|
||||
#include "memory/physical_memory.h"
|
||||
#include "object/thread.h"
|
||||
|
|
Loading…
Reference in New Issue