# HG changeset patch # User anatofuz # Date 1593153042 -32400 # Node ID 3d7e1c9a852ee53724f788ade9c0a577e99be70f # Parent 87a28b02c88f46095fd2bec92e090acf801c824a ... diff -r 87a28b02c88f -r 3d7e1c9a852e .hgignore --- a/.hgignore Tue Jun 23 12:17:25 2020 +0900 +++ b/.hgignore Fri Jun 26 15:30:42 2020 +0900 @@ -18,3 +18,5 @@ .gdb_history .vscode/ + +*.swp diff -r 87a28b02c88f -r 3d7e1c9a852e src/gearsTools/lib/Gears/Context/Template/XV6.pm --- a/src/gearsTools/lib/Gears/Context/Template/XV6.pm Tue Jun 23 12:17:25 2020 +0900 +++ b/src/gearsTools/lib/Gears/Context/Template/XV6.pm Fri Jun 26 15:30:42 2020 +0900 @@ -131,12 +131,20 @@ my $str = << 'EOFEOF'; #define NDIRECT 12 //fs.h +#define NPROC 64 + struct Context { enum Code next; struct Worker* worker; struct TaskManager* taskManager; int codeNum; + + struct Context* kernel_context; + struct proc* proc; + + + __code (**code) (struct Context*); union Data **data; void* heapStart; @@ -162,8 +170,16 @@ int iterate; struct Iterator* iterator; enum Code before; + }; +typedef struct KernelContext { + struct Context Context; + __code (*syscalls[10]) (void); + struct Context* proc_contexts[NPROC]; + struct proc* now_proc; +} KernelContext; + #include "spinlock.h" typedef int Int; #ifndef USE_CUDAWorker diff -r 87a28b02c88f -r 3d7e1c9a852e src/gearsTools/lib/Gears/Util.pm --- a/src/gearsTools/lib/Gears/Util.pm Tue Jun 23 12:17:25 2020 +0900 +++ b/src/gearsTools/lib/Gears/Util.pm Fri Jun 26 15:30:42 2020 +0900 @@ -202,7 +202,7 @@ next; } - if ($line =~ /^\/\/\s*data_gear\s*"(.*)\.(?:h|dg)?"/) { + if ($line =~ /^\/\/\s*include\s*"(.*)\.(?:h|dg)?"/) { push(@{$include_pool{$1}->{$cbc_file}},$.); next; } diff -r 87a28b02c88f -r 3d7e1c9a852e src/main.c --- a/src/main.c Tue Jun 23 12:17:25 2020 +0900 +++ b/src/main.c Fri Jun 26 15:30:42 2020 +0900 @@ -7,11 +7,14 @@ #include "memlayout.h" #include "mmu.h" +#include "kernel.h" + extern void* end; struct cpu cpus[NCPU]; struct cpu *cpu; + #define MB (1024*1024) void kmain (void) @@ -33,7 +36,10 @@ kmem_init (); kmem_init2(P2V(INIT_KERNMAP), P2V(PHYSTOP)); - + + kernel_context = calloc(sizeof(struct Context), 1); + initContext(kernel_context); + trap_init (); // vector table and stacks for models pic_init (P2V(VIC_BASE)); // interrupt controller uart_enable_rx (); // interrupt for uart diff -r 87a28b02c88f -r 3d7e1c9a852e src/proc.cbc --- a/src/proc.cbc Tue Jun 23 12:17:25 2020 +0900 +++ b/src/proc.cbc Fri Jun 26 15:30:42 2020 +0900 @@ -8,6 +8,8 @@ #include "spinlock.h" #interface "vm.h" +#include "kernel.h" + #define __ncode __code // @@ -141,6 +143,7 @@ p = allocproc(); initContext(&p->cbc_context); + p->cbc_context.kernel_context = kernel_context; initproc = p; @@ -219,6 +222,7 @@ return -1; } initContext(&np->cbc_context); + np->cbc_context.kernel_context = kernel_context; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ diff -r 87a28b02c88f -r 3d7e1c9a852e src/syscall.cbc --- a/src/syscall.cbc Tue Jun 23 12:17:25 2020 +0900 +++ b/src/syscall.cbc Fri Jun 26 15:30:42 2020 +0900 @@ -7,7 +7,11 @@ #include "arm.h" #include "syscall.h" +#include "kernel.h" #define __ncode __code + +//include "Trapframe.h" + # // User code makes a system call with INT T_SYSCALL. System call number // in r0. Arguments on the stack, from the user call to the C library @@ -153,8 +157,12 @@ [SYS_cbc_read] = cbc_read, }; +extern __code swtch(struct context **old, struct context *new); + +extern __code trapret(void); + __ncode cbc_trap_return(){ - return; + goto trapret(); } __ncode cbc_ret(int ret){ @@ -176,6 +184,10 @@ num = 22; //cprintf ("syscall(%d) from %s(%d)\n", num, proc->name, proc->pid); + kernel_context->now_proc = proc; + proc->cbc_context.proc = proc; + + if((num >= NELEM(syscalls)) && (num <= NELEM(cbccodes)) && cbccodes[num]) { proc->cbc_arg.cbc_console_arg.num = num; goto (cbccodes[num])(cbc_ret); @@ -197,3 +209,32 @@ proc->tf->r0 = -1; } } + +__ncode cbc_syscall(struct Trapframe* trapframe) { + int num = trapframe->syscall_number; + if (num == 5) + num = 22; + + kernel_context->now_proc = proc; + proc->cbc_context.proc = proc; + + if((num >= NELEM(syscalls)) && (num <= NELEM(cbccodes)) && cbccodes[num]) { + proc->cbc_arg.cbc_console_arg.num = num; + goto (cbccodes[num])(cbc_ret); + //goto meta(&proc->cbc_context, cbccodes[num]); + } + + if((num > 0) && (num < NELEM(syscalls)) && syscalls[num]) { + int ret = syscalls[num](); + + // in ARM, parameters to main (argc, argv) are passed in r0 and r1 + // do not set the return value if it is SYS_exec (the user program + // anyway does not expect us to return anything). + + goto cbc_ret(ret); + + } + + cprintf("%d %s: unknown sys call %d\n", proc->pid, proc->name, num); + goto cbc_ret(-1); +} diff -r 87a28b02c88f -r 3d7e1c9a852e src/trap.c --- a/src/trap.c Tue Jun 23 12:17:25 2020 +0900 +++ b/src/trap.c Fri Jun 26 15:30:42 2020 +0900 @@ -5,6 +5,25 @@ #include "arm.h" #include "proc.h" + +#include "kernel.h" + +extern __code exit(void); + +__code cbc_swi_handler_stub(struct trapframe* r) { + struct Context proc_context = proc->cbc_context; + struct Context kernel = kernel_context; + struct Syscall* syscall = Gearef(kernel, Syscall)->syscall; + goto cbc_swi_handler(proc_context, r, syscall); +} + +__code cbc_swi_handler(struct trapframe* r, struct Syscall* syscall) { + if (proc->killed) + goto exit(); + proc->tf = r; + goto syscall->perform(); +} + // trap routine void swi_handler (struct trapframe *r) { diff -r 87a28b02c88f -r 3d7e1c9a852e src/usr/CMakeLists.txt --- a/src/usr/CMakeLists.txt Tue Jun 23 12:17:25 2020 +0900 +++ b/src/usr/CMakeLists.txt Fri Jun 26 15:30:42 2020 +0900 @@ -74,7 +74,7 @@ #add_library(syslib string.c) # set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh stressfs usertests wc zombie hello) -set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh hello) +set(USR_COMMANDS cat echo grep init kill ln ls mkdir rm sh hello usertests) foreach(cmd ${USR_COMMANDS}) GearsCommand (TARGET _${cmd} SOURCES ${cmd}.c)