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 enterkernel, reg
157 .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_int98_entry
287 call x86_invoke_method
300 .global x86_int99_entry
307 call x86_return_from_method
328 movl need_resched, %eax
337 // The cli is to make sure interrupts don't get re-enabled in
338 // this thread context between the schedule and the ret from
371 .global x86_new_thread
380 call sched_new_thread
386 .section ".roshared","x"
388 // The vsyscall table must be the first thing in roshared (at
389 // vaddr 0x7fff0000).
391 #define PTR(x) (x - x86_syscall_ptr + 0x7fff0000)
393 .global x86_syscall_ptr
395 .long PTR(x86_shared_int98)
397 .global x86_sysret_ptr
399 .long PTR(x86_shared_int99)
402 // FIXME: This must be unpreemptible by traps
422 .section ".rwshared",""
424 // Userspace must set this to an appropriate entry point
425 // prior to registering objects with the kernel. It should
426 // not be modified while an object is registered (the kernel
427 // won't mind, but there's no mechanism to wait until no more
428 // upcalls to the old entry point are in progress).
429 .global x86_upcall_entry