Fix syscall interface and file header to actually work.
authorDavid Given <dg@cowlark.com>
Sun, 28 Jun 2015 22:01:25 +0000 (00:01 +0200)
committerDavid Given <dg@cowlark.com>
Sun, 28 Jun 2015 22:01:25 +0000 (00:01 +0200)
Library/libs/crt0_msp430x.s
Library/libs/fuzixmsp430x/syscall.s
Library/tools/syscall_msp430x.c

index 4d3bfa3..d90e03d 100644 (file)
@@ -2,16 +2,16 @@
 .globl _start
 _start:
        jmp 1f                             ; two bytes
-       .byte 0                            ; one byte of padding
+       .byte 0                            ; two bytes of padding
        .byte 'F', 'Z', 'X', '1'           ; magic starts at 0x8003
 
-       .word 0 ; chmem
+       .byte 0x80                         ; page to start at
+       .word 0                            ; chmem (0 means 'all')
        .word __data_start
-       .word __data_end
-       .word __bss_end
+       .word __data_len
+       .word __bss_len
        .word 0 ; spare
 
-       .align 2
 1:
        ; Wipe BSS.
        mov #__bss_start, r12
index 2f2b789..6fbb0fd 100644 (file)
@@ -5,11 +5,11 @@ _syscall:
         ; On entry, the syscall number is in r11 and the four parameters in
         ; r12-r15 (luckily, these are all caller saved).
         calla &(_start-4)
-        ; On exit from the kernel, the result in r12 is either 0 or an errno.
-        tst r12
+        ; On exit from the kernel, the result is in r12 and r13 is an errno.
+        tst r13
         jz 1f
                ; Error path.
-        mov r12, &errno
+        mov r13, &errno
         mov #-1, r12
 1:
         ret
index 9d7289c..b229f71 100644 (file)
@@ -22,6 +22,14 @@ static void write_call(int n)
              "\t.globl _syscall\n"
              "\t.globl %1$s\n\n"
              "%1$s:\n", syscall_name[n]);
+  if (syscall_args[n] == VARARGS)
+  {
+       /* Varargs syscalls have the first argument in r12 and the others on
+        * the stack. We support up to four parameters. */
+       fprintf(fp, "\tmov 2(sp), r13\n"
+                   "\tmov 4(sp), r14\n"
+                               "\tmov 6(sp), r15\n");
+  }
   fprintf(fp, "\tmov #%d, r11\n"
               "\tbr #_syscall\n",
                          n);