Spawn Processes using memory primitives rather than and elf loader.

This allows us to remove the temporary syscall for that style of process
spawn.
This commit is contained in:
Drew Galbraith 2023-06-07 00:04:53 -07:00
parent b06c76e477
commit 23895b5c6c
26 changed files with 403 additions and 94 deletions

View file

@ -6,5 +6,8 @@ _start:
call _exit
_exit:
// EXIT syscall.
mov $1, %rdi
// Return code as a param.
mov %rax, %rsi
syscall

View file

@ -2,6 +2,8 @@
#include <stdint.h>
#include "usr/zcall_internal.h"
uint64_t SysCall0(uint64_t number) {
uint64_t return_code;
asm("syscall" : "=a"(return_code) : "D"(number));
@ -23,18 +25,20 @@ uint64_t SysCall2(uint64_t number, const void* first, const void* second) {
return return_code;
}
uint64_t ZDebug(const char* message) {
return SysCall1(Z_DEBUG_PRINT, message);
void ZProcessExit(uint64_t code) {
SysCall1(Z_PROCESS_EXIT, reinterpret_cast<void*>(code));
}
uint64_t ZProcessSpawnElf(uint64_t cap_id, uint64_t elf_base,
uint64_t elf_size) {
ZProcessSpawnElfReq req{
.cap_id = cap_id,
.elf_base = elf_base,
.elf_size = elf_size,
uint64_t ZProcessSpawn(uint64_t proc_cap, uint64_t* new_proc_cap,
uint64_t* new_as_cap) {
ZProcessSpawnReq req{
.proc_cap = proc_cap,
};
return SysCall1(Z_PROCESS_SPAWN, &req);
ZProcessSpawnResp resp;
uint64_t ret = SysCall2(Z_PROCESS_SPAWN, &req, &resp);
*new_proc_cap = resp.proc_cap;
*new_as_cap = resp.as_cap;
return ret;
}
uint64_t ZThreadCreate(uint64_t proc_cap, uint64_t* thread_cap) {
@ -59,3 +63,29 @@ uint64_t ZThreadStart(uint64_t thread_cap, uint64_t entry, uint64_t arg1,
}
void ZThreadExit() { SysCall0(Z_THREAD_EXIT); }
uint64_t ZAddressSpaceMap(uint64_t as_cap, uint64_t offset, uint64_t mem_cap,
uint64_t* vaddr) {
ZAddressSpaceMapReq req{
.as_cap = as_cap,
.offset = offset,
.mem_cap = mem_cap,
};
ZAddressSpaceMapResp resp;
uint64_t ret = SysCall2(Z_ADDRESS_SPACE_MAP, &req, &resp);
*vaddr = resp.vaddr;
return ret;
}
uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* mem_cap) {
ZMemoryObjectCreateReq req{
.size = size,
};
ZMemoryObjectCreateResp resp;
uint64_t ret = SysCall2(Z_MEMORY_OBJECT_CREATE, &req, &resp);
*mem_cap = resp.mem_cap;
return ret;
}
uint64_t ZDebug(const char* message) {
return SysCall1(Z_DEBUG_PRINT, message);
}

45
zion/usr/zcall_internal.h Normal file
View file

@ -0,0 +1,45 @@
#pragma once
#include <stdint.h>
struct ZProcessSpawnReq {
uint64_t proc_cap;
};
struct ZProcessSpawnResp {
uint64_t proc_cap;
uint64_t as_cap;
};
struct ZThreadCreateReq {
uint64_t proc_cap;
};
struct ZThreadCreateResp {
uint64_t thread_cap;
};
struct ZThreadStartReq {
uint64_t thread_cap;
uint64_t entry;
uint64_t arg1;
uint64_t arg2;
};
struct ZAddressSpaceMapReq {
uint64_t as_cap;
uint64_t offset;
uint64_t mem_cap;
};
struct ZAddressSpaceMapResp {
uint64_t vaddr;
};
struct ZMemoryObjectCreateReq {
uint64_t size;
};
struct ZMemoryObjectCreateResp {
uint64_t mem_cap;
};