; ; Copyright 2010 Stefan Lankes, Chair for Operating Systems, ; RWTH Aachen University ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ; ; This file is part of MetalSVM. ; This is the kernel's entry point for the application processors. We switch to the ; protected mode and jump to our MetalSVM kernel. [BITS 16] SECTION .text GLOBAL _start ORG 0x10000 _start: jmp _realstart struc GDT_STR s0_15: resw 1 b0_15: resw 1 b16_23: resb 1 flags: resb 1 access: resb 1 b24_31: resb 1 endstruc gdt_start dw gdt_size gdt_ptr dd dummy_descriptor dummy_descriptor: istruc GDT_STR at s0_15, dw 0 at b0_15, dw 0 at b16_23, db 0 at flags, db 0 at access, db 0 at b24_31, db 0 iend ; 4GB 32-bit code , 9ah = 10011010b = Present, DPL 00,No System, Code Exec/Read. code32_descriptor: istruc GDT_STR at s0_15, dw 0x0ffff at b0_15, dw 0 at b16_23, db 0 at flags, db 0x9a at access, db 0xcf at b24_31, db 0 iend ; 4GB 32-bit data, 92h = 10010010b = Present, DPL 00, No System, Data Read/Write data32_descriptor: istruc GDT_STR at s0_15, dw 0x0ffff at b0_15, dw 0 at b16_23, db 0 at flags, db 0x92 at access, db 0xcf at b24_31, db 0 iend gdt_size equ $ - (dummy_descriptor) - 1 _realstart: lgdt [gdt_start] ; switch to protected mode by setting PE bit mov eax, cr0 or al, 0x1 mov cr0, eax ; far jump to the 32bit code jmp dword 0x08 : _pmstart [BITS 32] _pmstart: cli xor eax, eax mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax ; enable cache and turn on FPU exceptions mov eax, cr0 and eax, 0x9fffffff or eax, 0x20 mov cr0, eax ; clear the current pgd entry xor eax, eax mov cr3, eax ; set stack pointer mov esp, 0xDEADBEEF xor eax, eax xor ebx, ebx jmp 0x08 : 0xDEADC0DE