redesign of the boot code of the application processor

This commit is contained in:
Stefan Lankes 2011-07-18 08:35:57 +02:00
parent 1fb1379a9c
commit e7c0f53562

View file

@ -22,55 +22,10 @@
[BITS 16] [BITS 16]
SECTION .text SECTION .text
GLOBAL _start GLOBAL _start
ORG 0x10000 ORG 0x7000
_start: _start:
jmp _realstart cli
lgdt [gdtr]
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 ; switch to protected mode by setting PE bit
mov eax, cr0 mov eax, cr0
@ -78,28 +33,41 @@ _realstart:
mov cr0, eax mov cr0, eax
; far jump to the 32bit code ; far jump to the 32bit code
jmp dword 0x08 : _pmstart jmp dword codesel : _pmstart
[BITS 32] [BITS 32]
_pmstart: _pmstart:
cli
xor eax, eax xor eax, eax
mov ax, 0x10 mov ax, datasel
mov ds, ax mov ds, ax
mov es, ax mov es, ax
mov fs, ax mov fs, ax
mov gs, ax mov gs, ax
mov ss, ax mov ss, ax
; enable cache and turn on FPU exceptions mov esp, 0xDEADBEEF
mov eax, cr0 push DWORD 0xDEADDEAD
and eax, 0x9fffffff push DWORD 0x00 ; dummy value
or eax, 0x20 jmp codesel : 0xDEADC0DE
mov cr0, eax jmp $
; clear the current pgd entry
xor eax, eax gdtr: ; descritor table
mov cr3, eax dw gdt_end-gdt-1 ; limit
; set stack pointer dd gdt ; base adresse
mov esp, 0xDEADBEEF gdt:
xor eax, eax dd 0,0 ; null descriptor
xor ebx, ebx codesel equ $-gdt
jmp 0x08 : 0xDEADC0DE dw 0xFFFF ; segment size 0..15
dw 0x0000 ; segment address 0..15
db 0x00 ; segment address 16..23
db 0x9A ; access permissions und type
db 0xCF ; additional information and segment size 16...19
db 0x00 ; segment address 24..31
datasel equ $-gdt
dw 0xFFFF ; segment size 0..15
dw 0x0000 ; segment address 0..15
db 0x00 ; segment address 16..23
db 0x92 ; access permissions and type
db 0xCF ; additional informationen and degment size 16...19
db 0x00 ; segment address 24..31
gdt_end: