User processes start running; they can call back to the kernel via the
authorDavid Given <dg@cowlark.com>
Sat, 27 Jun 2015 11:42:30 +0000 (13:42 +0200)
committerDavid Given <dg@cowlark.com>
Sat, 27 Jun 2015 11:42:30 +0000 (13:42 +0200)
syscall interface.

Kernel/lowlevel-msp430x.c
Kernel/platform-msp430fr5969/crt0.S
Kernel/platform-msp430fr5969/msp430fr5969.ld
Kernel/syscall_exec16.c

index f81ead2..80aca4b 100644 (file)
@@ -1,6 +1,7 @@
 #include <kernel.h>
 #include <kdata.h>
 #include <printf.h>
+#include <stdarg.h>
 #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 (;;);
 }
 
index 628eade..a17f239 100644 (file)
@@ -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
index 03bc485..ec61c9f 100644 (file)
@@ -226,6 +226,10 @@ SECTIONS
     KEEP (*(.dtors))
   } > LOROM
 
+  .syscall : {
+    KEEP (*(.syscall))
+  } > SYSCALL
+
   .lowtext : {
        . = ALIGN(2);
     PROVIDE (_start = .);
index 4837d4f..78be29b 100644 (file)
@@ -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;