diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/app/ext2fs/main.c | 3 | ||||
-rw-r--r-- | src/user/app/init/driver/initctl.c | 4 | ||||
-rw-r--r-- | src/user/app/init/init.c | 22 | ||||
-rw-r--r-- | src/user/app/shell/shell.c | 1 | ||||
-rw-r--r-- | src/user/lib/_start2.c | 4 | ||||
-rw-r--r-- | src/user/lib/include/unistd.h | 3 | ||||
-rw-r--r-- | src/user/lib/intr.s | 20 | ||||
-rw-r--r-- | src/user/lib/syscall.c | 8 | ||||
-rw-r--r-- | src/user/lib/unistd.c | 11 |
9 files changed, 71 insertions, 5 deletions
diff --git a/src/user/app/ext2fs/main.c b/src/user/app/ext2fs/main.c index f6d65cc..65e7460 100644 --- a/src/user/app/ext2fs/main.c +++ b/src/user/app/ext2fs/main.c @@ -12,6 +12,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> struct handle { uint32_t n; @@ -191,6 +192,8 @@ err: int main(int argc, char **argv) { + intr_set(NULL); + if (argc < 2) errx(1, "bad usage"); // TODO pread/pwrite for normal handles FILE *disk = fopen(argv[1], "r+"); diff --git a/src/user/app/init/driver/initctl.c b/src/user/app/init/driver/initctl.c index 76d1b1b..67c8ade 100644 --- a/src/user/app/init/driver/initctl.c +++ b/src/user/app/init/driver/initctl.c @@ -29,7 +29,9 @@ void initctl_drv(handle_t killswitch) { } if (!strcmp(buf, "halt")) { _syscall_write(killswitch, "halt", 4, 0, 0); - exit(1); + } + if (!strcmp(buf, "intr")) { + _syscall_write(killswitch, "intr", 4, 0, 0); } c0_fs_respond(NULL, res.len, 0); break; diff --git a/src/user/app/init/init.c b/src/user/app/init/init.c index 350d9a0..0114ac5 100644 --- a/src/user/app/init/init.c +++ b/src/user/app/init/init.c @@ -3,6 +3,7 @@ #include <camellia/syscalls.h> #include <stdint.h> #include <stdio.h> +#include <string.h> #include <unistd.h> #include <camellia/fs/misc.h> @@ -29,7 +30,7 @@ void redirect(const char *exe, const char *out, const char *in) { exit(1); } _syscall_await(); - _syscall_filicide(); + _syscall_intr(); } } } @@ -39,7 +40,7 @@ int main(void) { freopen("/kdev/com1", "a+", stdout); freopen("/kdev/com1", "a+", stderr); - printf("in init (stage 2), main at %p\n", &main); + printf("[init] stage 2, main at %p\n", &main); MOUNT_AT("/keyboard") { MOUNT_AT("/") { fs_whitelist((const char*[]){"/kdev/ps2/kb", NULL}); } @@ -104,7 +105,22 @@ int main(void) { exit(1); } - _syscall_read(killswitch_pipe[0], NULL, 0, 0); + char buf[128]; + for (;;) { + if (_syscall_read(killswitch_pipe[0], buf, 128, 0) != 4) { + break; + } + if (memcmp(buf, "intr", 4) == 0) { + _syscall_intr(); + } else if (memcmp(buf, "halt", 4) == 0) { + break; + } + } + printf("[init] intr\n"); + _syscall_intr(); + _syscall_sleep(1000); + printf("[init] filicide\n"); _syscall_filicide(); + printf("[init] goodbye\n"); return 0; } diff --git a/src/user/app/shell/shell.c b/src/user/app/shell/shell.c index 3dad1bd..564daa8 100644 --- a/src/user/app/shell/shell.c +++ b/src/user/app/shell/shell.c @@ -144,7 +144,6 @@ static void run(char *cmd) { } } - int main(int argc, char **argv) { static char buf[256]; FILE *f = stdin; diff --git a/src/user/lib/_start2.c b/src/user/lib/_start2.c index ba3b6b0..495f046 100644 --- a/src/user/lib/_start2.c +++ b/src/user/lib/_start2.c @@ -17,9 +17,13 @@ const char *shortname(const char *path) { return path; } +void intr_trampoline(void); /* intr.s */ + _Noreturn void _start2(struct execdata *ed) { const char *progname; elf_selfreloc(); + _syscall_intr_set(intr_trampoline); + intr_set(intr_default); __setinitialcwd(ed->cwd); progname = shortname(ed->argv[0]); diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h index f49c337..d13767b 100644 --- a/src/user/lib/include/unistd.h +++ b/src/user/lib/include/unistd.h @@ -26,3 +26,6 @@ size_t absolutepath(char *out, const char *in, size_t size); // TODO put in an internal libc header void __setinitialcwd(const char *c); + +void intr_set(void (*fn)(void)); +void intr_default(void); diff --git a/src/user/lib/intr.s b/src/user/lib/intr.s new file mode 100644 index 0000000..008387d --- /dev/null +++ b/src/user/lib/intr.s @@ -0,0 +1,20 @@ +.section .text +.global intr_trampoline +.type intr_trampoline, @function +intr_trampoline: + push %rax + push %rdx + call *_intr(%rip) + pop %rdx + pop %rax + pop tmprip(%rip) + pop %rsp + jmp *tmprip(%rip) + +.section .bss +tmprip: + .skip 8 + +.global _intr +_intr: + .skip 8 diff --git a/src/user/lib/syscall.c b/src/user/lib/syscall.c index d6ed0af..d42c2ee 100644 --- a/src/user/lib/syscall.c +++ b/src/user/lib/syscall.c @@ -74,6 +74,14 @@ void _syscall_filicide(void) { return (void)_syscall(_SYSCALL_FILICIDE, 0, 0, 0, 0, 0); } +void _syscall_intr(void) { + return (void)_syscall(_SYSCALL_INTR, 0, 0, 0, 0, 0); +} + +void _syscall_intr_set(void __user *ip) { + return (void)_syscall(_SYSCALL_INTR_SET, (long)ip, 0, 0, 0, 0); +} + long _syscall_execbuf(void __user *buf, size_t len) { return _syscall(_SYSCALL_EXECBUF, (long)buf, (long)len, 0, 0, 0); } diff --git a/src/user/lib/unistd.c b/src/user/lib/unistd.c index 01aa94f..cb862f8 100644 --- a/src/user/lib/unistd.c +++ b/src/user/lib/unistd.c @@ -161,3 +161,14 @@ size_t absolutepath(char *out, const char *in, size_t size) { void __setinitialcwd(const char *s) { __initialcwd = s; } + +static void intr_null(void) { } + +extern void (*volatile _intr)(void); +void intr_set(void (*fn)(void)) { + _intr = fn ? fn : intr_null; +} + +void intr_default(void) { + exit(-1); +} |