diff --git a/sys/bootstrap/main.c b/sys/bootstrap/main.c index a84a1ef..ecf746e 100644 --- a/sys/bootstrap/main.c +++ b/sys/bootstrap/main.c @@ -5,11 +5,13 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -90,6 +92,45 @@ static void _fs_free(struct fs_allocator *alloc, void *p) heap_free(alloc->fs_arg, p); } +static enum fs_status std_write( + struct fs_file *f, + const xpc_buffer_t *buf, + size_t count, + off_t *seek) +{ + char data[1024]; + xpc_buffer_read(buf, 0, data, sizeof data, NULL); + if (count > sizeof data - 1) { + count = sizeof data - 1; + } + + data[count] = 0; + if (data[count - 1] == '\n') { + data[count - 1] = 0; + } + kern_log(data); + + *seek += count; + return FS_SUCCESS; +} + +static const struct fs_file_ops stdio_ops = { + .f_write = std_write, +}; + +static void create_stdio(struct fs_context *ctx, kern_handle_t out[3]) +{ + for (int i = 0; i < 3; i++) { + port_create(&out[i]); + kern_object_info_t info; + kern_object_query(out[i], &info); + struct fs_file *file = fs_context_open_file(ctx, info.obj_id); + fs_file_set_ops(file, &stdio_ops); + + port_connect(out[i], 0, 0); + } +} + int main( int argc, const char **argv, @@ -163,17 +204,6 @@ int main( launch_ctx_init(&launch); launch.ctx_resolve_library = resolve_dependency; - enum launch_status status - = launch_ctx_execute(&launch, ¶ms, LAUNCH_F_NONE, &result); - if (status != KERN_OK) { - kern_logf("failed to start init: %d", status); - return -1; - } - - kern_handle_close(result.r_task); - kern_handle_close(result.r_thread); - kern_handle_close(result.r_address_space); - heap_t heap = HEAP_INIT; struct fs_allocator fs_allocator = { @@ -190,6 +220,19 @@ int main( return -1; } + create_stdio(fs, params.p_stdio); + + enum launch_status status + = launch_ctx_execute(&launch, ¶ms, LAUNCH_F_NONE, &result); + if (status != KERN_OK) { + kern_logf("failed to start init: %d", status); + return -1; + } + + kern_handle_close(result.r_task); + kern_handle_close(result.r_thread); + kern_handle_close(result.r_address_space); + fs_context_set_channel(fs, channel); enum fs_status fs_status = fs_context_mount_filesystem( fs,