From 83e83abf39aa7162ba765f530b3190712c28e68d Mon Sep 17 00:00:00 2001 From: KAAAsS Date: Tue, 18 May 2021 21:49:48 +0800 Subject: [PATCH] finish lab4 --- lab4/.gdbinit | 2 +- lab4/CMakeLists.txt | 2 +- lab4/kernel/ipc/ipc_call.c | 30 +++++++++++++++++++++++------- lab4/kernel/ipc/ipc_return.c | 2 +- lab4/kernel/syscall/syscall.c | 2 ++ lab4/user/lib/spawn.c | 4 ++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lab4/.gdbinit b/lab4/.gdbinit index 38ac1f7..3cb3026 100644 --- a/lab4/.gdbinit +++ b/lab4/.gdbinit @@ -13,4 +13,4 @@ define add-symbol-file-auto end add-symbol-file-auto ./build/kernel.img -add-symbol-file-auto ./user/build/ramdisk/spawn_info.bin +add-symbol-file-auto ./user/build/ramdisk/ipc_reg.bin diff --git a/lab4/CMakeLists.txt b/lab4/CMakeLists.txt index 483fd25..6406c44 100644 --- a/lab4/CMakeLists.txt +++ b/lab4/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.14) set(CMAKE_VERBOSE_MAKEFILE on) -set(CMAKE_BUILD_TYPE "Debug") # "Release" or "Debug" +set(CMAKE_BUILD_TYPE "Release") # "Release" or "Debug" set(CHCORE_PLAT "raspi3") set(CHCORE_ARCH "aarch64") diff --git a/lab4/kernel/ipc/ipc_call.c b/lab4/kernel/ipc/ipc_call.c index 9c130a0..41db1ad 100644 --- a/lab4/kernel/ipc/ipc_call.c +++ b/lab4/kernel/ipc/ipc_call.c @@ -114,19 +114,19 @@ static u64 thread_migrate_to_server(struct ipc_connection *conn, u64 arg) * This command set the sp register, read the file to find which field * of the ipc_connection stores the stack of the server thread? * */ - arch_set_thread_stack(target, LAB4_IPC_BLANK); + arch_set_thread_stack(target, conn->server_stack_top); /** * Lab4 * This command set the ip register, read the file to find which field * of the ipc_connection stores the instruction to be called when switch * to the server? * */ - arch_set_thread_next_ip(target, LAB4_IPC_BLANK); + arch_set_thread_next_ip(target, conn->target->server_ipc_config->callback); /** * Lab4 * The argument set by sys_ipc_call; */ - arch_set_thread_arg(target, LAB4_IPC_BLANK); + arch_set_thread_arg(target, arg); /** * Passing the scheduling context of the current thread to thread of @@ -166,9 +166,10 @@ u64 sys_ipc_call(u32 conn_cap, ipc_msg_t * ipc_msg) /** * Lab4 - * Here, you need to transfer all the capbiliies of client thread to - * capbilities in server thread in the ipc_msg. + * Here, you need to transfer all the capabilities of client thread to + * capabilities in server thread in the ipc_msg. */ + ipc_send_cap(conn, ipc_msg); r = copy_to_user((char *)&ipc_msg->server_conn_cap, (char *)&conn->server_conn_cap, sizeof(u64)); @@ -180,7 +181,8 @@ u64 sys_ipc_call(u32 conn_cap, ipc_msg_t * ipc_msg) * The arg is actually the 64-bit arg for ipc_dispatcher * Then what value should the arg be? * */ - arg = LAB4_IPC_BLANK; + arg = (u64) ipc_msg; + arg = arg - conn->buf.client_user_addr + conn->buf.server_user_addr; thread_migrate_to_server(conn, arg); BUG("This function should never\n"); @@ -196,5 +198,19 @@ u64 sys_ipc_call(u32 conn_cap, ipc_msg_t * ipc_msg) * */ u64 sys_ipc_reg_call(u32 conn_cap, u64 arg0) { - return -1; + struct ipc_connection *conn = NULL; + int r; + + conn = obj_get(current_thread->process, conn_cap, TYPE_CONNECTION); + if (!conn) { + r = -ECAPBILITY; + goto out_fail; + } + + thread_migrate_to_server(conn, arg0); + + BUG("This function should never\n"); + + out_fail: + return r; } diff --git a/lab4/kernel/ipc/ipc_return.c b/lab4/kernel/ipc/ipc_return.c index 97fbb97..75d9bb5 100644 --- a/lab4/kernel/ipc/ipc_return.c +++ b/lab4/kernel/ipc/ipc_return.c @@ -40,7 +40,7 @@ static int thread_migrate_to_client(struct ipc_connection *conn, u64 ret_value) * Lab4 * The return value returned by server thread; */ - arch_set_thread_return(source, LAB4_IPC_BLANK); + arch_set_thread_return(source, ret_value); /** * Switch to the client */ diff --git a/lab4/kernel/syscall/syscall.c b/lab4/kernel/syscall/syscall.c index acda386..954e7a9 100644 --- a/lab4/kernel/syscall/syscall.c +++ b/lab4/kernel/syscall/syscall.c @@ -90,6 +90,8 @@ const void *syscall_table[NR_SYSCALL] = { [SYS_read_pmo] = sys_read_pmo, [SYS_transfer_caps] = sys_transfer_caps, + [SYS_ipc_reg_call] = sys_ipc_reg_call, + /* TMP FS */ [SYS_fs_load_cpio] = sys_fs_load_cpio, diff --git a/lab4/user/lib/spawn.c b/lab4/user/lib/spawn.c index 72904cd..b9dc7de 100644 --- a/lab4/user/lib/spawn.c +++ b/lab4/user/lib/spawn.c @@ -399,10 +399,10 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, { /* Step C: Output the child process & thread capabilities */ if (child_process_cap != NULL) { - + *child_process_cap = new_process_cap; } if (child_main_thread_cap != NULL) { - + *child_main_thread_cap = main_thread_cap; } }