From: David Given Date: Sat, 27 Jun 2015 11:42:30 +0000 (+0200) Subject: User processes start running; they can call back to the kernel via the X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b9a20463deb461d4a18d6ada101aa4b8c4065c39;p=FUZIX.git User processes start running; they can call back to the kernel via the syscall interface. --- diff --git a/Kernel/lowlevel-msp430x.c b/Kernel/lowlevel-msp430x.c index f81ead25..80aca4b3 100644 --- a/Kernel/lowlevel-msp430x.c +++ b/Kernel/lowlevel-msp430x.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "iomacros.h" #include "intrinsics.h" @@ -11,7 +12,40 @@ __interrupt void interrupt_handler(void) void doexec(uaddr_t start_addr) { - kprintf("exec %lx\n", start_addr); + di(); + udata.u_insys = 0; + + asm volatile( + "mov %0, sp\n" + "eint\n" + "br %1\n" + : + : "g" (udata.u_isp), + "g" (start_addr)); +} + +__attribute__ ((naked)) void unix_syscall_entry(void) +{ + asm volatile ( + "mov.b r11, %0\n" + "mov r12, %1\n" + "mov r13, %2\n" + "mov r14, %3\n" + "mov r15, %4\n" + "jmp unix_syscall_main\n" + : "=m" (udata.u_callno), + "=m" (udata.u_argn), + "=m" (udata.u_argn1), + "=m" (udata.u_argn2), + "=m" (udata.u_argn3) + : + ); +} + +void unix_syscall_main(void) +{ + kprintf("syscall %d(%x, %x, %x, %x)!\n", udata.u_callno, + udata.u_argn, udata.u_argn1, udata.u_argn2, udata.u_argn3); for (;;); } diff --git a/Kernel/platform-msp430fr5969/crt0.S b/Kernel/platform-msp430fr5969/crt0.S index 628eade5..a17f2390 100644 --- a/Kernel/platform-msp430fr5969/crt0.S +++ b/Kernel/platform-msp430fr5969/crt0.S @@ -91,6 +91,9 @@ proc irqrestore bis.w r12, SR ; Mask in saved value reta +.section ".syscall", "ax", @progbits + .long unix_syscall_entry + .section "__interrupt_vector_reset", "ax", @progbits .word __main .text diff --git a/Kernel/platform-msp430fr5969/msp430fr5969.ld b/Kernel/platform-msp430fr5969/msp430fr5969.ld index 03bc4853..ec61c9f8 100644 --- a/Kernel/platform-msp430fr5969/msp430fr5969.ld +++ b/Kernel/platform-msp430fr5969/msp430fr5969.ld @@ -226,6 +226,10 @@ SECTIONS KEEP (*(.dtors)) } > LOROM + .syscall : { + KEEP (*(.syscall)) + } > SYSCALL + .lowtext : { . = ALIGN(2); PROVIDE (_start = .); diff --git a/Kernel/syscall_exec16.c b/Kernel/syscall_exec16.c index 4837d4fa..78be29be 100644 --- a/Kernel/syscall_exec16.c +++ b/Kernel/syscall_exec16.c @@ -28,6 +28,10 @@ static int bload(inoptr i, uint16_t bl, uint16_t base, uint16_t len) udata.u_offset = (off_t)blk << 9; udata.u_count = 512; udata.u_base = (uint8_t *)base; + + /* This is necessary on the MSP430. Why??? */ + *(uint8_t volatile*)base; + if (cdread(i->c_dev, 0) < 0) { kputs("bload failed.\n"); return -1;