]> git.buserror.net Git - polintos/scott/priv.git/blobdiff - kernel/arch/x86/entry.S
Change x86 syscalls to direct branches, and define abi for additional syscalls.
[polintos/scott/priv.git] / kernel / arch / x86 / entry.S
index 3cbed22245fb5d2ea17e34b4096e5009df6e688a..8d4ede48ad2309d117979c0533b7095ca29ff99b 100644 (file)
@@ -2,30 +2,24 @@
 //
 // This software is copyright (c) 2006 Scott Wood.
 // 
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal with
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-// of the Software, and to permit persons to whom the Software is furnished to do
-// so, subject to the following condition:
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors or contributors be held liable for any damages
+// arising from the use of this software.
 // 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-// SOFTWARE.
+// Permission is hereby granted to everyone, free of charge, to use, copy,
+// modify, prepare derivative works of, publish, distribute, perform,
+// sublicense, and/or sell copies of the Software, provided that the above
+// copyright notice and disclaimer of warranty be included in all copies or
+// substantial portions of this software.
 
 #include <arch/addrs.h>
 
+#define ROSHARED_PTR(x) (x - roshared + 0x7fff0000)
+
        .org 0
        .code32
        .global _start
-.align 4
+       .align  4
 multiboot_hdr:
        .long   0x1badb002              // Multi-boot magic
        
@@ -110,8 +104,9 @@ using_our_gdt:
        
        movl    $0x87, x86_init_ptbl_l2 + 0x800 - KERNEL_START
        ljmp    $0x10, $paging_on - KERNEL_START
+       
 
-paging_on:     
+paging_on:
        lgdt    x86_gdtr + 6
        movl    %esi, x86_boot_info_phys
        
@@ -147,10 +142,25 @@ no_pentium_str:
 
 no_multiboot_str:
        .string "Unrecognized bootloader; a multiboot-compliant loader is required."
+
+       .macro  enterkernel, reg
+       pushl   %es
+       pushl   %ds
+       movl    $8, \reg
+       cld
+       movl    \reg, %ds
+       movl    \reg, %es
+       .endm
+       
+       .macro  exitkernel
+       popl    %ds
+       popl    %es
+       .endm
        
        .macro  pushvolatilesnoeax
        pushl   %ecx
        pushl   %edx
+       enterkernel %ecx
        .endm
        
        .macro  pushvolatiles
@@ -159,6 +169,7 @@ no_multiboot_str:
        .endm
 
        .macro  popvolatiles
+       exitkernel
        popl    %edx
        popl    %ecx
        popl    %eax
@@ -172,11 +183,11 @@ no_multiboot_str:
        .macro  pushall
        pushl   %esi
        pushl   %ebp
-       pushl   %esp
        pushl   %ebx
        pushl   %edx
        pushl   %ecx
        pushl   %eax
+       enterkernel %esi
        .endm
        
        .macro  pushallnoerr
@@ -185,11 +196,11 @@ no_multiboot_str:
        .endm
 
        .macro  popall
+       exitkernel
        popl    %eax
        popl    %ecx
        popl    %edx
        popl    %ebx
-       addl    $4, %esp
        popl    %ebp
        popl    %esi
        popl    %edi
@@ -269,17 +280,45 @@ x86_page_fault:
        popall
        iret
 
+       .global x86_int98_entry
+x86_int98_entry:
+       pushl   $0
+       pushl   %eax
+       enterkernel %ecx
+
+       pushl   %esp
+       call    x86_invoke_method
+       addl    $4, %esp
+
+       exitkernel
+       popl    %eax
+       xorl    %ecx, %ecx
+       popl    %edx
+       xorl    %ebx, %ebx
+       xorl    %ebp, %ebp
+       xorl    %esi, %esi
+       xorl    %edi, %edi
+       iret
+
        .global x86_int99_entry
 x86_int99_entry:
        pushl   %edx
-       pushl   4(%esp)
-       pushl   %edx
-       pushl   %ecx
        pushl   %eax
-       call    invoke_method
-       addl    $16, %esp
-       xorl    %ecx, %ecx
+       enterkernel %edx
+
+       pushl   %esp
+       call    x86_return_from_method
+       addl    $4, %esp
+       
+       exitkernel
+       popl    %eax
+       xorl    %ecx, %ecx
        popl    %edx
+       xorl    %ebx, %ebx
+       xorl    %ebp, %ebp
+       xorl    %esi, %esi
+       xorl    %edi, %edi
+       movl    $ROSHARED_PTR(x86_shared_int98_ret), (%esp)
        iret
 
        .global x86_irq
@@ -343,23 +382,83 @@ x86_new_thread:
        xorl    %edi, %edi
        
        call    sched_new_thread
-       pop     %eax
+       popl    %eax
        call    *%eax
        call    exit_thread
        ud2a
-
-       .section ".roshared","x"
        
-       // The syscall pointer must be the first thing in roshared
-       // (at vaddr 0x7fff0000), so that user code can make method
-       // invocations to find out where other stuff is.
+       .global arch_new_user_thread
+arch_new_user_thread:
+       movl    4(%esp), %eax   // arg1: user entry
+       movl    8(%esp), %ecx   // arg2: user stack
+       pushl   $0x23           // SS
+       pushl   %ecx            // ESP
+       pushl   $0x202          // EFLAGS
+       pushl   $0x2b           // CS
+       pushl   %eax            // EIP
        
-       .global x86_syscall_ptr
-x86_syscall_ptr:
-       .long   x86_shared_int99 - x86_syscall_ptr + 0x7fff0000
+       movl    $0x23, %ebx
+       movl    %ebx, %ds
+       movl    %ebx, %es
        
-       .global x86_shared_int99
+       xorl    %eax, %eax
+       xorl    %ecx, %ecx
+       iret
+
+       .section ".roshared","ax"
+roshared:
+x86_shared_int98:
+       // FIXME: This must be unpreemptible by traps
+       pushl   %gs
+       pushl   %fs
+       pushl   %ebp
+       pushl   %edi
+       pushl   %esi
+       pushl   %ebx
+       int     $0x98
+x86_shared_int98_ret:
+       popl    %ebx
+       popl    %esi
+       popl    %edi
+       popl    %ebp
+       popl    %fs
+       popl    %gs
+       ret
+
+       . = roshared + 0x80
 x86_shared_int99:
        int     $0x99
-       // FIXME: search for exception handler
        ret
+
+       .global test_user_ptr
+test_user_ptr:
+       .long   ROSHARED_PTR(test_user)
+       
+test_pib:
+       .long   0
+       .long   0
+       .long   ROSHARED_PTR(test_objlist)
+       .long   1
+       .long   0
+
+test_objlist:
+       .long   0
+       .space  128
+       
+test_user:
+       movl    $ROSHARED_PTR(test_pib), %eax
+       movl    $0x7fff0000, %ecx
+       call    *%ecx
+1:     jmp     1b
+
+       .section ".rwshared","a"
+       .align 4096
+
+       // Userspace must set this to an appropriate entry point
+       // prior to registering objects with the kernel.  It should
+       // not be modified while an object is registered (the kernel
+       // won't mind, but there's no mechanism to wait until no more
+       // upcalls to the old entry point are in progress).
+       .global x86_upcall_entry
+x86_upcall_entry:
+       .long   0