1 // arch/x86/entry.S - x86 entry points (booting and traps)
3 // This software is copyright (c) 2006 Scott Wood.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal with
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 // of the Software, and to permit persons to whom the Software is furnished to do
10 // so, subject to the following conditions:
12 // * Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimers.
15 // * Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimers in the
17 // documentation and/or other materials provided with the distribution.
19 // * The names of the Software's authors and/or contributors
20 // may not be used to endorse or promote products derived from
21 // this Software without specific prior written permission.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
31 #include <arch/addrs.h>
38 .long 0x1badb002 // Multi-boot magic
41 // bit 0: 4KiB-align all boot modules
42 // bit 1: must include memory size and map
43 // bit 2: must include video mode table
44 // bit 16: load addresses in this header are valid
45 // and should be used instead of the ELF header
49 // checksum: -(magic + flags), update if flags change
52 .long multiboot_hdr - KERNEL_START // header_addr
53 .long 0x00200000 // load_addr
54 .long 0 // load_end_addr: load whole file
55 .long bss_end - KERNEL_START // bss_end_addr
56 .long _start - KERNEL_START // entry_addr
60 lgdt x86_gdtr_phys + 6 - KERNEL_START
61 ljmp $0x10, $using_our_gdt - KERNEL_START
71 movl %ebx, %esi // Save the multiboot pointer somewhere
72 // it won't be clobbered by CPUID
74 // This gives 512 bytes to Threads::Thread; if it gets larger
75 // this needs to be updated (as well as the code at high_vaddr).
77 movl $x86_init_stack + 3584 - KERNEL_START, %esp
83 xorl $0x00200000, %eax
91 // Test for Page Size Extensions
107 // Load the initial page table
108 movl $x86_init_ptbl_l2 - KERNEL_START, %eax
111 // enable paging, kernel write-protect,
112 // and internal floating point error handling
114 orl $0x80010020, %eax
117 // Set up high page tables for 0x80000000 mapping,
119 movl $0x87, x86_init_ptbl_l2 + 0x800 - KERNEL_START
120 ljmp $0x10, $paging_on - KERNEL_START
124 movl %esi, x86_boot_info_phys
126 movl $high_vaddr, %eax
130 movl $x86_init_stack + 3584, %esp
134 movl $no_multiboot_str - KERNEL_START, %esi
137 movl $no_pentium_str - KERNEL_START, %esi
143 1: movb %al, (%edi, %ecx, 2)
144 movb $14, 1(%edi, %ecx, 2) // It's not at the cursor, so use
145 // yellow to make it stand out.
147 movb (%esi, %ecx), %al
154 .string "This kernel requires a Pentium-compatible CPU. Either CPUID or PSE is missing."
157 .string "Unrecognized bootloader; a multiboot-compliant loader is required."
159 .macro pushvolatilesnoeax
175 // Non-volatile registers must be pushed if the handler will
176 // need to access all of the interrupted code's registers,
177 // such as when producing an error dump. Does not include
178 // edi, as that is usually swapped with the error code.
228 .global x86_breakpoint
233 call x86_do_breakpoint
239 .global x86_invalid_insn
244 call x86_do_invalid_insn
252 xchgl %edi, (%esp) // get error code
264 .global x86_page_fault
266 xchgl %edi, (%esp) // get error code
274 call x86_do_page_fault
280 .global x86_int99_entry
301 movl need_resched, %eax
310 // The cli is to make sure interrupts don't get re-enabled in
311 // this thread context between the schedule and the ret from
344 .global x86_new_thread
353 call sched_new_thread
359 .section ".roshared","x"
361 // The syscall pointer must be the first thing in roshared
362 // (at vaddr 0x7fff0000), so that user code can make method
363 // invocations to find out where other stuff is.
365 .global x86_syscall_ptr
367 .long x86_shared_int99 - x86_syscall_ptr + 0x7fff0000
369 .global x86_shared_int99
372 // FIXME: search for exception handler