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 condition:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
23 #include <arch/addrs.h>
30 .long 0x1badb002 // Multi-boot magic
33 // bit 0: 4KiB-align all boot modules
34 // bit 1: must include memory size and map
35 // bit 2: must include video mode table
36 // bit 16: load addresses in this header are valid
37 // and should be used instead of the ELF header
41 // checksum: -(magic + flags), update if flags change
44 .long multiboot_hdr - KERNEL_START // header_addr
45 .long 0x00200000 // load_addr
46 .long 0 // load_end_addr: load whole file
47 .long bss_end - KERNEL_START // bss_end_addr
48 .long _start - KERNEL_START // entry_addr
52 lgdt x86_gdtr_phys + 6 - KERNEL_START
53 ljmp $0x10, $using_our_gdt - KERNEL_START
63 movl %ebx, %esi // Save the multiboot pointer somewhere
64 // it won't be clobbered by CPUID
66 // This gives 512 bytes to Threads::Thread; if it gets larger
67 // this needs to be updated (as well as the code at high_vaddr).
69 movl $x86_init_stack + 3584 - KERNEL_START, %esp
75 xorl $0x00200000, %eax
83 // Test for Page Size Extensions
99 // Load the initial page table
100 movl $x86_init_ptbl_l2 - KERNEL_START, %eax
103 // enable paging, kernel write-protect,
104 // and internal floating point error handling
106 orl $0x80010020, %eax
109 // Set up high page tables for 0x80000000 mapping,
111 movl $0x87, x86_init_ptbl_l2 + 0x800 - KERNEL_START
112 ljmp $0x10, $paging_on - KERNEL_START
116 movl %esi, x86_boot_info_phys
118 movl $high_vaddr, %eax
122 movl $x86_init_stack + 3584, %esp
126 movl $no_multiboot_str - KERNEL_START, %esi
129 movl $no_pentium_str - KERNEL_START, %esi
135 1: movb %al, (%edi, %ecx, 2)
136 movb $14, 1(%edi, %ecx, 2) // It's not at the cursor, so use
137 // yellow to make it stand out.
139 movb (%esi, %ecx), %al
146 .string "This kernel requires a Pentium-compatible CPU. Either CPUID or PSE is missing."
149 .string "Unrecognized bootloader; a multiboot-compliant loader is required."
151 .macro pushvolatilesnoeax
167 // Non-volatile registers must be pushed if the handler will
168 // need to access all of the interrupted code's registers,
169 // such as when producing an error dump. Does not include
170 // edi, as that is usually swapped with the error code.
220 .global x86_breakpoint
225 call x86_do_breakpoint
231 .global x86_invalid_insn
236 call x86_do_invalid_insn
244 xchgl %edi, (%esp) // get error code
256 .global x86_page_fault
258 xchgl %edi, (%esp) // get error code
266 call x86_do_page_fault
272 .global x86_int99_entry
293 movl need_resched, %eax
302 // The cli is to make sure interrupts don't get re-enabled in
303 // this thread context between the schedule and the ret from
336 .global x86_new_thread
345 call sched_new_thread
351 .section ".roshared","x"
353 // The syscall pointer must be the first thing in roshared
354 // (at vaddr 0x7fff0000), so that user code can make method
355 // invocations to find out where other stuff is.
357 .global x86_syscall_ptr
359 .long x86_shared_int99 - x86_syscall_ptr + 0x7fff0000
361 .global x86_shared_int99
364 // FIXME: search for exception handler