1 // arch/x86/entry.S - x86 entry points (booting and traps)
3 // This software is copyright (c) 2006 Scott Wood.
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
15 #include <arch/addrs.h>
17 #define ROSHARED_PTR(x) (x - x86_syscall_ptr + 0x7fff0000)
24 .long 0x1badb002 // Multi-boot magic
27 // bit 0: 4KiB-align all boot modules
28 // bit 1: must include memory size and map
29 // bit 2: must include video mode table
30 // bit 16: load addresses in this header are valid
31 // and should be used instead of the ELF header
35 // checksum: -(magic + flags), update if flags change
38 .long multiboot_hdr - KERNEL_START // header_addr
39 .long 0x00200000 // load_addr
40 .long 0 // load_end_addr: load whole file
41 .long bss_end - KERNEL_START // bss_end_addr
42 .long _start - KERNEL_START // entry_addr
46 lgdt x86_gdtr_phys + 6 - KERNEL_START
47 ljmp $0x10, $using_our_gdt - KERNEL_START
57 movl %ebx, %esi // Save the multiboot pointer somewhere
58 // it won't be clobbered by CPUID
60 // This gives 512 bytes to Threads::Thread; if it gets larger
61 // this needs to be updated (as well as the code at high_vaddr).
63 movl $x86_init_stack + 3584 - KERNEL_START, %esp
69 xorl $0x00200000, %eax
77 // Test for Page Size Extensions
93 // Load the initial page table
94 movl $x86_init_ptbl_l2 - KERNEL_START, %eax
97 // enable paging, kernel write-protect,
98 // and internal floating point error handling
100 orl $0x80010020, %eax
103 // Set up high page tables for 0x80000000 mapping,
105 movl $0x87, x86_init_ptbl_l2 + 0x800 - KERNEL_START
106 ljmp $0x10, $paging_on - KERNEL_START
111 movl %esi, x86_boot_info_phys
113 movl $high_vaddr, %eax
117 movl $x86_init_stack + 3584, %esp
121 movl $no_multiboot_str - KERNEL_START, %esi
124 movl $no_pentium_str - KERNEL_START, %esi
130 1: movb %al, (%edi, %ecx, 2)
131 movb $14, 1(%edi, %ecx, 2) // It's not at the cursor, so use
132 // yellow to make it stand out.
134 movb (%esi, %ecx), %al
141 .string "This kernel requires a Pentium-compatible CPU. Either CPUID or PSE is missing."
144 .string "Unrecognized bootloader; a multiboot-compliant loader is required."
146 .macro enterkernel, reg
160 .macro pushvolatilesnoeax
178 // Non-volatile registers must be pushed if the handler will
179 // need to access all of the interrupted code's registers,
180 // such as when producing an error dump. Does not include
181 // edi, as that is usually swapped with the error code.
231 .global x86_breakpoint
236 call x86_do_breakpoint
242 .global x86_invalid_insn
247 call x86_do_invalid_insn
255 xchgl %edi, (%esp) // get error code
267 .global x86_page_fault
269 xchgl %edi, (%esp) // get error code
277 call x86_do_page_fault
283 .global x86_int98_entry
290 call x86_invoke_method
303 .global x86_int99_entry
310 call x86_return_from_method
321 movl $ROSHARED_PTR(x86_shared_int98_ret), (%esp)
332 movl need_resched, %eax
341 // The cli is to make sure interrupts don't get re-enabled in
342 // this thread context between the schedule and the ret from
375 .global x86_new_thread
384 call sched_new_thread
390 .global arch_new_user_thread
391 arch_new_user_thread:
392 movl 4(%esp), %eax // arg1: user entry
393 movl 8(%esp), %ecx // arg2: user stack
396 pushl $0x202 // EFLAGS
408 .section ".roshared","ax"
411 // The vsyscall table must be the first thing in roshared
412 // (at vaddr 0x7fff0000).
414 .global x86_syscall_ptr
416 .long ROSHARED_PTR(x86_shared_int98)
418 .global x86_sysret_ptr
420 .long ROSHARED_PTR(x86_shared_int99)
423 // FIXME: This must be unpreemptible by traps
431 x86_shared_int98_ret:
444 .global test_user_ptr
447 .long ROSHARED_PTR(test_user)
452 .long ROSHARED_PTR(test_objlist)
461 movl $ROSHARED_PTR(test_pib), %eax
465 .section ".rwshared","a"
468 // Userspace must set this to an appropriate entry point
469 // prior to registering objects with the kernel. It should
470 // not be modified while an object is registered (the kernel
471 // won't mind, but there's no mechanism to wait until no more
472 // upcalls to the old entry point are in progress).
473 .global x86_upcall_entry