]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/BootSector/start.S
Remove exit from batch file
[mirror_edk2.git] / DuetPkg / BootSector / start.S
CommitLineData
819958c6 1#------------------------------------------------------------------------------\r
2#*\r
3#* Copyright 2006 - 2007, Intel Corporation \r
4#* All rights reserved. This program and the accompanying materials \r
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#* start.S\r
13#* \r
14#* Abstract:\r
15#*\r
16#------------------------------------------------------------------------------\r
17\r
88e9055e 18 .stack: \r
19 .486p: \r
20 .code16\r
819958c6 21 \r
22.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020\r
23.equ FAT_DIRECTORY_ENTRY_SHIFT, 5\r
24.equ BLOCK_SIZE, 0x0200\r
25.equ BLOCK_MASK, 0x01ff\r
26.equ BLOCK_SHIFT, 9\r
27\r
28 .org 0x0\r
29Ia32Jump: \r
30 jmp BootSectorEntryPoint # JMP inst - 3 bytes\r
31 nop\r
32\r
33OemId: .ascii "INTEL " # OemId - 8 bytes\r
34\r
35SectorSize: .word 0 # Sector Size - 16 bits\r
36SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits\r
37ReservedSectors: .word 0 # Reserved Sectors - 16 bits\r
38NoFats: .byte 0 # Number of FATs - 8 bits\r
39RootEntries: .word 0 # Root Entries - 16 bits\r
40Sectors: .word 0 # Number of Sectors - 16 bits\r
41Media: .byte 0 # Media - 8 bits - ignored\r
42SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits\r
43SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored\r
44Heads: .word 0 # Heads - 16 bits - ignored\r
45HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored\r
46LargeSectors: .long 0 # Large Sectors - 32 bits \r
47PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored\r
48CurrentHead: .byte 0 # Current Head - 8 bits\r
49Signature: .byte 0 # Signature - 8 bits - ignored\r
50VolId: .ascii " " # Volume Serial Number- 4 bytes\r
51FatLabel: .ascii " " # Label - 11 bytes\r
52SystemId: .ascii "FAT12 " # SystemId - 8 bytes\r
53\r
54BootSectorEntryPoint: \r
55 #ASSUME ds:@code\r
56 #ASSUME ss:@code\r
57 # ds = 1000, es = 2000 + x (size of first cluster >> 4)\r
58 # cx = Start Cluster of EfiLdr\r
59 # dx = Start Cluster of Efivar.bin\r
60\r
61# Re use the BPB data stored in Boot Sector\r
62 movw $0x7c00, %bp\r
63\r
64 pushw %cx\r
65# Read Efivar.bin\r
66# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already\r
67 movw $0x1900, %ax\r
68 movw %ax, %es\r
69 testw %dx, %dx\r
70 jnz CheckVarStoreSize\r
71\r
72 movb $1, %al\r
73NoVarStore: \r
74 pushw %es\r
75# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl\r
640a2e52 76 movb %al, %es:(4)\r
819958c6 77 jmp SaveVolumeId\r
78\r
79CheckVarStoreSize: \r
80 movw %dx, %di\r
81 cmpl $0x4000, %ds:2(%di)\r
82 movb $2, %al\r
83 jne NoVarStore\r
84\r
85LoadVarStore: \r
86 movb $0, %al\r
f3fb74cd 87 movb %al, %es:(4)\r
819958c6 88 movw (%di), %cx\r
89# ES:DI = 1500:0\r
90 xorw %di, %di\r
91 pushw %es\r
92 movw $0x1500, %ax\r
93 movw %ax, %es\r
94 call ReadFile\r
95SaveVolumeId: \r
96 popw %es\r
97 movw VolId(%bp), %ax\r
f3fb74cd 98 movw %ax, %es:(0) # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId\r
819958c6 99 movw VolId+2(%bp), %ax\r
f3fb74cd 100 movw %ax, %es:(2)\r
819958c6 101\r
102# Read Efildr\r
103 popw %cx\r
104# cx = Start Cluster of Efildr -> BS.com has filled already\r
105# ES:DI = 2000:0, first cluster will be read again\r
106 xorw %di, %di # di = 0\r
107 movw $0x2000, %ax\r
108 movw %ax, %es\r
109 call ReadFile\r
110 movw %cs, %ax\r
111 movw %ax, %cs:JumpSegment\r
112\r
113JumpFarInstruction: \r
114 .byte 0xea\r
115JumpOffset: \r
116 .word 0x200\r
117JumpSegment: \r
118 .word 0x2000\r
119\r
120\r
121\r
122# ****************************************************************************\r
123# ReadFile\r
124#\r
125# Arguments:\r
126# CX = Start Cluster of File\r
127# ES:DI = Buffer to store file content read from disk\r
128#\r
129# Return:\r
130# (ES << 4 + DI) = end of file content Buffer\r
131#\r
132# ****************************************************************************\r
133ReadFile: \r
134# si = NumberOfClusters\r
135# cx = ClusterNumber\r
136# dx = CachedFatSectorNumber\r
137# ds:0000 = CacheFatSectorBuffer\r
138# es:di = Buffer to load file\r
139# bx = NextClusterNumber\r
140 pusha\r
141 movw $1, %si # NumberOfClusters = 1\r
142 pushw %cx # Push Start Cluster onto stack\r
143 movw $0xfff, %dx # CachedFatSectorNumber = 0xfff\r
144FatChainLoop: \r
145 movw %cx, %ax # ax = ClusterNumber \r
146 andw $0xff8, %ax # ax = ax & 0xff8\r
147 cmpw $0xff8, %ax # See if this is the last cluster\r
148 je FoundLastCluster # Jump if last cluster found\r
149 movw %cx, %ax # ax = ClusterNumber\r
150 shlw %ax # ax = ClusterNumber * 2\r
151 addw %cx, %ax # ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3\r
152 shrw %ax # FatOffset = ClusterNumber*3 / 2\r
153 pushw %si # Save si\r
154 movw %ax, %si # si = FatOffset\r
ccec4c39 155 shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT\r
819958c6 156 addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)\r
ccec4c39 157 andw $BLOCK_MASK,%si # si = FatOffset & BLOCK_MASK\r
819958c6 158 cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber\r
159 je SkipFatRead\r
160 movw $2, %bx\r
161 pushw %es\r
162 pushw %ds\r
163 popw %es\r
164 call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI\r
165 popw %es\r
166 movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber\r
167SkipFatRead: \r
168 movw (%si), %bx # bx = NextClusterNumber\r
169 movw %cx, %ax # ax = ClusterNumber\r
170 andw $1, %ax # See if this is an odd cluster number\r
171 je EvenFatEntry\r
172 shrw $4, %bx # NextClusterNumber = NextClusterNumber >> 4\r
173EvenFatEntry: \r
174 andw $0xfff, %bx # Strip upper 4 bits of NextClusterNumber\r
175 popw %si # Restore si\r
176 decw %bx # bx = NextClusterNumber - 1\r
177 cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber\r
178 jne ReadClusters\r
179 incw %bx # bx = NextClusterNumber\r
180 incw %si # NumberOfClusters++\r
181 movw %bx, %cx # ClusterNumber = NextClusterNumber\r
182 jmp FatChainLoop\r
183ReadClusters: \r
184 incw %bx\r
185 popw %ax # ax = StartCluster\r
186 pushw %bx # StartCluster = NextClusterNumber\r
187 movw %bx, %cx # ClusterNumber = NextClusterNumber\r
188 subw $2, %ax # ax = StartCluster - 2\r
189 xorb %bh, %bh\r
190 movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster\r
191 mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster\r
192 addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster\r
193 pushw %ax # save start sector\r
194 movw %si, %ax # ax = NumberOfClusters\r
195 mulw %bx # ax = NumberOfClusters * SectorsPerCluster\r
196 movw %ax, %bx # bx = Number of Sectors\r
197 popw %ax # ax = Start Sector\r
198 call ReadBlocks\r
199 movw $1, %si # NumberOfClusters = 1\r
200 jmp FatChainLoop\r
201FoundLastCluster: \r
202 popw %cx\r
203 popa\r
204 ret\r
205\r
206\r
207# ****************************************************************************\r
208# ReadBlocks - Reads a set of blocks from a block device\r
209#\r
210# AX = Start LBA\r
211# BX = Number of Blocks to Read\r
212# ES:DI = Buffer to store sectors read from disk\r
213# ****************************************************************************\r
214\r
215# cx = Blocks\r
216# bx = NumberOfBlocks\r
217# si = StartLBA\r
218\r
219ReadBlocks: \r
220 pusha\r
221 addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA\r
222 addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA\r
223 movl %eax, %esi # esi = Start LBA\r
224 movw %bx, %cx # cx = Number of blocks to read\r
225ReadCylinderLoop: \r
226 movw $0x7bfc, %bp # bp = 0x7bfc\r
227 movl %esi, %eax # eax = Start LBA\r
228 xorl %edx, %edx # edx = 0\r
229 movzwl (%bp), %ebx # bx = MaxSector\r
230 divl %ebx # ax = StartLBA / MaxSector\r
231 incw %dx # dx = (StartLBA % MaxSector) + 1\r
232\r
233 movw (%bp), %bx # bx = MaxSector\r
234 subw %dx, %bx # bx = MaxSector - Sector\r
235 incw %bx # bx = MaxSector - Sector + 1\r
236 cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)\r
237 jg LimitTransfer\r
238 movw %cx, %bx # bx = Blocks\r
239LimitTransfer: \r
240 pushw %ax # save ax\r
241 movw %es, %ax # ax = es\r
f3fb74cd 242 shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system\r
819958c6 243 andw $0x7f, %ax # ax = Number of blocks into current seg\r
244 addw %bx, %ax # ax = End Block number of transfer\r
245 cmpw $0x80, %ax # See if it crosses a 64K boundry\r
246 jle NotCrossing64KBoundry # Branch if not crossing 64K boundry\r
247 subw $0x80, %ax # ax = Number of blocks past 64K boundry\r
248 subw %ax, %bx # Decrease transfer size by block overage\r
249NotCrossing64KBoundry: \r
250 popw %ax # restore ax\r
251\r
252 pushw %cx\r
253 movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector\r
254 xorw %dx, %dx # dx = 0\r
255 divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder \r
256 # dx = ax % (MaxHead + 1) = Head\r
257\r
258 pushw %bx # Save number of blocks to transfer\r
259 movb %dl, %dh # dh = Head\r
260 movw $0x7c00, %bp # bp = 0x7c00\r
261 movb PhysicalDrive(%bp), %dl # dl = Drive Number\r
262 movb %al, %ch # ch = Cylinder\r
263 movb %bl, %al # al = Blocks\r
264 movb $2, %ah # ah = Function 2\r
265 movw %di, %bx # es:bx = Buffer address\r
266 int $0x13\r
267 jc DiskError\r
268 popw %bx\r
269 popw %cx\r
270 movzwl %bx, %ebx\r
271 addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks\r
272 subw %bx, %cx # Blocks = Blocks - NumberOfBlocks\r
273 movw %es, %ax\r
f3fb74cd 274 shlw $(BLOCK_SHIFT-4), %bx\r
819958c6 275 addw %bx, %ax\r
276 movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE\r
277 cmpw $0, %cx\r
278 jne ReadCylinderLoop\r
279 popa\r
280 ret\r
281\r
282DiskError: \r
283 pushw %cs\r
284 popw %ds\r
ccec4c39 285 leaw ErrorString, %si\r
819958c6 286 movw $7, %cx\r
287 jmp PrintStringAndHalt\r
288\r
289PrintStringAndHalt: \r
290 movw $0xb800, %ax\r
291 movw %ax, %es\r
292 movw $160, %di\r
293 rep\r
294 movsw\r
295Halt: \r
296 jmp Halt\r
297\r
298ErrorString: \r
299 .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c\r
300\r
f3fb74cd 301 .org 0x01fa\r
819958c6 302LBAOffsetForBootSector: \r
303 .long 0x0\r
304\r
f3fb74cd 305 .org 0x01fe\r
819958c6 306 .word 0xaa55\r
307\r
308#******************************************************************************\r
309#******************************************************************************\r
310#******************************************************************************\r
311\r
312.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay\r
313.equ KBD_CONTROL_PORT, 0x060 # 8042 control port \r
314.equ KBD_STATUS_PORT, 0x064 # 8042 status port \r
315.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port\r
316.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20\r
317\r
318 #.org 0x200\r
319 jmp start\r
320Em64String: \r
321 .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
322\r
323start: \r
324 movw %cs, %ax\r
325 movw %ax, %ds\r
326 movw %ax, %es\r
327 movw %ax, %ss\r
328 movw $MyStack, %sp\r
329\r
330# mov ax,0b800h\r
331# mov es,ax\r
332# mov byte ptr es:[160],'a'\r
333# mov ax,cs\r
334# mov es,ax\r
335\r
336 movl $0, %ebx\r
337 leal MemoryMap, %edi\r
338MemMapLoop: \r
339 movl $0xe820, %eax\r
340 movl $20, %ecx\r
9ffd16fb 341 movl $0x534d4150, %edx # SMAP\r
819958c6 342 int $0x15\r
343 jc MemMapDone\r
344 addl $20, %edi\r
345 cmpl $0, %ebx\r
346 je MemMapDone\r
347 jmp MemMapLoop\r
348MemMapDone: \r
349 leal MemoryMap, %eax\r
350 subl %eax, %edi # Get the address of the memory map\r
351 movl %edi, MemoryMapSize # Save the size of the memory map\r
352\r
353 xorl %ebx, %ebx\r
354 movw %cs, %bx # BX=segment\r
355 shll $4, %ebx # BX="linear" address of segment base\r
356 leal GDT_BASE(%ebx), %eax #\r
357 movl %eax, (gdtr + 2) #\r
358 leal IDT_BASE(%ebx), %eax #\r
359 movl %eax, (idtr + 2) #\r
360 leal MemoryMapSize(%ebx), %edx #\r
361\r
362 addl $0x1000, %ebx # Source of EFI32\r
363 movl %ebx, JUMP+2\r
364 addl $0x1000, %ebx\r
365 movl %ebx, %esi # Source of EFILDR32\r
366\r
367# mov ax,0b800h\r
368# mov es,ax\r
369# mov byte ptr es:[162],'b'\r
370# mov ax,cs\r
371# mov es,ax\r
372\r
373#\r
374# Enable A20 Gate \r
375#\r
376\r
377 movw $0x2401, %ax # Enable A20 Gate\r
378 int $0x15\r
379 jnc A20GateEnabled # Jump if it suceeded\r
380\r
381#\r
382# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.\r
383#\r
384\r
385 call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller\r
386 jnz Timeout8042 # Jump if the 8042 timed out\r
387 outw %ax, $DELAY_PORT # Delay 1 uS\r
388 mov $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port\r
389 out %al, $KBD_STATUS_PORT # Send command to the 8042\r
390 call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller\r
391 jnz Timeout8042 # Jump if the 8042 timed out\r
392 mov $ENABLE_A20_CMD, %al # gate address bit 20 on\r
393 out %al, $KBD_CONTROL_PORT # Send command to thre 8042\r
394 call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller\r
395 movw $25, %cx # Delay 25 uS for the command to complete on the 8042\r
396Delay25uS: \r
397 outw %ax, $DELAY_PORT # Delay 1 uS\r
398 loop Delay25uS\r
399Timeout8042: \r
400\r
401\r
402A20GateEnabled: \r
403\r
404#\r
405# DISABLE INTERRUPTS - Entering Protected Mode\r
406#\r
407\r
408 cli\r
409\r
410# mov ax,0b800h\r
411# mov es,ax\r
412# mov byte ptr es:[164],'c'\r
413# mov ax,cs\r
414# mov es,ax\r
415\r
416 .byte 0x66\r
417 lgdt gdtr\r
418 .byte 0x66\r
419 lidt idtr\r
420\r
421 movl %cr0, %eax\r
422 orb $1, %al\r
423 movl %eax, %cr0\r
424\r
425 movl $0x008, %eax # Flat data descriptor\r
426 movl $0x00400000, %ebp # Destination of EFILDR32\r
427 movl $0x00070000, %ebx # Length of copy\r
428\r
429JUMP: \r
430# jmp far 0010:00020000\r
431 .byte 0x66\r
432 .byte 0xea\r
433 .long 0x00020000\r
434 .word 0x0010\r
435\r
436Empty8042InputBuffer: \r
437 movw $0, %cx\r
438Empty8042Loop: \r
439 outw %ax, $DELAY_PORT # Delay 1us\r
440 in $KBD_STATUS_PORT, %al # Read the 8042 Status Port\r
441 andb $0x2, %al # Check the Input Buffer Full Flag\r
442 loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS\r
443 ret\r
444\r
445##############################################################################\r
446# data\r
447##############################################################################\r
448\r
449 .align 0x2\r
450\r
451 gdtr: .long GDT_END - GDT_BASE - 1 # GDT limit \r
452 .long 0 # (GDT base gets set above)\r
453##############################################################################\r
454# global descriptor table (GDT)\r
455##############################################################################\r
456\r
457 .align 0x2\r
458\r
459GDT_BASE: \r
460# null descriptor\r
461.equ NULL_SEL, .-GDT_BASE\r
462 .word 0 # limit 15:0\r
463 .word 0 # base 15:0\r
464 .byte 0 # base 23:16\r
465 .byte 0 # type\r
466 .byte 0 # limit 19:16, flags\r
467 .byte 0 # base 31:24\r
468\r
469# linear data segment descriptor\r
470.equ LINEAR_SEL, .-GDT_BASE\r
471 .word 0xFFFF # limit 0xFFFFF\r
472 .word 0 # base 0\r
473 .byte 0\r
474 .byte 0x92 # present, ring 0, data, expand-up, writable\r
475 .byte 0xCF # page-granular, 32-bit\r
476 .byte 0\r
477\r
478# linear code segment descriptor\r
479.equ LINEAR_CODE_SEL, .-GDT_BASE\r
480 .word 0xFFFF # limit 0xFFFFF\r
481 .word 0 # base 0\r
482 .byte 0\r
483 .byte 0x9A # present, ring 0, data, expand-up, writable\r
484 .byte 0xCF # page-granular, 32-bit\r
485 .byte 0\r
486\r
487# system data segment descriptor\r
488.equ SYS_DATA_SEL, .-GDT_BASE\r
489 .word 0xFFFF # limit 0xFFFFF\r
490 .word 0 # base 0\r
491 .byte 0\r
492 .byte 0x92 # present, ring 0, data, expand-up, writable\r
493 .byte 0xCF # page-granular, 32-bit\r
494 .byte 0\r
495\r
496# system code segment descriptor\r
497.equ SYS_CODE_SEL, .-GDT_BASE\r
498 .word 0xFFFF # limit 0xFFFFF\r
499 .word 0 # base 0\r
500 .byte 0\r
501 .byte 0x9A # present, ring 0, data, expand-up, writable\r
502 .byte 0xCF # page-granular, 32-bit\r
503 .byte 0\r
504\r
505# spare segment descriptor\r
506.equ SPARE3_SEL, .-GDT_BASE\r
507 .word 0 # limit 0xFFFFF\r
508 .word 0 # base 0\r
509 .byte 0\r
510 .byte 0 # present, ring 0, data, expand-up, writable\r
511 .byte 0 # page-granular, 32-bit\r
512 .byte 0\r
513\r
514# spare segment descriptor\r
515.equ SPARE4_SEL, .-GDT_BASE\r
516 .word 0 # limit 0xFFFFF\r
517 .word 0 # base 0\r
518 .byte 0\r
519 .byte 0 # present, ring 0, data, expand-up, writable\r
520 .byte 0 # page-granular, 32-bit\r
521 .byte 0\r
522\r
523# spare segment descriptor\r
524.equ SPARE5_SEL, .-GDT_BASE\r
525 .word 0 # limit 0xFFFFF\r
526 .word 0 # base 0\r
527 .byte 0\r
528 .byte 0 # present, ring 0, data, expand-up, writable\r
529 .byte 0 # page-granular, 32-bit\r
530 .byte 0\r
531\r
532GDT_END: \r
533\r
534 .align 0x2\r
535\r
536\r
537\r
538idtr: .long IDT_END - IDT_BASE - 1 # IDT limit\r
539 .long 0 # (IDT base gets set above)\r
540##############################################################################\r
541# interrupt descriptor table (IDT)\r
542#\r
543# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ\r
544# mappings. This implementation only uses the system timer and all other\r
545# IRQs will remain masked. The descriptors for vectors 33+ are provided\r
546# for convenience.\r
547##############################################################################\r
548\r
549#idt_tag db "IDT",0 \r
550 .align 0x2\r
551\r
552IDT_BASE: \r
553# divide by zero (INT 0)\r
554.equ DIV_ZERO_SEL, .-IDT_BASE\r
555 .word 0 # offset 15:0\r
556 .long SYS_CODE_SEL # selector 15:0\r
557 .byte 0 # 0 for interrupt gate\r
558 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
559 .word 0 # offset 31:16\r
560\r
561# debug exception (INT 1)\r
562.equ DEBUG_EXCEPT_SEL, .-IDT_BASE\r
563 .word 0 # offset 15:0\r
564 .long SYS_CODE_SEL # selector 15:0\r
565 .byte 0 # 0 for interrupt gate\r
566 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
567 .word 0 # offset 31:16\r
568\r
569# NMI (INT 2)\r
570.equ NMI_SEL, .-IDT_BASE\r
571 .word 0 # offset 15:0\r
572 .long SYS_CODE_SEL # selector 15:0\r
573 .byte 0 # 0 for interrupt gate\r
574 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
575 .word 0 # offset 31:16\r
576\r
577# soft breakpoint (INT 3)\r
578.equ BREAKPOINT_SEL, .-IDT_BASE\r
579 .word 0 # offset 15:0\r
580 .long SYS_CODE_SEL # selector 15:0\r
581 .byte 0 # 0 for interrupt gate\r
582 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
583 .word 0 # offset 31:16\r
584\r
585# overflow (INT 4)\r
586.equ OVERFLOW_SEL, .-IDT_BASE\r
587 .word 0 # offset 15:0\r
588 .long SYS_CODE_SEL # selector 15:0\r
589 .byte 0 # 0 for interrupt gate\r
590 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
591 .word 0 # offset 31:16\r
592\r
593# bounds check (INT 5)\r
594.equ BOUNDS_CHECK_SEL, .-IDT_BASE\r
595 .word 0 # offset 15:0\r
596 .long SYS_CODE_SEL # selector 15:0\r
597 .byte 0 # 0 for interrupt gate\r
598 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
599 .word 0 # offset 31:16\r
600\r
601# invalid opcode (INT 6)\r
602.equ INVALID_OPCODE_SEL, .-IDT_BASE\r
603 .word 0 # offset 15:0\r
604 .long SYS_CODE_SEL # selector 15:0\r
605 .byte 0 # 0 for interrupt gate\r
606 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
607 .word 0 # offset 31:16\r
608\r
609# device not available (INT 7)\r
610.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE\r
611 .word 0 # offset 15:0\r
612 .long SYS_CODE_SEL # selector 15:0\r
613 .byte 0 # 0 for interrupt gate\r
614 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
615 .word 0 # offset 31:16\r
616\r
617# double fault (INT 8)\r
618.equ DOUBLE_FAULT_SEL, .-IDT_BASE\r
619 .word 0 # offset 15:0\r
620 .long SYS_CODE_SEL # selector 15:0\r
621 .byte 0 # 0 for interrupt gate\r
622 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
623 .word 0 # offset 31:16\r
624\r
625# Coprocessor segment overrun - reserved (INT 9)\r
626.equ RSVD_INTR_SEL1, .-IDT_BASE\r
627 .word 0 # offset 15:0\r
628 .long SYS_CODE_SEL # selector 15:0\r
629 .byte 0 # 0 for interrupt gate\r
630 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
631 .word 0 # offset 31:16\r
632\r
633# invalid TSS (INT 0x0a)\r
634.equ INVALID_TSS_SEL, .-IDT_BASE\r
635 .word 0 # offset 15:0\r
636 .long SYS_CODE_SEL # selector 15:0\r
637 .byte 0 # 0 for interrupt gate\r
638 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
639 .word 0 # offset 31:16\r
640\r
641# segment not present (INT 0x0b)\r
642.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE\r
643 .word 0 # offset 15:0\r
644 .long SYS_CODE_SEL # selector 15:0\r
645 .byte 0 # 0 for interrupt gate\r
646 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
647 .word 0 # offset 31:16\r
648\r
649# stack fault (INT 0x0c)\r
650.equ STACK_FAULT_SEL, .-IDT_BASE\r
651 .word 0 # offset 15:0\r
652 .long SYS_CODE_SEL # selector 15:0\r
653 .byte 0 # 0 for interrupt gate\r
654 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
655 .word 0 # offset 31:16\r
656\r
657# general protection (INT 0x0d)\r
658.equ GP_FAULT_SEL, .-IDT_BASE\r
659 .word 0 # offset 15:0\r
660 .long SYS_CODE_SEL # selector 15:0\r
661 .byte 0 # 0 for interrupt gate\r
662 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
663 .word 0 # offset 31:16\r
664\r
665# page fault (INT 0x0e)\r
666.equ PAGE_FAULT_SEL, .-IDT_BASE\r
667 .word 0 # offset 15:0\r
668 .long SYS_CODE_SEL # selector 15:0\r
669 .byte 0 # 0 for interrupt gate\r
670 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
671 .word 0 # offset 31:16\r
672\r
673# Intel reserved - do not use (INT 0x0f)\r
674.equ RSVD_INTR_SEL2, .-IDT_BASE\r
675 .word 0 # offset 15:0\r
676 .long SYS_CODE_SEL # selector 15:0\r
677 .byte 0 # 0 for interrupt gate\r
678 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
679 .word 0 # offset 31:16\r
680\r
681# floating point error (INT 0x10)\r
682.equ FLT_POINT_ERR_SEL, .-IDT_BASE\r
683 .word 0 # offset 15:0\r
684 .long SYS_CODE_SEL # selector 15:0\r
685 .byte 0 # 0 for interrupt gate\r
686 .byte 0x0e | 0x80 # type = 386 interrupt gate, present\r
687 .word 0 # offset 31:16\r
688\r
689# alignment check (INT 0x11)\r
690.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE\r
691 .word 0 # offset 15:0\r
692 .long SYS_CODE_SEL # selector 15:0\r
693 .byte 0 # 0 for interrupt gate\r
694 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
695 .word 0 # offset 31:16\r
696\r
697# machine check (INT 0x12)\r
698.equ MACHINE_CHECK_SEL, .-IDT_BASE\r
699 .word 0 # offset 15:0\r
700 .long SYS_CODE_SEL # selector 15:0\r
701 .byte 0 # 0 for interrupt gate\r
702 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
703 .word 0 # offset 31:16\r
704\r
705# SIMD floating-point exception (INT 0x13)\r
706.equ SIMD_EXCEPTION_SEL, .-IDT_BASE\r
707 .word 0 # offset 15:0\r
708 .long SYS_CODE_SEL # selector 15:0\r
709 .byte 0 # 0 for interrupt gate\r
710 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
711 .word 0 # offset 31:16\r
712\r
713# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail\r
714 .fill 85 * 8, 1, 0 # db (85 * 8) dup(0)\r
715\r
716# IRQ 0 (System timer) - (INT 0x68)\r
717.equ IRQ0_SEL, .-IDT_BASE\r
718 .word 0 # offset 15:0\r
719 .long SYS_CODE_SEL # selector 15:0\r
720 .byte 0 # 0 for interrupt gate\r
721 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
722 .word 0 # offset 31:16\r
723\r
724# IRQ 1 (8042 Keyboard controller) - (INT 0x69)\r
725.equ IRQ1_SEL, .-IDT_BASE\r
726 .word 0 # offset 15:0\r
727 .long SYS_CODE_SEL # selector 15:0\r
728 .byte 0 # 0 for interrupt gate\r
729 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
730 .word 0 # offset 31:16\r
731\r
732# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 0x6a)\r
733.equ IRQ2_SEL, .-IDT_BASE\r
734 .word 0 # offset 15:0\r
735 .long SYS_CODE_SEL # selector 15:0\r
736 .byte 0 # 0 for interrupt gate\r
737 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
738 .word 0 # offset 31:16\r
739\r
740# IRQ 3 (COM 2) - (INT 0x6b)\r
741.equ IRQ3_SEL, .-IDT_BASE\r
742 .word 0 # offset 15:0\r
743 .long SYS_CODE_SEL # selector 15:0\r
744 .byte 0 # 0 for interrupt gate\r
745 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
746 .word 0 # offset 31:16\r
747\r
748# IRQ 4 (COM 1) - (INT 0x6c)\r
749.equ IRQ4_SEL, .-IDT_BASE\r
750 .word 0 # offset 15:0\r
751 .long SYS_CODE_SEL # selector 15:0\r
752 .byte 0 # 0 for interrupt gate\r
753 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
754 .word 0 # offset 31:16\r
755\r
756# IRQ 5 (LPT 2) - (INT 0x6d)\r
757.equ IRQ5_SEL, .-IDT_BASE\r
758 .word 0 # offset 15:0\r
759 .long SYS_CODE_SEL # selector 15:0\r
760 .byte 0 # 0 for interrupt gate\r
761 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
762 .word 0 # offset 31:16\r
763\r
764# IRQ 6 (Floppy controller) - (INT 0x6e)\r
765.equ IRQ6_SEL, .-IDT_BASE\r
766 .word 0 # offset 15:0\r
767 .long SYS_CODE_SEL # selector 15:0\r
768 .byte 0 # 0 for interrupt gate\r
769 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
770 .word 0 # offset 31:16\r
771\r
772# IRQ 7 (LPT 1) - (INT 0x6f)\r
773.equ IRQ7_SEL, .-IDT_BASE\r
774 .word 0 # offset 15:0\r
775 .long SYS_CODE_SEL # selector 15:0\r
776 .byte 0 # 0 for interrupt gate\r
777 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
778 .word 0 # offset 31:16\r
779\r
780# IRQ 8 (RTC Alarm) - (INT 0x70)\r
781.equ IRQ8_SEL, .-IDT_BASE\r
782 .word 0 # offset 15:0\r
783 .long SYS_CODE_SEL # selector 15:0\r
784 .byte 0 # 0 for interrupt gate\r
785 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
786 .word 0 # offset 31:16\r
787\r
788# IRQ 9 - (INT 0x71)\r
789.equ IRQ9_SEL, .-IDT_BASE\r
790 .word 0 # offset 15:0\r
791 .long SYS_CODE_SEL # selector 15:0\r
792 .byte 0 # 0 for interrupt gate\r
793 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
794 .word 0 # offset 31:16\r
795\r
796# IRQ 10 - (INT 0x72)\r
797.equ IRQ10_SEL, .-IDT_BASE\r
798 .word 0 # offset 15:0\r
799 .long SYS_CODE_SEL # selector 15:0\r
800 .byte 0 # 0 for interrupt gate\r
801 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
802 .word 0 # offset 31:16\r
803\r
804# IRQ 11 - (INT 0x73)\r
805.equ IRQ11_SEL, .-IDT_BASE\r
806 .word 0 # offset 15:0\r
807 .long SYS_CODE_SEL # selector 15:0\r
808 .byte 0 # 0 for interrupt gate\r
809 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
810 .word 0 # offset 31:16\r
811\r
812# IRQ 12 (PS/2 mouse) - (INT 0x74)\r
813.equ IRQ12_SEL, .-IDT_BASE\r
814 .word 0 # offset 15:0\r
815 .long SYS_CODE_SEL # selector 15:0\r
816 .byte 0 # 0 for interrupt gate\r
817 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
818 .word 0 # offset 31:16\r
819 \r
820# IRQ 13 (Floating point error) - (INT 0x75)\r
821.equ IRQ13_SEL, .-IDT_BASE\r
822 .word 0 # offset 15:0\r
823 .long SYS_CODE_SEL # selector 15:0\r
824 .byte 0 # 0 for interrupt gate\r
825 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
826 .word 0 # offset 31:16\r
827\r
828# IRQ 14 (Secondary IDE) - (INT 0x76)\r
829.equ IRQ14_SEL, .-IDT_BASE\r
830 .word 0 # offset 15:0\r
831 .long SYS_CODE_SEL # selector 15:0\r
832 .byte 0 # 0 for interrupt gate\r
833 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
834 .word 0 # offset 31:16\r
835\r
836# IRQ 15 (Primary IDE) - (INT 0x77)\r
837.equ IRQ15_SEL, .-IDT_BASE\r
838 .word 0 # offset 15:0\r
839 .long SYS_CODE_SEL # selector 15:0\r
840 .byte 0 # 0 for interrupt gate\r
841 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present\r
842 .word 0 # offset 31:16\r
843\r
844IDT_END: \r
845\r
846 .align 0x2\r
847\r
848MemoryMapSize: .long 0\r
849MemoryMap: .long 0,0,0,0,0,0,0,0\r
850 .long 0,0,0,0,0,0,0,0\r
851 .long 0,0,0,0,0,0,0,0\r
852 .long 0,0,0,0,0,0,0,0\r
853 .long 0,0,0,0,0,0,0,0\r
854 .long 0,0,0,0,0,0,0,0\r
855 .long 0,0,0,0,0,0,0,0\r
856 .long 0,0,0,0,0,0,0,0\r
857 .long 0,0,0,0,0,0,0,0\r
858 .long 0,0,0,0,0,0,0,0\r
859 .long 0,0,0,0,0,0,0,0\r
860 .long 0,0,0,0,0,0,0,0\r
861 .long 0,0,0,0,0,0,0,0\r
862 .long 0,0,0,0,0,0,0,0\r
863 .long 0,0,0,0,0,0,0,0\r
864 .long 0,0,0,0,0,0,0,0\r
865 .long 0,0,0,0,0,0,0,0\r
866 .long 0,0,0,0,0,0,0,0\r
867 .long 0,0,0,0,0,0,0,0\r
868 .long 0,0,0,0,0,0,0,0\r
869 .long 0,0,0,0,0,0,0,0\r
870 .long 0,0,0,0,0,0,0,0\r
871 .long 0,0,0,0,0,0,0,0\r
872 .long 0,0,0,0,0,0,0,0\r
873 .long 0,0,0,0,0,0,0,0\r
874 .long 0,0,0,0,0,0,0,0\r
875 .long 0,0,0,0,0,0,0,0\r
876 .long 0,0,0,0,0,0,0,0\r
877 .long 0,0,0,0,0,0,0,0\r
878 .long 0,0,0,0,0,0,0,0\r
879\r
880 .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
881 .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
882\r
883 .org 0x0fe0\r
884MyStack: \r
885 # below is the pieces of the IVT that is used to redirect INT 68h - 6fh\r
886 # back to INT 08h - 0fh when in real mode... It is 'org'ed to a\r
887 # known low address (20f00) so it can be set up by PlMapIrqToVect in\r
888 # 8259.c\r
889\r
890 int $8\r
891 iret\r
892\r
893 int $9\r
894 iret\r
895\r
896 int $10\r
897 iret\r
898\r
899 int $11\r
900 iret\r
901\r
902 int $12\r
903 iret\r
904\r
905 int $13\r
906 iret\r
907\r
908 int $14\r
909 iret\r
910\r
911 int $15\r
912 iret\r
913\r
914\r
915 .org 0x0ffe\r
916BlockSignature: \r
917 .word 0xaa55\r
918\r
919\r