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
110 movl %esi, x86_boot_info_phys
112 movl $high_vaddr, %eax
116 movl $x86_init_stack + 3584, %esp
120 movl $no_multiboot_str - KERNEL_START, %esi
123 movl $no_pentium_str - KERNEL_START, %esi
129 1: movb %al, (%edi, %ecx, 2)
130 movb $14, 1(%edi, %ecx, 2) // It's not at the cursor, so use
131 // yellow to make it stand out.
133 movb (%esi, %ecx), %al
140 .string "This kernel requires a Pentium-compatible CPU. Either CPUID or PSE is missing."
143 .string "Unrecognized bootloader; a multiboot-compliant loader is required."
145 .macro enterkernel, reg
159 .macro pushvolatilesnoeax
177 // Non-volatile registers must be pushed if the handler will
178 // need to access all of the interrupted code's registers,
179 // such as when producing an error dump. Does not include
180 // edi, as that is usually swapped with the error code.
230 .global x86_breakpoint
235 call x86_do_breakpoint
241 .global x86_invalid_insn
246 call x86_do_invalid_insn
254 xchgl %edi, (%esp) // get error code
266 .global x86_page_fault
268 xchgl %edi, (%esp) // get error code
276 call x86_do_page_fault
282 .global x86_int98_entry
289 call x86_invoke_method
302 .global x86_int99_entry
309 call x86_return_from_method
320 movl $ROSHARED_PTR(x86_shared_int98_ret), (%esp)
331 movl need_resched, %eax
340 // The cli is to make sure interrupts don't get re-enabled in
341 // this thread context between the schedule and the ret from
374 .global x86_new_thread
383 call sched_new_thread
389 .section ".roshared","x"
391 // The vsyscall table must be the first thing in roshared
392 // (at vaddr 0x7fff0000).
394 .global x86_syscall_ptr
396 .long ROSHARED_PTR(x86_shared_int98)
398 .global x86_sysret_ptr
400 .long ROSHARED_PTR(x86_shared_int99)
403 // FIXME: This must be unpreemptible by traps
411 x86_shared_int98_ret:
424 .section ".rwshared",""
426 // Userspace must set this to an appropriate entry point
427 // prior to registering objects with the kernel. It should
428 // not be modified while an object is registered (the kernel
429 // won't mind, but there's no mechanism to wait until no more
430 // upcalls to the old entry point are in progress).
431 .global x86_upcall_entry