]>
Commit | Line | Data |
---|---|---|
f3eb2131 | 1 | #------------------------------------------------------------------------------\r |
2 | #*\r | |
69b1c021 | 3 | #* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
b1f700a8 | 4 | #* This program and the accompanying materials \r |
f3eb2131 | 5 | #* are licensed and made available under the terms and conditions of the BSD License \r |
6 | #* which accompanies this distribution. The full text of the license may be found at \r | |
7 | #* http://opensource.org/licenses/bsd-license.php \r | |
8 | #* \r | |
9 | #* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | #* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | #* \r | |
12 | #* st32_64.asm\r | |
13 | #* \r | |
14 | #* Abstract:\r | |
15 | #*\r | |
16 | #------------------------------------------------------------------------------\r | |
17 | \r | |
18 | \r | |
19 | .stack: \r | |
20 | .486p: \r | |
21 | .code16\r | |
22 | \r | |
e343d447 | 23 | .equ FAT_DIRECTORY_ENTRY_SIZE, 0x020\r |
24 | .equ FAT_DIRECTORY_ENTRY_SHIFT, 5\r | |
25 | .equ BLOCK_SIZE, 0x0200\r | |
26 | .equ BLOCK_MASK, 0x01ff\r | |
f3eb2131 | 27 | .equ BLOCK_SHIFT, 9\r |
28 | \r | |
29 | .org 0x0\r | |
69b1c021 | 30 | \r |
31 | .global _start\r | |
32 | _start:\r | |
33 | \r | |
f3eb2131 | 34 | Ia32Jump: \r |
35 | jmp BootSectorEntryPoint # JMP inst - 3 bytes\r | |
36 | nop\r | |
37 | \r | |
e343d447 | 38 | OemId: .ascii "INTEL " # OemId - 8 bytes\r |
39 | SectorSize: .word 0 # Sector Size - 2 bytes\r | |
40 | SectorsPerCluster: .byte 0 # Sector Per Cluster - 1 byte\r | |
41 | ReservedSectors: .word 0 # Reserved Sectors - 2 bytes\r | |
42 | NoFats: .byte 0 # Number of FATs - 1 byte\r | |
43 | RootEntries: .word 0 # Root Entries - 2 bytes\r | |
44 | Sectors: .word 0 # Number of Sectors - 2 bytes\r | |
45 | Media: .byte 0 # Media - 1 byte\r | |
46 | SectorsPerFat16: .word 0 # Sectors Per FAT for FAT12/FAT16 - 2 byte\r | |
47 | SectorsPerTrack: .word 0 # Sectors Per Track - 2 bytes\r | |
48 | Heads: .word 0 # Heads - 2 bytes\r | |
49 | HiddenSectors: .long 0 # Hidden Sectors - 4 bytes\r | |
50 | LargeSectors: .long 0 # Large Sectors - 4 bytes\r | |
51 | \r | |
52 | #******************************************************************************\r | |
53 | #\r | |
54 | #The structure for FAT32 starting at offset 36 of the boot sector. (At this point, \r | |
55 | #the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)\r | |
56 | #\r | |
57 | #******************************************************************************\r | |
58 | \r | |
59 | SectorsPerFat32: .long 0 # Sectors Per FAT for FAT32 - 4 bytes\r | |
60 | ExtFlags: .word 0 # Mirror Flag - 2 bytes\r | |
61 | FSVersion: .word 0 # File System Version - 2 bytes\r | |
62 | RootCluster: .long 0 # 1st Cluster Number of Root Dir - 4 bytes\r | |
63 | FSInfo: .word 0 # Sector Number of FSINFO - 2 bytes\r | |
64 | BkBootSector: .word 0 # Sector Number of Bk BootSector - 2 bytes\r | |
65 | Reserved: .fill 12,1,0 # Reserved Field - 12 bytes\r | |
66 | PhysicalDrive: .byte 0 # Physical Drive Number - 1 byte\r | |
67 | Reserved1: .byte 0 # Reserved Field - 1 byte\r | |
68 | Signature: .byte 0 # Extended Boot Signature - 1 byte\r | |
69 | VolId: .ascii " " # Volume Serial Number - 4 bytes\r | |
70 | FatLabel: .ascii " " # Volume Label - 11 bytes\r | |
71 | FileSystemType: .ascii "FAT32 " # File System Type - 8 bytes\r | |
72 | \r | |
f3eb2131 | 73 | \r |
74 | BootSectorEntryPoint: \r | |
75 | # ASSUME ds:@code\r | |
76 | # ASSUME ss:@code\r | |
77 | # ds = 1000, es = 2000 + x (size of first cluster >> 4)\r | |
78 | # cx = Start Cluster of EfiLdr\r | |
79 | # dx = Start Cluster of Efivar.bin\r | |
80 | \r | |
81 | # Re use the BPB data stored in Boot Sector\r | |
82 | movw $0x7c00,%bp\r | |
83 | \r | |
84 | pushw %cx\r | |
85 | # Read Efivar.bin\r | |
86 | # 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already\r | |
87 | movw $0x1900,%ax\r | |
88 | movw %ax,%es\r | |
89 | testw %dx,%dx\r | |
90 | jnz CheckVarStoreSize\r | |
91 | \r | |
92 | movb $1,%al\r | |
93 | NoVarStore: \r | |
94 | pushw %es\r | |
95 | # Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl\r | |
b29a823d | 96 | movb %al, %es:(4)\r |
f3eb2131 | 97 | jmp SaveVolumeId\r |
98 | \r | |
99 | CheckVarStoreSize: \r | |
100 | movw %dx,%di\r | |
101 | cmpl $0x4000, %ds:2(%di)\r | |
102 | movb $2,%al\r | |
103 | jne NoVarStore\r | |
104 | \r | |
105 | LoadVarStore: \r | |
106 | movb $0,%al\r | |
e343d447 | 107 | movb %al, %es:(4)\r |
f3eb2131 | 108 | movw (%di), %cx\r |
109 | # ES:DI = 1500:0\r | |
110 | xorw %di,%di\r | |
111 | pushw %es\r | |
112 | movw $0x1500,%ax\r | |
113 | movw %ax,%es\r | |
114 | call ReadFile\r | |
115 | SaveVolumeId: \r | |
116 | popw %es\r | |
e343d447 | 117 | movw VolId(%bp), %ax\r |
118 | movw %ax, %es:(0) # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId\r | |
119 | movw VolId+2(%bp), %ax\r | |
f3eb2131 | 120 | movw %ax, %es:(2)\r |
121 | \r | |
122 | # Read Efildr\r | |
123 | popw %cx\r | |
124 | # cx = Start Cluster of Efildr -> BS.com has filled already\r | |
125 | # ES:DI = 2000:0, first cluster will be read again\r | |
126 | xorw %di,%di # di = 0\r | |
127 | movw $0x2000,%ax\r | |
128 | movw %ax,%es\r | |
129 | call ReadFile\r | |
130 | movw %cs,%ax\r | |
131 | movw %ax, %cs:JumpSegment\r | |
132 | \r | |
133 | CheckEm64T: \r | |
134 | movl $0x80000001,%eax\r | |
135 | # cpuid\r | |
136 | .word 0xA20F\r | |
137 | btl $29,%edx\r | |
138 | jc CheckEm64TPass\r | |
139 | pushw %cs\r | |
140 | popw %ds\r | |
141 | leaw Em64String,%si\r | |
142 | movw $18,%cx\r | |
143 | jmp PrintStringAndHalt\r | |
144 | CheckEm64TPass: \r | |
69b1c021 | 145 | JumpFarInstruction: \r |
f3eb2131 | 146 | .byte 0xea\r |
69b1c021 | 147 | JumpOffset: \r |
f3eb2131 | 148 | .word 0x200\r |
69b1c021 | 149 | JumpSegment: \r |
f3eb2131 | 150 | .word 0x2000\r |
151 | \r | |
152 | \r | |
153 | \r | |
154 | # ****************************************************************************\r | |
155 | # ReadFile\r | |
156 | #\r | |
157 | # Arguments:\r | |
158 | # CX = Start Cluster of File\r | |
159 | # ES:DI = Buffer to store file content read from disk\r | |
160 | #\r | |
161 | # Return:\r | |
162 | # (ES << 4 + DI) = end of file content Buffer\r | |
163 | #\r | |
164 | # ****************************************************************************\r | |
165 | ReadFile: \r | |
166 | # si = NumberOfClusters\r | |
167 | # cx = ClusterNumber\r | |
168 | # dx = CachedFatSectorNumber\r | |
169 | # ds:0000 = CacheFatSectorBuffer\r | |
170 | # es:di = Buffer to load file\r | |
171 | # bx = NextClusterNumber\r | |
172 | pusha\r | |
173 | movw $1,%si # NumberOfClusters = 1\r | |
174 | pushw %cx # Push Start Cluster onto stack\r | |
175 | movw $0xfff,%dx # CachedFatSectorNumber = 0xfff\r | |
176 | FatChainLoop: \r | |
177 | movw %cx,%ax # ax = ClusterNumber \r | |
178 | andw $0xfff8,%ax # ax = ax & 0xfff8\r | |
179 | cmpw $0xfff8,%ax # See if this is the last cluster\r | |
180 | je FoundLastCluster # Jump if last cluster found\r | |
181 | movw %cx,%ax # ax = ClusterNumber\r | |
182 | shlw $2, %ax # FatOffset = ClusterNumber * 2\r | |
183 | pushw %si # Save si\r | |
184 | movw %ax,%si # si = FatOffset\r | |
185 | shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT\r | |
186 | addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)\r | |
187 | andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK\r | |
188 | cmpw %dx,%ax # Compare FatSectorNumber to CachedFatSectorNumber\r | |
189 | je SkipFatRead\r | |
190 | movw $2,%bx\r | |
191 | pushw %es\r | |
192 | pushw %ds\r | |
193 | popw %es\r | |
194 | call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI\r | |
195 | popw %es\r | |
196 | movw %ax,%dx # CachedFatSectorNumber = FatSectorNumber\r | |
197 | SkipFatRead: \r | |
198 | movw (%si), %bx # bx = NextClusterNumber\r | |
199 | movw %cx,%ax # ax = ClusterNumber\r | |
200 | popw %si # Restore si\r | |
201 | decw %bx # bx = NextClusterNumber - 1\r | |
202 | cmpw %cx,%bx # See if (NextClusterNumber-1)==ClusterNumber\r | |
203 | jne ReadClusters\r | |
204 | incw %bx # bx = NextClusterNumber\r | |
205 | incw %si # NumberOfClusters++\r | |
206 | movw %bx,%cx # ClusterNumber = NextClusterNumber\r | |
207 | jmp FatChainLoop\r | |
208 | ReadClusters: \r | |
209 | incw %bx\r | |
210 | popw %ax # ax = StartCluster\r | |
211 | pushw %bx # StartCluster = NextClusterNumber\r | |
212 | movw %bx,%cx # ClusterNumber = NextClusterNumber\r | |
213 | subw $2,%ax # ax = StartCluster - 2\r | |
214 | xorb %bh,%bh\r | |
215 | movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster\r | |
216 | mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster\r | |
217 | addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster\r | |
218 | pushw %ax # save start sector\r | |
219 | movw %si,%ax # ax = NumberOfClusters\r | |
220 | mulw %bx # ax = NumberOfClusters * SectorsPerCluster\r | |
221 | movw %ax,%bx # bx = Number of Sectors\r | |
222 | popw %ax # ax = Start Sector\r | |
223 | call ReadBlocks\r | |
224 | movw $1,%si # NumberOfClusters = 1\r | |
225 | jmp FatChainLoop\r | |
226 | FoundLastCluster: \r | |
227 | popw %cx\r | |
228 | popa\r | |
229 | ret\r | |
230 | \r | |
231 | \r | |
232 | # ****************************************************************************\r | |
233 | # ReadBlocks - Reads a set of blocks from a block device\r | |
234 | #\r | |
235 | # AX = Start LBA\r | |
236 | # BX = Number of Blocks to Read\r | |
237 | # ES:DI = Buffer to store sectors read from disk\r | |
238 | # ****************************************************************************\r | |
239 | \r | |
240 | # cx = Blocks\r | |
241 | # bx = NumberOfBlocks\r | |
242 | # si = StartLBA\r | |
243 | \r | |
244 | ReadBlocks: \r | |
245 | pusha\r | |
e343d447 | 246 | addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA\r |
f3eb2131 | 247 | addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA\r |
248 | movl %eax,%esi # esi = Start LBA\r | |
249 | movw %bx,%cx # cx = Number of blocks to read\r | |
250 | ReadCylinderLoop: \r | |
251 | movw $0x7bfc,%bp # bp = 0x7bfc\r | |
252 | movl %esi,%eax # eax = Start LBA\r | |
253 | xorl %edx,%edx # edx = 0\r | |
b29a823d | 254 | movzwl (%bp), %ebx # bx = MaxSector\r |
f3eb2131 | 255 | divl %ebx # ax = StartLBA / MaxSector\r |
256 | incw %dx # dx = (StartLBA % MaxSector) + 1\r | |
257 | \r | |
258 | movw (%bp), %bx # bx = MaxSector\r | |
259 | subw %dx,%bx # bx = MaxSector - Sector\r | |
260 | incw %bx # bx = MaxSector - Sector + 1\r | |
261 | cmpw %bx,%cx # Compare (Blocks) to (MaxSector - Sector + 1)\r | |
262 | jg LimitTransfer\r | |
263 | movw %cx,%bx # bx = Blocks\r | |
264 | LimitTransfer: \r | |
265 | pushw %ax # save ax\r | |
266 | movw %es,%ax # ax = es\r | |
267 | shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system\r | |
268 | andw $0x7f,%ax # ax = Number of blocks into current seg\r | |
269 | addw %bx,%ax # ax = End Block number of transfer\r | |
270 | cmpw $0x80,%ax # See if it crosses a 64K boundry\r | |
271 | jle NotCrossing64KBoundry # Branch if not crossing 64K boundry\r | |
272 | subw $0x80,%ax # ax = Number of blocks past 64K boundry\r | |
273 | subw %ax,%bx # Decrease transfer size by block overage\r | |
274 | NotCrossing64KBoundry: \r | |
275 | popw %ax # restore ax\r | |
276 | \r | |
277 | pushw %cx\r | |
278 | movb %dl,%cl # cl = (StartLBA % MaxSector) + 1 = Sector\r | |
279 | xorw %dx,%dx # dx = 0\r | |
e343d447 | 280 | divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder \r |
f3eb2131 | 281 | # dx = ax % (MaxHead + 1) = Head\r |
282 | \r | |
283 | pushw %bx # Save number of blocks to transfer\r | |
284 | movb %dl,%dh # dh = Head\r | |
285 | movw $0x7c00,%bp # bp = 0x7c00\r | |
286 | movb PhysicalDrive(%bp), %dl # dl = Drive Number\r | |
287 | movb %al,%ch # ch = Cylinder\r | |
288 | movb %bl,%al # al = Blocks\r | |
289 | movb $2,%ah # ah = Function 2\r | |
290 | movw %di,%bx # es:bx = Buffer address\r | |
291 | int $0x13\r | |
292 | jc DiskError\r | |
293 | popw %bx\r | |
294 | popw %cx\r | |
295 | movzwl %bx,%ebx\r | |
296 | addl %ebx,%esi # StartLBA = StartLBA + NumberOfBlocks\r | |
297 | subw %bx,%cx # Blocks = Blocks - NumberOfBlocks\r | |
298 | movw %es,%ax\r | |
299 | shlw $(BLOCK_SHIFT-4), %bx\r | |
300 | addw %bx,%ax\r | |
301 | movw %ax,%es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE\r | |
302 | cmpw $0,%cx\r | |
303 | jne ReadCylinderLoop\r | |
304 | popa\r | |
305 | ret\r | |
306 | \r | |
307 | DiskError: \r | |
308 | pushw %cs\r | |
309 | popw %ds\r | |
310 | leaw ErrorString,%si\r | |
311 | movw $7,%cx\r | |
312 | jmp PrintStringAndHalt\r | |
313 | \r | |
314 | PrintStringAndHalt: \r | |
315 | movw $0xb800,%ax\r | |
316 | movw %ax,%es\r | |
317 | movw $160,%di\r | |
318 | rep\r | |
319 | movsw\r | |
320 | Halt: \r | |
321 | jmp Halt\r | |
322 | \r | |
e343d447 | 323 | ErrorString: \r |
f3eb2131 | 324 | .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c\r |
325 | \r | |
326 | .org 0x01fa\r | |
327 | LBAOffsetForBootSector: \r | |
328 | .long 0x0\r | |
329 | \r | |
330 | .org 0x01fe\r | |
331 | .word 0xaa55\r | |
332 | \r | |
333 | #******************************************************************************\r | |
334 | #******************************************************************************\r | |
335 | #******************************************************************************\r | |
336 | \r | |
337 | .equ DELAY_PORT, 0x0ed # Port to use for 1uS delay\r | |
338 | .equ KBD_CONTROL_PORT, 0x060 # 8042 control port \r | |
339 | .equ KBD_STATUS_PORT, 0x064 # 8042 status port \r | |
340 | .equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port\r | |
341 | .equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20\r | |
342 | \r | |
343 | .org 0x200\r | |
344 | jmp start\r | |
345 | Em64String: \r | |
346 | .byte 'E', 0x0c, 'm', 0x0c, '6', 0x0c, '4', 0x0c, 'T', 0x0c, ' ', 0x0c, 'U', 0x0c, 'n', 0x0c, 's', 0x0c, 'u', 0x0c, 'p', 0x0c, 'p', 0x0c, 'o', 0x0c, 'r', 0x0c, 't', 0x0c, 'e', 0x0c, 'd', 0x0c, '!', 0x0c\r | |
347 | \r | |
348 | start: \r | |
349 | movw %cs,%ax\r | |
350 | movw %ax,%ds\r | |
351 | movw %ax,%es\r | |
352 | movw %ax,%ss\r | |
353 | movw $MyStack, %sp\r | |
354 | \r | |
355 | # mov ax,0b800h\r | |
356 | # mov es,ax\r | |
357 | # mov byte ptr es:[160],'a'\r | |
358 | # mov ax,cs\r | |
359 | # mov es,ax\r | |
360 | \r | |
361 | movl $0,%ebx\r | |
362 | leal MemoryMap, %edi\r | |
363 | MemMapLoop: \r | |
364 | movl $0xe820,%eax\r | |
365 | movl $20,%ecx\r | |
366 | movl $0x534d4150, %edx # SMAP\r | |
367 | int $0x15\r | |
368 | jc MemMapDone\r | |
369 | addl $20,%edi\r | |
370 | cmpl $0,%ebx\r | |
371 | je MemMapDone\r | |
372 | jmp MemMapLoop\r | |
373 | MemMapDone: \r | |
374 | leal MemoryMap, %eax\r | |
375 | subl %eax,%edi # Get the address of the memory map\r | |
b29a823d | 376 | movl %edi, MemoryMapSize # Save the size of the memory map\r |
f3eb2131 | 377 | \r |
378 | xorl %ebx,%ebx\r | |
379 | movw %cs,%bx # BX=segment\r | |
380 | shll $4,%ebx # BX="linear" address of segment base\r | |
e343d447 | 381 | leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt\r |
382 | movl %eax, (gdtr + 2) # Put address of gdt into the gdtr\r | |
383 | leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt\r | |
384 | movl %eax, (idtr + 2) # Put address of idt into the idtr\r | |
f3eb2131 | 385 | leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map\r |
386 | \r | |
387 | # mov ax,0b800h\r | |
388 | # mov es,ax\r | |
389 | # mov byte ptr es:[162],'b'\r | |
390 | # mov ax,cs\r | |
391 | # mov es,ax\r | |
392 | \r | |
393 | #\r | |
394 | # Enable A20 Gate \r | |
395 | #\r | |
396 | \r | |
397 | movw $0x2401,%ax # Enable A20 Gate\r | |
398 | int $0x15\r | |
399 | jnc A20GateEnabled # Jump if it suceeded\r | |
400 | \r | |
401 | #\r | |
402 | # If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.\r | |
403 | #\r | |
404 | \r | |
405 | call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller\r | |
406 | jnz Timeout8042 # Jump if the 8042 timed out\r | |
407 | outw %ax, $DELAY_PORT # Delay 1 uS\r | |
408 | movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port\r | |
409 | outb %al, $KBD_STATUS_PORT # Send command to the 8042\r | |
410 | call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller\r | |
411 | jnz Timeout8042 # Jump if the 8042 timed out\r | |
412 | movb $ENABLE_A20_CMD, %al # gate address bit 20 on\r | |
413 | outb %al, $KBD_CONTROL_PORT # Send command to thre 8042\r | |
414 | call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller\r | |
415 | movw $25,%cx # Delay 25 uS for the command to complete on the 8042\r | |
416 | Delay25uS: \r | |
417 | outw %ax, $DELAY_PORT # Delay 1 uS\r | |
418 | loop Delay25uS\r | |
419 | Timeout8042: \r | |
420 | \r | |
421 | \r | |
422 | A20GateEnabled: \r | |
423 | \r | |
424 | #\r | |
425 | # DISABLE INTERRUPTS - Entering Protected Mode\r | |
426 | #\r | |
427 | \r | |
428 | cli\r | |
429 | \r | |
430 | # mov ax,0b800h\r | |
431 | # mov es,ax\r | |
432 | # mov byte ptr es:[164],'c'\r | |
433 | # mov ax,cs\r | |
434 | # mov es,ax\r | |
435 | \r | |
436 | leal OffsetIn32BitProtectedMode, %eax\r | |
437 | addl $0x20000+0x6,%eax\r | |
b29a823d | 438 | movl %eax, OffsetIn32BitProtectedMode \r |
f3eb2131 | 439 | \r |
440 | leal OffsetInLongMode, %eax\r | |
441 | addl $0x20000+0x6,%eax\r | |
442 | movl %eax, OffsetInLongMode \r | |
443 | \r | |
444 | #\r | |
445 | # load GDT\r | |
446 | #\r | |
447 | .byte 0x66\r | |
448 | lgdt gdtr\r | |
449 | \r | |
450 | #\r | |
451 | # Enable Protect Mode (set CR0.PE=1)\r | |
452 | #\r | |
69b1c021 | 453 | movl %cr0, %eax # Read CR0.\r |
f3eb2131 | 454 | orl $0x1,%eax # Set PE=1\r |
455 | movl %eax, %cr0 # Write CR0.\r | |
456 | .byte 0x66\r | |
457 | .byte 0xea # jmp far 16:32\r | |
458 | OffsetIn32BitProtectedMode: \r | |
459 | .long 0x0000000 # offset $+8 (In32BitProtectedMode)\r | |
460 | .word 0x10 # selector (flat CS)\r | |
461 | In32BitProtectedMode: \r | |
462 | \r | |
463 | #\r | |
464 | # Entering Long Mode\r | |
465 | #\r | |
466 | .byte 0x66\r | |
467 | movw $8,%ax\r | |
468 | movw %ax,%ds\r | |
469 | movw %ax,%es\r | |
470 | movw %ax,%ss\r | |
471 | \r | |
472 | #\r | |
473 | # Enable the 64-bit page-translation-table entries by\r | |
474 | # setting CR4.PAE=1 (this is _required_ before activating\r | |
475 | # long mode). Paging is not enabled until after long mode\r | |
476 | # is enabled.\r | |
477 | #\r | |
478 | .byte 0xf\r | |
479 | .byte 0x20\r | |
480 | .byte 0xe0\r | |
481 | # mov eax, cr4\r | |
482 | btsl $5,%eax\r | |
483 | .byte 0xf\r | |
484 | .byte 0x22\r | |
485 | .byte 0xe0\r | |
486 | # mov cr4, eax\r | |
487 | \r | |
488 | #\r | |
489 | # This is the Trapolean Page Tables that are guarenteed\r | |
490 | # under 4GB.\r | |
491 | #\r | |
492 | # Address Map:\r | |
493 | # 10000 ~ 12000 - efildr (loaded)\r | |
494 | # 20000 ~ 21000 - start64.com\r | |
495 | # 21000 ~ 22000 - efi64.com\r | |
496 | # 22000 ~ 90000 - efildr\r | |
497 | # 90000 ~ 96000 - 4G pagetable (will be reload later)\r | |
498 | #\r | |
499 | .byte 0xb8\r | |
500 | .long 0x90000\r | |
501 | # mov eax, 90000h\r | |
502 | movl %eax, %cr3\r | |
503 | \r | |
504 | #\r | |
505 | # Enable long mode (set EFER.LME=1).\r | |
506 | #\r | |
507 | .byte 0xb9\r | |
508 | .long 0xc0000080\r | |
509 | # mov ecx, 0c0000080h ; EFER MSR number.\r | |
510 | .byte 0xf\r | |
511 | .byte 0x32\r | |
512 | # rdmsr ; Read EFER.\r | |
513 | .byte 0xf\r | |
514 | .byte 0xba\r | |
515 | .byte 0xe8\r | |
516 | .byte 0x8\r | |
517 | # bts eax, 8 ; Set LME=1.\r | |
518 | .byte 0xf\r | |
519 | .byte 0x30\r | |
520 | # wrmsr ; Write EFER.\r | |
521 | \r | |
522 | #\r | |
523 | # Enable paging to activate long mode (set CR0.PG=1)\r | |
524 | #\r | |
69b1c021 | 525 | movl %cr0, %eax # Read CR0.\r |
f3eb2131 | 526 | .byte 0xf\r |
527 | .byte 0xba\r | |
528 | .byte 0xe8\r | |
529 | .byte 0x1f\r | |
530 | # bts eax, 31 ; Set PG=1.\r | |
531 | movl %eax, %cr0 # Write CR0.\r | |
532 | jmp GoToLongMode\r | |
533 | GoToLongMode: \r | |
534 | \r | |
535 | .byte 0x67\r | |
536 | .byte 0xea # Far Jump $+9:Selector to reload CS\r | |
537 | OffsetInLongMode: \r | |
538 | .long 00000000 # $+9 Offset is ensuing instruction boundary\r | |
539 | .word 0x38 # Selector is our code selector, 38h\r | |
540 | \r | |
541 | InLongMode: \r | |
542 | .byte 0x66\r | |
543 | movw $0x30,%ax\r | |
544 | movw %ax,%ds\r | |
545 | \r | |
546 | .byte 0x66\r | |
547 | movw $0x18,%ax\r | |
548 | movw %ax,%es\r | |
549 | movw %ax,%ss\r | |
550 | movw %ax,%ds\r | |
551 | \r | |
552 | .byte 0xbd\r | |
553 | .long 0x400000\r | |
554 | # mov ebp,000400000h ; Destination of EFILDR32\r | |
555 | .byte 0xbb\r | |
556 | .long 0x70000\r | |
557 | # mov ebx,000070000h ; Length of copy\r | |
558 | \r | |
559 | #\r | |
560 | # load idt later\r | |
561 | #\r | |
562 | .byte 0x48\r | |
563 | .byte 0x33\r | |
564 | .byte 0xc0\r | |
565 | # xor rax, rax\r | |
566 | .byte 0x66\r | |
567 | movw $idtr, %ax\r | |
568 | .byte 0x48\r | |
569 | .byte 0x5\r | |
570 | .long 0x20000\r | |
571 | # add rax, 20000h\r | |
572 | \r | |
573 | .byte 0xf\r | |
574 | .byte 0x1\r | |
575 | .byte 0x18\r | |
576 | # lidt fword ptr [rax]\r | |
577 | \r | |
578 | .byte 0x48\r | |
579 | .byte 0xc7\r | |
580 | .byte 0xc0\r | |
581 | .long 0x21000\r | |
582 | # mov rax, 21000h\r | |
583 | .byte 0x50\r | |
584 | # push rax\r | |
585 | \r | |
586 | # ret\r | |
587 | .byte 0xc3\r | |
588 | \r | |
589 | Empty8042InputBuffer: \r | |
590 | movw $0,%cx\r | |
591 | Empty8042Loop: \r | |
592 | outw %ax, $DELAY_PORT # Delay 1us\r | |
593 | inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port\r | |
594 | andb $0x2,%al # Check the Input Buffer Full Flag\r | |
595 | loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS\r | |
596 | ret\r | |
597 | \r | |
598 | ##############################################################################\r | |
599 | # data\r | |
600 | ##############################################################################\r | |
601 | \r | |
9811c392 | 602 | .p2align 1\r |
f3eb2131 | 603 | \r |
e9a9efb8 | 604 | gdtr: .word GDT_END - GDT_BASE - 1 # GDT limit \r |
f3eb2131 | 605 | .long 0 # (GDT base gets set above)\r |
606 | ##############################################################################\r | |
607 | # global descriptor table (GDT)\r | |
608 | ##############################################################################\r | |
609 | \r | |
9811c392 | 610 | .p2align 1\r |
f3eb2131 | 611 | \r |
612 | GDT_BASE: \r | |
613 | # null descriptor\r | |
614 | .equ NULL_SEL, .-GDT_BASE # Selector [0x0]\r | |
615 | .word 0 # limit 15:0\r | |
616 | .word 0 # base 15:0\r | |
617 | .byte 0 # base 23:16\r | |
618 | .byte 0 # type\r | |
619 | .byte 0 # limit 19:16, flags\r | |
620 | .byte 0 # base 31:24\r | |
621 | \r | |
622 | # linear data segment descriptor\r | |
623 | .equ LINEAR_SEL, .-GDT_BASE # Selector [0x8]\r | |
624 | .word 0xFFFF # limit 0xFFFFF\r | |
625 | .word 0 # base 0\r | |
626 | .byte 0\r | |
627 | .byte 0x92 # present, ring 0, data, expand-up, writable\r | |
628 | .byte 0xCF # page-granular, 32-bit\r | |
629 | .byte 0\r | |
630 | \r | |
631 | # linear code segment descriptor\r | |
632 | .equ LINEAR_CODE_SEL, .-GDT_BASE # Selector [0x10]\r | |
633 | .word 0xFFFF # limit 0xFFFFF\r | |
634 | .word 0 # base 0\r | |
635 | .byte 0\r | |
636 | .byte 0x9A # present, ring 0, data, expand-up, writable\r | |
637 | .byte 0xCF # page-granular, 32-bit\r | |
638 | .byte 0\r | |
639 | \r | |
640 | # system data segment descriptor\r | |
641 | .equ SYS_DATA_SEL, .-GDT_BASE # Selector [0x18]\r | |
642 | .word 0xFFFF # limit 0xFFFFF\r | |
643 | .word 0 # base 0\r | |
644 | .byte 0\r | |
645 | .byte 0x92 # present, ring 0, data, expand-up, writable\r | |
646 | .byte 0xCF # page-granular, 32-bit\r | |
647 | .byte 0\r | |
648 | \r | |
649 | # system code segment descriptor\r | |
650 | .equ SYS_CODE_SEL, .-GDT_BASE # Selector [0x20]\r | |
651 | .word 0xFFFF # limit 0xFFFFF\r | |
652 | .word 0 # base 0\r | |
653 | .byte 0\r | |
654 | .byte 0x9A # present, ring 0, data, expand-up, writable\r | |
655 | .byte 0xCF # page-granular, 32-bit\r | |
656 | .byte 0\r | |
657 | \r | |
658 | # spare segment descriptor\r | |
659 | .equ SPARE3_SEL, .-GDT_BASE # Selector [0x28]\r | |
660 | .word 0 # limit 0xFFFFF\r | |
661 | .word 0 # base 0\r | |
662 | .byte 0\r | |
663 | .byte 0 # present, ring 0, data, expand-up, writable\r | |
664 | .byte 0 # page-granular, 32-bit\r | |
665 | .byte 0\r | |
666 | \r | |
667 | #\r | |
668 | # system data segment descriptor\r | |
669 | #\r | |
670 | .equ SYS_DATA64_SEL, .-GDT_BASE # Selector [0x30]\r | |
671 | .word 0xFFFF # limit 0xFFFFF\r | |
672 | .word 0 # base 0\r | |
673 | .byte 0\r | |
674 | .byte 0x92 # P | DPL [1..2] | 1 | 1 | C | R | A\r | |
675 | .byte 0xCF # G | D | L | AVL | Segment [19..16]\r | |
676 | .byte 0\r | |
677 | \r | |
678 | #\r | |
679 | # system code segment descriptor\r | |
680 | #\r | |
681 | .equ SYS_CODE64_SEL, .-GDT_BASE # Selector [0x38]\r | |
682 | .word 0xFFFF # limit 0xFFFFF\r | |
683 | .word 0 # base 0\r | |
684 | .byte 0\r | |
685 | .byte 0x9A # P | DPL [1..2] | 1 | 1 | C | R | A\r | |
686 | .byte 0xAF # G | D | L | AVL | Segment [19..16]\r | |
687 | .byte 0\r | |
688 | \r | |
689 | # spare segment descriptor\r | |
690 | .equ SPARE4_SEL, .-GDT_BASE # Selector [0x40]\r | |
691 | .word 0 # limit 0xFFFFF\r | |
692 | .word 0 # base 0\r | |
693 | .byte 0\r | |
694 | .byte 0 # present, ring 0, data, expand-up, writable\r | |
695 | .byte 0 # page-granular, 32-bit\r | |
696 | .byte 0\r | |
697 | \r | |
698 | GDT_END: \r | |
699 | \r | |
9811c392 | 700 | .p2align 1\r |
f3eb2131 | 701 | \r |
702 | \r | |
703 | \r | |
704 | idtr: .long IDT_END - IDT_BASE - 1 # IDT limit\r | |
705 | .quad 0 # (IDT base gets set above)\r | |
706 | \r | |
707 | ##############################################################################\r | |
708 | # interrupt descriptor table (IDT)\r | |
709 | #\r | |
710 | # Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ\r | |
711 | # mappings. This implementation only uses the system timer and all other\r | |
712 | # IRQs will remain masked. The descriptors for vectors 33+ are provided\r | |
713 | # for convenience.\r | |
714 | ##############################################################################\r | |
715 | \r | |
716 | #idt_tag db "IDT",0 \r | |
9811c392 | 717 | .p2align 1\r |
f3eb2131 | 718 | \r |
719 | \r | |
720 | IDT_BASE: \r | |
721 | # divide by zero (INT 0)\r | |
722 | .equ DIV_ZERO_SEL, .-IDT_BASE\r | |
b29a823d | 723 | .word 0 # offset 15:0\r |
f3eb2131 | 724 | .long SYS_CODE64_SEL # selector 15:0\r |
725 | .byte 0 # 0 for interrupt gate\r | |
726 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 727 | .word 0 # offset 31:16\r |
728 | .long 0 # offset 63:32\r | |
729 | .long 0 # 0 for reserved\r | |
f3eb2131 | 730 | \r |
731 | # debug exception (INT 1)\r | |
732 | .equ DEBUG_EXCEPT_SEL, .-IDT_BASE\r | |
b29a823d | 733 | .word 0 # offset 15:0\r |
f3eb2131 | 734 | .long SYS_CODE64_SEL # selector 15:0\r |
735 | .byte 0 # 0 for interrupt gate\r | |
736 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 737 | .word 0 # offset 31:16\r |
738 | .long 0 # offset 63:32\r | |
739 | .long 0 # 0 for reserved\r | |
f3eb2131 | 740 | \r |
741 | # NMI (INT 2)\r | |
742 | .equ NMI_SEL, .-IDT_BASE\r | |
b29a823d | 743 | .word 0 # offset 15:0\r |
f3eb2131 | 744 | .long SYS_CODE64_SEL # selector 15:0\r |
745 | .byte 0 # 0 for interrupt gate\r | |
746 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 747 | .word 0 # offset 31:16\r |
748 | .long 0 # offset 63:32\r | |
749 | .long 0 # 0 for reserved\r | |
f3eb2131 | 750 | \r |
751 | # soft breakpoint (INT 3)\r | |
752 | .equ BREAKPOINT_SEL, .-IDT_BASE\r | |
b29a823d | 753 | .word 0 # offset 15:0\r |
f3eb2131 | 754 | .long SYS_CODE64_SEL # selector 15:0\r |
755 | .byte 0 # 0 for interrupt gate\r | |
756 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 757 | .word 0 # offset 31:16\r |
758 | .long 0 # offset 63:32\r | |
759 | .long 0 # 0 for reserved\r | |
f3eb2131 | 760 | \r |
761 | # overflow (INT 4)\r | |
762 | .equ OVERFLOW_SEL, .-IDT_BASE\r | |
b29a823d | 763 | .word 0 # offset 15:0\r |
f3eb2131 | 764 | .long SYS_CODE64_SEL # selector 15:0\r |
765 | .byte 0 # 0 for interrupt gate\r | |
766 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 767 | .word 0 # offset 31:16\r |
768 | .long 0 # offset 63:32\r | |
769 | .long 0 # 0 for reserved\r | |
f3eb2131 | 770 | \r |
771 | # bounds check (INT 5)\r | |
772 | .equ BOUNDS_CHECK_SEL, .-IDT_BASE\r | |
b29a823d | 773 | .word 0 # offset 15:0\r |
f3eb2131 | 774 | .long SYS_CODE64_SEL # selector 15:0\r |
775 | .byte 0 # 0 for interrupt gate\r | |
776 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 777 | .word 0 # offset 31:16\r |
778 | .long 0 # offset 63:32\r | |
779 | .long 0 # 0 for reserved\r | |
f3eb2131 | 780 | \r |
781 | # invalid opcode (INT 6)\r | |
782 | .equ INVALID_OPCODE_SEL, .-IDT_BASE\r | |
b29a823d | 783 | .word 0 # offset 15:0\r |
f3eb2131 | 784 | .long SYS_CODE64_SEL # selector 15:0\r |
785 | .byte 0 # 0 for interrupt gate\r | |
786 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 787 | .word 0 # offset 31:16\r |
788 | .long 0 # offset 63:32\r | |
789 | .long 0 # 0 for reserved\r | |
f3eb2131 | 790 | \r |
791 | # device not available (INT 7)\r | |
792 | .equ DEV_NOT_AVAIL_SEL, .-IDT_BASE\r | |
b29a823d | 793 | .word 0 # offset 15:0\r |
f3eb2131 | 794 | .long SYS_CODE64_SEL # selector 15:0\r |
795 | .byte 0 # 0 for interrupt gate\r | |
796 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 797 | .word 0 # offset 31:16\r |
798 | .long 0 # offset 63:32\r | |
799 | .long 0 # 0 for reserved\r | |
f3eb2131 | 800 | \r |
801 | # double fault (INT 8)\r | |
802 | .equ DOUBLE_FAULT_SEL, .-IDT_BASE\r | |
b29a823d | 803 | .word 0 # offset 15:0\r |
f3eb2131 | 804 | .long SYS_CODE64_SEL # selector 15:0\r |
805 | .byte 0 # 0 for interrupt gate\r | |
806 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 807 | .word 0 # offset 31:16\r |
808 | .long 0 # offset 63:32\r | |
809 | .long 0 # 0 for reserved\r | |
f3eb2131 | 810 | \r |
811 | # Coprocessor segment overrun - reserved (INT 9)\r | |
812 | .equ RSVD_INTR_SEL1, .-IDT_BASE\r | |
b29a823d | 813 | .word 0 # offset 15:0\r |
f3eb2131 | 814 | .long SYS_CODE64_SEL # selector 15:0\r |
815 | .byte 0 # 0 for interrupt gate\r | |
816 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 817 | .word 0 # offset 31:16\r |
818 | .long 0 # offset 63:32\r | |
819 | .long 0 # 0 for reserved\r | |
f3eb2131 | 820 | \r |
821 | # invalid TSS (INT 0ah)\r | |
822 | .equ INVALID_TSS_SEL, .-IDT_BASE\r | |
b29a823d | 823 | .word 0 # offset 15:0\r |
f3eb2131 | 824 | .long SYS_CODE64_SEL # selector 15:0\r |
825 | .byte 0 # 0 for interrupt gate\r | |
826 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 827 | .word 0 # offset 31:16\r |
828 | .long 0 # offset 63:32\r | |
829 | .long 0 # 0 for reserved\r | |
f3eb2131 | 830 | \r |
831 | # segment not present (INT 0bh)\r | |
832 | .equ SEG_NOT_PRESENT_SEL, .-IDT_BASE\r | |
b29a823d | 833 | .word 0 # offset 15:0\r |
f3eb2131 | 834 | .long SYS_CODE64_SEL # selector 15:0\r |
835 | .byte 0 # 0 for interrupt gate\r | |
836 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 837 | .word 0 # offset 31:16\r |
838 | .long 0 # offset 63:32\r | |
839 | .long 0 # 0 for reserved\r | |
f3eb2131 | 840 | \r |
841 | # stack fault (INT 0ch)\r | |
842 | .equ STACK_FAULT_SEL, .-IDT_BASE\r | |
b29a823d | 843 | .word 0 # offset 15:0\r |
f3eb2131 | 844 | .long SYS_CODE64_SEL # selector 15:0\r |
845 | .byte 0 # 0 for interrupt gate\r | |
846 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 847 | .word 0 # offset 31:16\r |
848 | .long 0 # offset 63:32\r | |
849 | .long 0 # 0 for reserved\r | |
f3eb2131 | 850 | \r |
851 | # general protection (INT 0dh)\r | |
852 | .equ GP_FAULT_SEL, .-IDT_BASE\r | |
b29a823d | 853 | .word 0 # offset 15:0\r |
f3eb2131 | 854 | .long SYS_CODE64_SEL # selector 15:0\r |
855 | .byte 0 # 0 for interrupt gate\r | |
856 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 857 | .word 0 # offset 31:16\r |
858 | .long 0 # offset 63:32\r | |
859 | .long 0 # 0 for reserved\r | |
f3eb2131 | 860 | \r |
861 | # page fault (INT 0eh)\r | |
862 | .equ PAGE_FAULT_SEL, .-IDT_BASE\r | |
b29a823d | 863 | .word 0 # offset 15:0\r |
f3eb2131 | 864 | .long SYS_CODE64_SEL # selector 15:0\r |
865 | .byte 0 # 0 for interrupt gate\r | |
866 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 867 | .word 0 # offset 31:16\r |
868 | .long 0 # offset 63:32\r | |
869 | .long 0 # 0 for reserved\r | |
f3eb2131 | 870 | \r |
871 | # Intel reserved - do not use (INT 0fh)\r | |
872 | .equ RSVD_INTR_SEL2, .-IDT_BASE\r | |
b29a823d | 873 | .word 0 # offset 15:0\r |
f3eb2131 | 874 | .long SYS_CODE64_SEL # selector 15:0\r |
875 | .byte 0 # 0 for interrupt gate\r | |
876 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 877 | .word 0 # offset 31:16\r |
878 | .long 0 # offset 63:32\r | |
879 | .long 0 # 0 for reserved\r | |
f3eb2131 | 880 | \r |
881 | # floating point error (INT 10h)\r | |
882 | .equ FLT_POINT_ERR_SEL, .-IDT_BASE\r | |
b29a823d | 883 | .word 0 # offset 15:0\r |
f3eb2131 | 884 | .long SYS_CODE64_SEL # selector 15:0\r |
885 | .byte 0 # 0 for interrupt gate\r | |
886 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 887 | .word 0 # offset 31:16\r |
888 | .long 0 # offset 63:32\r | |
889 | .long 0 # 0 for reserved\r | |
f3eb2131 | 890 | \r |
891 | # alignment check (INT 11h)\r | |
892 | .equ ALIGNMENT_CHECK_SEL, .-IDT_BASE\r | |
b29a823d | 893 | .word 0 # offset 15:0\r |
f3eb2131 | 894 | .long SYS_CODE64_SEL # selector 15:0\r |
895 | .byte 0 # 0 for interrupt gate\r | |
896 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 897 | .word 0 # offset 31:16\r |
898 | .long 0 # offset 63:32\r | |
899 | .long 0 # 0 for reserved\r | |
f3eb2131 | 900 | \r |
901 | # machine check (INT 12h)\r | |
902 | .equ MACHINE_CHECK_SEL, .-IDT_BASE\r | |
b29a823d | 903 | .word 0 # offset 15:0\r |
f3eb2131 | 904 | .long SYS_CODE64_SEL # selector 15:0\r |
905 | .byte 0 # 0 for interrupt gate\r | |
906 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 907 | .word 0 # offset 31:16\r |
908 | .long 0 # offset 63:32\r | |
909 | .long 0 # 0 for reserved\r | |
f3eb2131 | 910 | \r |
911 | # SIMD floating-point exception (INT 13h)\r | |
912 | .equ SIMD_EXCEPTION_SEL, .-IDT_BASE\r | |
b29a823d | 913 | .word 0 # offset 15:0\r |
f3eb2131 | 914 | .long SYS_CODE64_SEL # selector 15:0\r |
915 | .byte 0 # 0 for interrupt gate\r | |
916 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 917 | .word 0 # offset 31:16\r |
918 | .long 0 # offset 63:32\r | |
919 | .long 0 # 0 for reserved\r | |
f3eb2131 | 920 | \r |
921 | # 85 unspecified descriptors, First 12 of them are reserved, the rest are avail\r | |
b29a823d | 922 | .fill 85 * 16, 1, 0 # db (85 * 16) dup(0)\r |
f3eb2131 | 923 | \r |
924 | # IRQ 0 (System timer) - (INT 68h)\r | |
925 | .equ IRQ0_SEL, .-IDT_BASE\r | |
b29a823d | 926 | .word 0 # offset 15:0\r |
f3eb2131 | 927 | .long SYS_CODE64_SEL # selector 15:0\r |
928 | .byte 0 # 0 for interrupt gate\r | |
929 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 930 | .word 0 # offset 31:16\r |
931 | .long 0 # offset 63:32\r | |
932 | .long 0 # 0 for reserved\r | |
f3eb2131 | 933 | \r |
934 | # IRQ 1 (8042 Keyboard controller) - (INT 69h)\r | |
935 | .equ IRQ1_SEL, .-IDT_BASE\r | |
b29a823d | 936 | .word 0 # offset 15:0\r |
f3eb2131 | 937 | .long SYS_CODE64_SEL # selector 15:0\r |
938 | .byte 0 # 0 for interrupt gate\r | |
939 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 940 | .word 0 # offset 31:16\r |
941 | .long 0 # offset 63:32\r | |
942 | .long 0 # 0 for reserved\r | |
f3eb2131 | 943 | \r |
944 | # Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)\r | |
945 | .equ IRQ2_SEL, .-IDT_BASE\r | |
b29a823d | 946 | .word 0 # offset 15:0\r |
f3eb2131 | 947 | .long SYS_CODE64_SEL # selector 15:0\r |
948 | .byte 0 # 0 for interrupt gate\r | |
949 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 950 | .word 0 # offset 31:16\r |
951 | .long 0 # offset 63:32\r | |
952 | .long 0 # 0 for reserved\r | |
f3eb2131 | 953 | \r |
954 | # IRQ 3 (COM 2) - (INT 6bh)\r | |
955 | .equ IRQ3_SEL, .-IDT_BASE\r | |
b29a823d | 956 | .word 0 # offset 15:0\r |
f3eb2131 | 957 | .long SYS_CODE64_SEL # selector 15:0\r |
958 | .byte 0 # 0 for interrupt gate\r | |
959 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 960 | .word 0 # offset 31:16\r |
961 | .long 0 # offset 63:32\r | |
962 | .long 0 # 0 for reserved\r | |
f3eb2131 | 963 | \r |
964 | # IRQ 4 (COM 1) - (INT 6ch)\r | |
965 | .equ IRQ4_SEL, .-IDT_BASE\r | |
b29a823d | 966 | .word 0 # offset 15:0\r |
f3eb2131 | 967 | .long SYS_CODE64_SEL # selector 15:0\r |
968 | .byte 0 # 0 for interrupt gate\r | |
969 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 970 | .word 0 # offset 31:16\r |
971 | .long 0 # offset 63:32\r | |
972 | .long 0 # 0 for reserved\r | |
f3eb2131 | 973 | \r |
974 | # IRQ 5 (LPT 2) - (INT 6dh)\r | |
975 | .equ IRQ5_SEL, .-IDT_BASE\r | |
b29a823d | 976 | .word 0 # offset 15:0\r |
f3eb2131 | 977 | .long SYS_CODE64_SEL # selector 15:0\r |
978 | .byte 0 # 0 for interrupt gate\r | |
979 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 980 | .word 0 # offset 31:16\r |
981 | .long 0 # offset 63:32\r | |
982 | .long 0 # 0 for reserved\r | |
f3eb2131 | 983 | \r |
984 | # IRQ 6 (Floppy controller) - (INT 6eh)\r | |
985 | .equ IRQ6_SEL, .-IDT_BASE\r | |
b29a823d | 986 | .word 0 # offset 15:0\r |
f3eb2131 | 987 | .long SYS_CODE64_SEL # selector 15:0\r |
988 | .byte 0 # 0 for interrupt gate\r | |
989 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 990 | .word 0 # offset 31:16\r |
991 | .long 0 # offset 63:32\r | |
992 | .long 0 # 0 for reserved\r | |
f3eb2131 | 993 | \r |
994 | # IRQ 7 (LPT 1) - (INT 6fh)\r | |
995 | .equ IRQ7_SEL, .-IDT_BASE\r | |
b29a823d | 996 | .word 0 # offset 15:0\r |
f3eb2131 | 997 | .long SYS_CODE64_SEL # selector 15:0\r |
998 | .byte 0 # 0 for interrupt gate\r | |
999 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1000 | .word 0 # offset 31:16\r |
1001 | .long 0 # offset 63:32\r | |
1002 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1003 | \r |
1004 | # IRQ 8 (RTC Alarm) - (INT 70h)\r | |
1005 | .equ IRQ8_SEL, .-IDT_BASE\r | |
b29a823d | 1006 | .word 0 # offset 15:0\r |
f3eb2131 | 1007 | .long SYS_CODE64_SEL # selector 15:0\r |
1008 | .byte 0 # 0 for interrupt gate\r | |
1009 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1010 | .word 0 # offset 31:16\r |
1011 | .long 0 # offset 63:32\r | |
1012 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1013 | \r |
1014 | # IRQ 9 - (INT 71h)\r | |
1015 | .equ IRQ9_SEL, .-IDT_BASE\r | |
b29a823d | 1016 | .word 0 # offset 15:0\r |
f3eb2131 | 1017 | .long SYS_CODE64_SEL # selector 15:0\r |
1018 | .byte 0 # 0 for interrupt gate\r | |
1019 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1020 | .word 0 # offset 31:16\r |
1021 | .long 0 # offset 63:32\r | |
1022 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1023 | \r |
1024 | # IRQ 10 - (INT 72h)\r | |
1025 | .equ IRQ10_SEL, .-IDT_BASE\r | |
b29a823d | 1026 | .word 0 # offset 15:0\r |
f3eb2131 | 1027 | .long SYS_CODE64_SEL # selector 15:0\r |
1028 | .byte 0 # 0 for interrupt gate\r | |
1029 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1030 | .word 0 # offset 31:16\r |
1031 | .long 0 # offset 63:32\r | |
1032 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1033 | \r |
1034 | # IRQ 11 - (INT 73h)\r | |
1035 | .equ IRQ11_SEL, .-IDT_BASE\r | |
b29a823d | 1036 | .word 0 # offset 15:0\r |
f3eb2131 | 1037 | .long SYS_CODE64_SEL # selector 15:0\r |
1038 | .byte 0 # 0 for interrupt gate\r | |
1039 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1040 | .word 0 # offset 31:16\r |
1041 | .long 0 # offset 63:32\r | |
1042 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1043 | \r |
1044 | # IRQ 12 (PS/2 mouse) - (INT 74h)\r | |
1045 | .equ IRQ12_SEL, .-IDT_BASE\r | |
b29a823d | 1046 | .word 0 # offset 15:0\r |
f3eb2131 | 1047 | .long SYS_CODE64_SEL # selector 15:0\r |
1048 | .byte 0 # 0 for interrupt gate\r | |
1049 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1050 | .word 0 # offset 31:16\r |
1051 | .long 0 # offset 63:32\r | |
1052 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1053 | \r |
1054 | # IRQ 13 (Floating point error) - (INT 75h)\r | |
1055 | .equ IRQ13_SEL, .-IDT_BASE\r | |
b29a823d | 1056 | .word 0 # offset 15:0\r |
f3eb2131 | 1057 | .long SYS_CODE64_SEL # selector 15:0\r |
1058 | .byte 0 # 0 for interrupt gate\r | |
1059 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1060 | .word 0 # offset 31:16\r |
1061 | .long 0 # offset 63:32\r | |
1062 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1063 | \r |
1064 | # IRQ 14 (Secondary IDE) - (INT 76h)\r | |
1065 | .equ IRQ14_SEL, .-IDT_BASE\r | |
b29a823d | 1066 | .word 0 # offset 15:0\r |
f3eb2131 | 1067 | .long SYS_CODE64_SEL # selector 15:0\r |
1068 | .byte 0 # 0 for interrupt gate\r | |
1069 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1070 | .word 0 # offset 31:16\r |
1071 | .long 0 # offset 63:32\r | |
1072 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1073 | \r |
1074 | # IRQ 15 (Primary IDE) - (INT 77h)\r | |
1075 | .equ IRQ15_SEL, .-IDT_BASE\r | |
b29a823d | 1076 | .word 0 # offset 15:0\r |
f3eb2131 | 1077 | .long SYS_CODE64_SEL # selector 15:0\r |
1078 | .byte 0 # 0 for interrupt gate\r | |
1079 | .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r | |
b29a823d | 1080 | .word 0 # offset 31:16\r |
1081 | .long 0 # offset 63:32\r | |
1082 | .long 0 # 0 for reserved\r | |
f3eb2131 | 1083 | \r |
1084 | IDT_END: \r | |
1085 | \r | |
9811c392 | 1086 | .p2align 1\r |
f3eb2131 | 1087 | \r |
1088 | MemoryMapSize: .long 0\r | |
1089 | MemoryMap: .long 0,0,0,0,0,0,0,0\r | |
1090 | .long 0,0,0,0,0,0,0,0\r | |
1091 | .long 0,0,0,0,0,0,0,0\r | |
1092 | .long 0,0,0,0,0,0,0,0\r | |
1093 | .long 0,0,0,0,0,0,0,0\r | |
1094 | .long 0,0,0,0,0,0,0,0\r | |
1095 | .long 0,0,0,0,0,0,0,0\r | |
1096 | .long 0,0,0,0,0,0,0,0\r | |
1097 | .long 0,0,0,0,0,0,0,0\r | |
1098 | .long 0,0,0,0,0,0,0,0\r | |
1099 | .long 0,0,0,0,0,0,0,0\r | |
1100 | .long 0,0,0,0,0,0,0,0\r | |
1101 | .long 0,0,0,0,0,0,0,0\r | |
1102 | .long 0,0,0,0,0,0,0,0\r | |
1103 | .long 0,0,0,0,0,0,0,0\r | |
1104 | .long 0,0,0,0,0,0,0,0\r | |
1105 | .long 0,0,0,0,0,0,0,0\r | |
1106 | .long 0,0,0,0,0,0,0,0\r | |
1107 | .long 0,0,0,0,0,0,0,0\r | |
1108 | .long 0,0,0,0,0,0,0,0\r | |
1109 | .long 0,0,0,0,0,0,0,0\r | |
1110 | .long 0,0,0,0,0,0,0,0\r | |
1111 | .long 0,0,0,0,0,0,0,0\r | |
1112 | .long 0,0,0,0,0,0,0,0\r | |
1113 | .long 0,0,0,0,0,0,0,0\r | |
1114 | .long 0,0,0,0,0,0,0,0\r | |
1115 | .long 0,0,0,0,0,0,0,0\r | |
1116 | .long 0,0,0,0,0,0,0,0\r | |
1117 | .long 0,0,0,0,0,0,0,0\r | |
1118 | .long 0,0,0,0,0,0,0,0\r | |
1119 | \r | |
f3eb2131 | 1120 | .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\r |
1121 | \r | |
69b1c021 | 1122 | .org 0x0fe0\r |
f3eb2131 | 1123 | MyStack: \r |
1124 | # below is the pieces of the IVT that is used to redirect INT 68h - 6fh\r | |
1125 | # back to INT 08h - 0fh when in real mode... It is 'org'ed to a\r | |
1126 | # known low address (20f00) so it can be set up by PlMapIrqToVect in\r | |
1127 | # 8259.c\r | |
1128 | \r | |
1129 | int $8\r | |
1130 | iret\r | |
1131 | \r | |
1132 | int $9\r | |
1133 | iret\r | |
1134 | \r | |
1135 | int $10\r | |
1136 | iret\r | |
1137 | \r | |
1138 | int $11\r | |
1139 | iret\r | |
1140 | \r | |
1141 | int $12\r | |
1142 | iret\r | |
1143 | \r | |
1144 | int $13\r | |
1145 | iret\r | |
1146 | \r | |
1147 | int $14\r | |
1148 | iret\r | |
1149 | \r | |
1150 | int $15\r | |
1151 | iret\r | |
1152 | \r | |
1153 | \r | |
69b1c021 | 1154 | .org 0x0ffe\r |
f3eb2131 | 1155 | BlockSignature: \r |
1156 | .word 0xaa55\r | |
1157 | \r |