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>
22 .long 0x1badb002 // Multi-boot magic
25 // bit 0: 4KiB-align all boot modules
26 // bit 1: must include memory size and map
27 // bit 2: must include video mode table
28 // bit 16: load addresses in this header are valid
29 // and should be used instead of the ELF header
33 // checksum: -(magic + flags), update if flags change
36 .long multiboot_hdr - KERNEL_START // header_addr
37 .long 0x00200000 // load_addr
38 .long 0 // load_end_addr: load whole file
39 .long bss_end - KERNEL_START // bss_end_addr
40 .long _start - KERNEL_START // entry_addr
44 lgdt x86_gdtr_phys + 6 - KERNEL_START
45 ljmp $0x10, $using_our_gdt - KERNEL_START
55 movl %ebx, %esi // Save the multiboot pointer somewhere
56 // it won't be clobbered by CPUID
58 // This gives 512 bytes to Threads::Thread; if it gets larger
59 // this needs to be updated (as well as the code at high_vaddr).
61 movl $x86_init_stack + 3584 - KERNEL_START, %esp
67 xorl $0x00200000, %eax
75 // Test for Page Size Extensions
91 // Load the initial page table
92 movl $x86_init_ptbl_l2 - KERNEL_START, %eax
95 // enable paging, kernel write-protect,
96 // and internal floating point error handling
101 // Set up high page tables for 0x80000000 mapping,
103 movl $0x87, x86_init_ptbl_l2 + 0x800 - KERNEL_START
104 ljmp $0x10, $paging_on - KERNEL_START
108 movl %esi, x86_boot_info_phys
110 movl $high_vaddr, %eax
114 movl $x86_init_stack + 3584, %esp
118 movl $no_multiboot_str - KERNEL_START, %esi
121 movl $no_pentium_str - KERNEL_START, %esi
127 1: movb %al, (%edi, %ecx, 2)
128 movb $14, 1(%edi, %ecx, 2) // It's not at the cursor, so use
129 // yellow to make it stand out.
131 movb (%esi, %ecx), %al
138 .string "This kernel requires a Pentium-compatible CPU. Either CPUID or PSE is missing."
141 .string "Unrecognized bootloader; a multiboot-compliant loader is required."
143 .macro pushvolatilesnoeax
159 // Non-volatile registers must be pushed if the handler will
160 // need to access all of the interrupted code's registers,
161 // such as when producing an error dump. Does not include
162 // edi, as that is usually swapped with the error code.
212 .global x86_breakpoint
217 call x86_do_breakpoint
223 .global x86_invalid_insn
228 call x86_do_invalid_insn
236 xchgl %edi, (%esp) // get error code
248 .global x86_page_fault
250 xchgl %edi, (%esp) // get error code
258 call x86_do_page_fault
264 .global x86_int99_entry
285 movl need_resched, %eax
294 // The cli is to make sure interrupts don't get re-enabled in
295 // this thread context between the schedule and the ret from
328 .global x86_new_thread
337 call sched_new_thread
343 .section ".roshared","x"
345 // The syscall pointer must be the first thing in roshared
346 // (at vaddr 0x7fff0000), so that user code can make method
347 // invocations to find out where other stuff is.
349 .global x86_syscall_ptr
351 .long x86_shared_int99 - x86_syscall_ptr + 0x7fff0000
353 .global x86_shared_int99
356 // FIXME: search for exception handler