comparison cos/kernel/goto64.asm @ 24:d8627924d40d

Split up in more files and reboot command
author windel
date Fri, 02 Dec 2011 14:00:02 +0100
parents 5dd47d6eebac
children 3a6a9b929db0
comparison
equal deleted inserted replaced
23:5dd47d6eebac 24:d8627924d40d
8 8
9 ; This file sets up long mode and creates paging tables. 9 ; This file sets up long mode and creates paging tables.
10 ; Use 2 mbyte pages. Is this more efficient? 10 ; Use 2 mbyte pages. Is this more efficient?
11 11
12 ; Intended memory map (copied from pure64), at the end of this file: 12 ; Intended memory map (copied from pure64), at the end of this file:
13 ; 0x0 : IDT, 256 entries 13 ; MOVED TO 0x5000!! 0x0 : IDT, 256 entries
14 ; 0x1000 - 0x2000 : PML4 (Page map level 4) 14 ; 0x1000 - 0x2000 : PML4 (Page map level 4)
15 ; 0x2000 - 0x3000 : PDPT (page directory pointer table) 15 ; 0x2000 - 0x3000 : PDPT (page directory pointer table)
16 ; 0x3000 - 0x4000 : PDT (page directory table) 16 ; 0x3000 - 0x4000 : PDT (page directory table)
17 ; 0x4000 - 0x5000 : PT (page table) 17 ; 0x4000 - 0x5000 : PT (page table)
18 ; 0x5000 - 0xA000 : Stack 18 ; 0x5000 - 0x6000 : IDT entries
19 ; 0x6000 - 0xA000 : Stack
20
21 ; panic macro to debug on real hardware
22 %macro DOPANIC 1
23 mov al, %1
24 mov edi, 0xb8000
25 stosb
26 xchg bx,bx
27 hlt
28 %endmacro
19 29
20 bits 32 ; Start in 32 bits mode, as loaded by GRUB 30 bits 32 ; Start in 32 bits mode, as loaded by GRUB
21 31
22 ; Multiboot header: 32 ; Multiboot header:
23 ; Settings for multiboot header 33 ; Settings for multiboot header
107 117
108 no_long_mode: 118 no_long_mode:
109 ; Print long mode not supported 119 ; Print long mode not supported
110 mov edi, 0xb8000 120 mov edi, 0xb8000
111 mov esi, hltmessage 121 mov esi, hltmessage
112 xor eax,eax 122 xor eax, eax
113 loop1: 123 loop1:
114 lodsb 124 lodsb
115 mov dl, al 125 mov dl, al
116 stosb 126 stosb
117 mov al, 0x1f 127 mov al, 0x1f
118 stosb 128 stosb
119 cmp dl, 0 129 cmp dl, 0
120 jne loop1 130 jne loop1
121
122 hlt 131 hlt
123 132
124 cpu_has_long_mode: 133 cpu_has_long_mode:
125 134
126 lgdt [gdt32pointer] ; Reload a valid temporary 32 bits GDT, overload GRUB gdt. 135 lgdt [gdt32pointer] ; Reload a valid temporary 32 bits GDT, overload GRUB gdt.
136 cld ; clear direction? 145 cld ; clear direction?
137 146
138 ; Clear the paging tables 0x1000, 0x2000, 0x3000 and 0x4000: 147 ; Clear the paging tables 0x1000, 0x2000, 0x3000 and 0x4000:
139 mov edi, 0x1000 148 mov edi, 0x1000
140 xor eax, eax 149 xor eax, eax
141 mov ecx, 4096 150 mov ecx, 0x1000
142 rep stosd 151 rep stosd
143 152
144 ; Create PML4 table: 153 ; Create PML4 table:
145 mov edi, 0x1000 154 mov edi, 0x1000
146 mov eax, 0x2003 155 mov eax, 0x2003
178 ; Enable address extension: 187 ; Enable address extension:
179 mov eax, cr4 188 mov eax, cr4
180 or eax, 1 << 5 ; PAE-bit is bit 5 189 or eax, 1 << 5 ; PAE-bit is bit 5
181 mov cr4, eax 190 mov cr4, eax
182 191
183 ; Load the GDT: 192 lgdt [gdt64pointer] ; Load the GDT
184 lgdt [gdt64pointer]
185 193
186 ; Set LM-bit (Long Mode bit): 194 ; Set LM-bit (Long Mode bit):
187 mov ecx, 0xC0000080 195 mov ecx, 0xC0000080
188 rdmsr 196 rdmsr
189 or eax, 0x100 ; Set bit 8 (LM-bit) 197 or eax, 0x100 ; Set bit 8 (LM-bit)
212 220
213 lgdt [gdt64pointer] ; Reload GDT in 64 bits mode 221 lgdt [gdt64pointer] ; Reload GDT in 64 bits mode
214 222
215 mov rsp, 0xA000 ; Setup stack pointer. 223 mov rsp, 0xA000 ; Setup stack pointer.
216 224
217 # XCHG BX, BX ; bochs breakpoint
218
219 extern kmain 225 extern kmain
220 call kmain ; Call kernel in C-code 226 call kmain ; Call kernel in C-code
221 227
222 # Should we ever return, remain in endless loop:
223 cli
224 hang:
225 hlt
226 jmp hang
227