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