diff --git a/sys/bootstrap/CMakeLists.txt b/sys/bootstrap/CMakeLists.txt index 5381979..8e3b73e 100644 --- a/sys/bootstrap/CMakeLists.txt +++ b/sys/bootstrap/CMakeLists.txt @@ -5,7 +5,7 @@ set_property(SOURCE ${arch_sources} PROPERTY LANGUAGE C) add_executable(bootstrap ${c_sources} ${arch_sources}) -target_link_libraries(bootstrap libmango ulibc liblaunch libmsg-fs) +target_link_libraries(bootstrap libmango ulibc liblaunch interface::fs) target_compile_options(bootstrap PRIVATE -fPIC -pie -fno-stack-protector -nostdlib -ffreestanding) diff --git a/sys/bootstrap/arch/x86_64/start.S b/sys/bootstrap/arch/x86_64/start.S index 45ef52b..f600396 100644 --- a/sys/bootstrap/arch/x86_64/start.S +++ b/sys/bootstrap/arch/x86_64/start.S @@ -6,10 +6,12 @@ .extern main .type main, @function -.extern exit -.type exit, @function +.extern task_exit +.type task_exit, @function _start: call main + mov %rax, %rdi + call task_exit 1: pause jmp 1b diff --git a/sys/bootstrap/main.c b/sys/bootstrap/main.c index 56960e1..751c5ed 100644 --- a/sys/bootstrap/main.c +++ b/sys/bootstrap/main.c @@ -1,3 +1,5 @@ +#define MSG_IMPLEMENTATION +#define MSG_NO_MALLOC #include "tar.h" #include @@ -5,8 +7,7 @@ #include #include #include -#include -#include +#include #include #include @@ -46,6 +47,31 @@ static enum launch_status resolve_dependency( return LAUNCH_OK; } +static kern_status_t open(const char *path, int flags, int *out_err) +{ + kern_logf("received msg: open(%s, %d)", path, flags); + *out_err = 13; + return KERN_OK; +} + +static kern_status_t uppercase(const char *old, struct msg_string *new) +{ + kern_logf("received msg: uppercase(%s)", old); + size_t i; + for (i = 0; old[i] && i < new->str_max - 1; i++) { + char c = old[i]; + if (c >= 'a' && c <= 'z') { + new->str_buf[i] = old[i] - 'a' + 'A'; + } else { + new->str_buf[i] = old[i]; + } + } + + new->str_len = i - 1; + new->str_buf[i] = 0; + return KERN_OK; +} + int main( int argc, const char **argv, @@ -98,48 +124,29 @@ int main( = launch_ctx_execute(&launch, ¶ms, LAUNCH_F_NONE, &result); kern_logf("launch result: %d", status); + const struct fs_vtable fs_vtable = { + .open = open, + .uppercase = uppercase, + }; #if 1 while (1) { msgid_t id; - struct rosetta_msg msg; - kern_status_t status = rosetta_msg_recv(channel, &id, &msg); + struct msg_header hdr; + kern_status_t status = msg_recv_generic(channel, &id, &hdr); if (status != KERN_OK) { kern_logf("message recv error %d", status); continue; } - if (msg.msg_protocol != ROSETTA_MSG_FS) { + if (hdr.hdr_protocol != PROTOCOL_FS) { kern_logf( "unknown message protocol %u", - msg.msg_protocol); + hdr.hdr_protocol); continue; } - if (msg.msg_id != ROSETTA_MSG_FS_OPEN) { - kern_logf("unknown message function %u", msg.msg_id); - continue; - } - - char path[4096]; - int flags; - struct rosetta_msg_string path_str = { - .s_buf = path, - .s_max = sizeof path, - }; - status = rosetta_msg_fs_open_recv( - channel, - id, - &path_str, - &flags); - if (status != KERN_OK) { - kern_logf("rosetta.fs.open recv error %d", status); - continue; - } - - kern_logf("open(%s, %d)", path, flags); - - rosetta_msg_fs_open_reply(channel, id, 0); + status = fs_dispatch(channel, &fs_vtable, id, &hdr); } #endif