+++ /dev/null
-;------------------------------------------------------------------------------\r
-;*\r
-;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
-;* This program and the accompanying materials \r
-;* are licensed and made available under the terms and conditions of the BSD License \r
-;* which accompanies this distribution. The full text of the license may be found at \r
-;* http://opensource.org/licenses/bsd-license.php \r
-;* \r
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-;* \r
-;* start16.asm\r
-;* \r
-;* Abstract:\r
-;*\r
-;------------------------------------------------------------------------------\r
-\r
- .model small\r
- .stack\r
- .486p\r
- .code\r
-\r
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h\r
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5\r
-BLOCK_SIZE EQU 0200h\r
-BLOCK_MASK EQU 01ffh\r
-BLOCK_SHIFT EQU 9\r
-\r
- org 0h\r
-Ia32Jump:\r
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes\r
- nop\r
-\r
-OemId db "INTEL " ; OemId - 8 bytes\r
-\r
-SectorSize dw 0 ; Sector Size - 16 bits\r
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits\r
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits\r
-NoFats db 0 ; Number of FATs - 8 bits\r
-RootEntries dw 0 ; Root Entries - 16 bits\r
-Sectors dw 0 ; Number of Sectors - 16 bits\r
-Media db 0 ; Media - 8 bits - ignored\r
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits\r
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored\r
-Heads dw 0 ; Heads - 16 bits - ignored\r
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored\r
-LargeSectors dd 0 ; Large Sectors - 32 bits \r
-PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored\r
-CurrentHead db 0 ; Current Head - 8 bits\r
-Signature db 0 ; Signature - 8 bits - ignored\r
-VolId db " " ; Volume Serial Number- 4 bytes\r
-FatLabel db " " ; Label - 11 bytes\r
-SystemId db "FAT16 " ; SystemId - 8 bytes\r
-\r
-BootSectorEntryPoint:\r
- ASSUME ds:@code\r
- ASSUME ss:@code\r
- ; ds = 1000, es = 2000 + x (size of first cluster >> 4)\r
- ; cx = Start Cluster of EfiLdr\r
- ; dx = Start Cluster of Efivar.bin\r
-\r
-; Re use the BPB data stored in Boot Sector\r
- mov bp,07c00h\r
-\r
- push cx\r
-; Read Efivar.bin\r
-; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already\r
- mov ax,01900h\r
- mov es,ax\r
- test dx,dx\r
- jnz CheckVarStoreSize\r
-\r
- mov al,1\r
-NoVarStore:\r
- push es\r
-; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl\r
- mov byte ptr es:[4],al\r
- jmp SaveVolumeId\r
-\r
-CheckVarStoreSize:\r
- mov di,dx\r
- cmp dword ptr ds:[di+2], 04000h\r
- mov al,2\r
- jne NoVarStore\r
-\r
-LoadVarStore:\r
- mov al,0\r
- mov byte ptr es:[4],al\r
- mov cx,word ptr[di]\r
-; ES:DI = 1500:0\r
- xor di,di\r
- push es\r
- mov ax,01500h\r
- mov es,ax\r
- call ReadFile\r
-SaveVolumeId:\r
- pop es\r
- mov ax,word ptr [bp+VolId]\r
- mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId\r
- mov ax,word ptr [bp+VolId+2]\r
- mov word ptr es:[2],ax\r
-\r
-; Read Efildr\r
- pop cx\r
-; cx = Start Cluster of Efildr -> BS.com has filled already\r
-; ES:DI = 2000:0, first cluster will be read again\r
- xor di,di ; di = 0\r
- mov ax,02000h\r
- mov es,ax\r
- call ReadFile\r
- mov ax,cs\r
- mov word ptr cs:[JumpSegment],ax\r
-\r
-JumpFarInstruction:\r
- db 0eah\r
-JumpOffset:\r
- dw 0200h\r
-JumpSegment:\r
- dw 2000h\r
-\r
-\r
-\r
-; ****************************************************************************\r
-; ReadFile\r
-;\r
-; Arguments:\r
-; CX = Start Cluster of File\r
-; ES:DI = Buffer to store file content read from disk\r
-;\r
-; Return:\r
-; (ES << 4 + DI) = end of file content Buffer\r
-;\r
-; ****************************************************************************\r
-ReadFile:\r
-; si = NumberOfClusters\r
-; cx = ClusterNumber\r
-; dx = CachedFatSectorNumber\r
-; ds:0000 = CacheFatSectorBuffer\r
-; es:di = Buffer to load file\r
-; bx = NextClusterNumber\r
- pusha\r
- mov si,1 ; NumberOfClusters = 1\r
- push cx ; Push Start Cluster onto stack\r
- mov dx,0fffh ; CachedFatSectorNumber = 0xfff\r
-FatChainLoop:\r
- mov ax,cx ; ax = ClusterNumber \r
- and ax,0fff8h ; ax = ax & 0xfff8\r
- cmp ax,0fff8h ; See if this is the last cluster\r
- je FoundLastCluster ; Jump if last cluster found\r
- mov ax,cx ; ax = ClusterNumber\r
- shl ax,1 ; FatOffset = ClusterNumber * 2\r
- push si ; Save si\r
- mov si,ax ; si = FatOffset\r
- shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT\r
- add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)\r
- and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK\r
- cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber\r
- je SkipFatRead\r
- mov bx,2 \r
- push es\r
- push ds\r
- pop es\r
- call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI\r
- pop es\r
- mov dx,ax ; CachedFatSectorNumber = FatSectorNumber\r
-SkipFatRead:\r
- mov bx,word ptr [si] ; bx = NextClusterNumber\r
- mov ax,cx ; ax = ClusterNumber\r
- pop si ; Restore si\r
- dec bx ; bx = NextClusterNumber - 1\r
- cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber\r
- jne ReadClusters\r
- inc bx ; bx = NextClusterNumber\r
- inc si ; NumberOfClusters++\r
- mov cx,bx ; ClusterNumber = NextClusterNumber\r
- jmp FatChainLoop\r
-ReadClusters:\r
- inc bx\r
- pop ax ; ax = StartCluster\r
- push bx ; StartCluster = NextClusterNumber\r
- mov cx,bx ; ClusterNumber = NextClusterNumber\r
- sub ax,2 ; ax = StartCluster - 2\r
- xor bh,bh \r
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster\r
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster\r
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster\r
- push ax ; save start sector\r
- mov ax,si ; ax = NumberOfClusters\r
- mul bx ; ax = NumberOfClusters * SectorsPerCluster\r
- mov bx,ax ; bx = Number of Sectors\r
- pop ax ; ax = Start Sector\r
- call ReadBlocks\r
- mov si,1 ; NumberOfClusters = 1\r
- jmp FatChainLoop\r
-FoundLastCluster:\r
- pop cx\r
- popa\r
- ret\r
-\r
-\r
-; ****************************************************************************\r
-; ReadBlocks - Reads a set of blocks from a block device\r
-;\r
-; AX = Start LBA\r
-; BX = Number of Blocks to Read\r
-; ES:DI = Buffer to store sectors read from disk\r
-; ****************************************************************************\r
-\r
-; cx = Blocks\r
-; bx = NumberOfBlocks\r
-; si = StartLBA\r
-\r
-ReadBlocks:\r
- pusha\r
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA\r
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA\r
- mov esi,eax ; esi = Start LBA\r
- mov cx,bx ; cx = Number of blocks to read\r
-ReadCylinderLoop:\r
- mov bp,07bfch ; bp = 0x7bfc\r
- mov eax,esi ; eax = Start LBA\r
- xor edx,edx ; edx = 0\r
- movzx ebx,word ptr [bp] ; bx = MaxSector\r
- div ebx ; ax = StartLBA / MaxSector\r
- inc dx ; dx = (StartLBA % MaxSector) + 1\r
-\r
- mov bx,word ptr [bp] ; bx = MaxSector\r
- sub bx,dx ; bx = MaxSector - Sector\r
- inc bx ; bx = MaxSector - Sector + 1\r
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)\r
- jg LimitTransfer\r
- mov bx,cx ; bx = Blocks\r
-LimitTransfer:\r
- push ax ; save ax\r
- mov ax,es ; ax = es\r
- shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system\r
- and ax,07fh ; ax = Number of blocks into current seg\r
- add ax,bx ; ax = End Block number of transfer\r
- cmp ax,080h ; See if it crosses a 64K boundry\r
- jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry\r
- sub ax,080h ; ax = Number of blocks past 64K boundry\r
- sub bx,ax ; Decrease transfer size by block overage\r
-NotCrossing64KBoundry:\r
- pop ax ; restore ax\r
-\r
- push cx\r
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector\r
- xor dx,dx ; dx = 0\r
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder \r
- ; dx = ax % (MaxHead + 1) = Head\r
-\r
- push bx ; Save number of blocks to transfer\r
- mov dh,dl ; dh = Head\r
- mov bp,07c00h ; bp = 0x7c00\r
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number\r
- mov ch,al ; ch = Cylinder\r
- mov al,bl ; al = Blocks\r
- mov ah,2 ; ah = Function 2\r
- mov bx,di ; es:bx = Buffer address\r
- int 013h\r
- jc DiskError\r
- pop bx\r
- pop cx\r
- movzx ebx,bx\r
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks\r
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks\r
- mov ax,es\r
- shl bx,(BLOCK_SHIFT-4)\r
- add ax,bx\r
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE\r
- cmp cx,0\r
- jne ReadCylinderLoop\r
- popa\r
- ret\r
-\r
-DiskError:\r
- push cs\r
- pop ds\r
- lea si, [ErrorString]\r
- mov cx, 7\r
- jmp PrintStringAndHalt\r
-\r
-PrintStringAndHalt:\r
- mov ax,0b800h\r
- mov es,ax\r
- mov di,160\r
- rep movsw\r
-Halt:\r
- jmp Halt\r
-\r
-ErrorString:\r
- db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch\r
-\r
- org 01fah\r
-LBAOffsetForBootSector:\r
- dd 0h\r
-\r
- org 01feh\r
- dw 0aa55h\r
-\r
-;******************************************************************************\r
-;******************************************************************************\r
-;******************************************************************************\r
-\r
-DELAY_PORT equ 0edh ; Port to use for 1uS delay\r
-KBD_CONTROL_PORT equ 060h ; 8042 control port \r
-KBD_STATUS_PORT equ 064h ; 8042 status port \r
-WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port\r
-ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20\r
-\r
- org 200h\r
- jmp start\r
-Em64String:\r
- db 'E', 0ch, 'm', 0ch, '6', 0ch, '4', 0ch, 'T', 0ch, ' ', 0ch, 'U', 0ch, 'n', 0ch, 's', 0ch, 'u', 0ch, 'p', 0ch, 'p', 0ch, 'o', 0ch, 'r', 0ch, 't', 0ch, 'e', 0ch, 'd', 0ch, '!', 0ch\r
-\r
-start: \r
- mov ax,cs\r
- mov ds,ax\r
- mov es,ax\r
- mov ss,ax\r
- mov sp,MyStack\r
-\r
-; mov ax,0b800h\r
-; mov es,ax\r
-; mov byte ptr es:[160],'a'\r
-; mov ax,cs\r
-; mov es,ax\r
-\r
- mov ebx,0\r
- lea edi,MemoryMap\r
-MemMapLoop:\r
- mov eax,0e820h\r
- mov ecx,20\r
- mov edx,'SMAP'\r
- int 15h\r
- jc MemMapDone\r
- add edi,20\r
- cmp ebx,0\r
- je MemMapDone\r
- jmp MemMapLoop\r
-MemMapDone:\r
- lea eax,MemoryMap\r
- sub edi,eax ; Get the address of the memory map\r
- mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map\r
-\r
- xor ebx,ebx\r
- mov bx,cs ; BX=segment\r
- shl ebx,4 ; BX="linear" address of segment base\r
- lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt\r
- mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr\r
- lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt\r
- mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr\r
- lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map\r
-\r
- add ebx,01000h ; Source of EFI32\r
- mov dword ptr [JUMP+2],ebx\r
- add ebx,01000h\r
- mov esi,ebx ; Source of EFILDR32\r
-\r
-; mov ax,0b800h\r
-; mov es,ax\r
-; mov byte ptr es:[162],'b'\r
-; mov ax,cs\r
-; mov es,ax\r
-\r
-;\r
-; Enable A20 Gate \r
-;\r
-\r
- mov ax,2401h ; Enable A20 Gate\r
- int 15h\r
- jnc A20GateEnabled ; Jump if it suceeded\r
-\r
-;\r
-; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.\r
-;\r
-\r
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller\r
- jnz Timeout8042 ; Jump if the 8042 timed out\r
- out DELAY_PORT,ax ; Delay 1 uS\r
- mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port\r
- out KBD_STATUS_PORT,al ; Send command to the 8042\r
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller\r
- jnz Timeout8042 ; Jump if the 8042 timed out\r
- mov al,ENABLE_A20_CMD ; gate address bit 20 on\r
- out KBD_CONTROL_PORT,al ; Send command to thre 8042\r
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller\r
- mov cx,25 ; Delay 25 uS for the command to complete on the 8042\r
-Delay25uS:\r
- out DELAY_PORT,ax ; Delay 1 uS\r
- loop Delay25uS \r
-Timeout8042:\r
-\r
-\r
-A20GateEnabled:\r
- mov bx,0008h ; Flat data descriptor\r
-;\r
-; DISABLE INTERRUPTS - Entering Protected Mode\r
-;\r
-\r
- cli \r
-\r
-; mov ax,0b800h\r
-; mov es,ax\r
-; mov byte ptr es:[164],'c'\r
-; mov ax,cs\r
-; mov es,ax\r
-\r
- db 66h \r
- lgdt fword ptr [gdtr]\r
- db 66h \r
- lidt fword ptr [idtr]\r
-\r
- mov eax,cr0\r
- or al,1\r
- mov cr0,eax\r
-JUMP:\r
-; jmp far 0010:00020000\r
- db 066h\r
- db 0eah\r
- dd 000020000h\r
- dw 00010h\r
-\r
-Empty8042InputBuffer:\r
- mov cx,0\r
-Empty8042Loop:\r
- out DELAY_PORT,ax ; Delay 1us\r
- in al,KBD_STATUS_PORT ; Read the 8042 Status Port\r
- and al,02h ; Check the Input Buffer Full Flag\r
- loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS\r
- ret\r
-\r
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
-; data\r
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
-\r
- align 02h\r
-\r
-gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit\r
- dd 0 ; (GDT base gets set above)\r
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
-; global descriptor table (GDT)\r
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
-\r
- align 02h\r
-\r
-public GDT_BASE\r
-GDT_BASE:\r
-; null descriptor\r
-NULL_SEL equ $-GDT_BASE\r
- dw 0 ; limit 15:0\r
- dw 0 ; base 15:0\r
- db 0 ; base 23:16\r
- db 0 ; type\r
- db 0 ; limit 19:16, flags\r
- db 0 ; base 31:24\r
-\r
-; linear data segment descriptor\r
-LINEAR_SEL equ $-GDT_BASE\r
- dw 0FFFFh ; limit 0xFFFFF\r
- dw 0 ; base 0\r
- db 0\r
- db 092h ; present, ring 0, data, expand-up, writable\r
- db 0CFh ; page-granular, 32-bit\r
- db 0\r
-\r
-; linear code segment descriptor\r
-LINEAR_CODE_SEL equ $-GDT_BASE\r
- dw 0FFFFh ; limit 0xFFFFF\r
- dw 0 ; base 0\r
- db 0\r
- db 09Ah ; present, ring 0, data, expand-up, writable\r
- db 0CFh ; page-granular, 32-bit\r
- db 0\r
-\r
-; system data segment descriptor\r
-SYS_DATA_SEL equ $-GDT_BASE\r
- dw 0FFFFh ; limit 0xFFFFF\r
- dw 0 ; base 0\r
- db 0\r
- db 092h ; present, ring 0, data, expand-up, writable\r
- db 0CFh ; page-granular, 32-bit\r
- db 0\r
-\r
-; system code segment descriptor\r
-SYS_CODE_SEL equ $-GDT_BASE\r
- dw 0FFFFh ; limit 0xFFFFF\r
- dw 0 ; base 0\r
- db 0\r
- db 09Ah ; present, ring 0, data, expand-up, writable\r
- db 0CFh ; page-granular, 32-bit\r
- db 0\r
-\r
-; spare segment descriptor\r
-SPARE3_SEL equ $-GDT_BASE\r
- dw 0 ; limit 0xFFFFF\r
- dw 0 ; base 0\r
- db 0\r
- db 0 ; present, ring 0, data, expand-up, writable\r
- db 0 ; page-granular, 32-bit\r
- db 0\r
-\r
-; spare segment descriptor\r
-SPARE4_SEL equ $-GDT_BASE\r
- dw 0 ; limit 0xFFFFF\r
- dw 0 ; base 0\r
- db 0\r
- db 0 ; present, ring 0, data, expand-up, writable\r
- db 0 ; page-granular, 32-bit\r
- db 0\r
-\r
-; spare segment descriptor\r
-SPARE5_SEL equ $-GDT_BASE\r
- dw 0 ; limit 0xFFFFF\r
- dw 0 ; base 0\r
- db 0\r
- db 0 ; present, ring 0, data, expand-up, writable\r
- db 0 ; page-granular, 32-bit\r
- db 0\r
-\r
-GDT_END:\r
-\r
- align 02h\r
-\r
-\r
-\r
-idtr dw IDT_END - IDT_BASE - 1 ; IDT limit\r
- dd 0 ; (IDT base gets set above)\r
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
-; interrupt descriptor table (IDT)\r
-;\r
-; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ\r
-; mappings. This implementation only uses the system timer and all other\r
-; IRQs will remain masked. The descriptors for vectors 33+ are provided\r
-; for convenience.\r
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
-\r
-;idt_tag db "IDT",0 \r
- align 02h\r
-\r
-public IDT_BASE\r
-IDT_BASE:\r
-; divide by zero (INT 0)\r
-DIV_ZERO_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; debug exception (INT 1)\r
-DEBUG_EXCEPT_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; NMI (INT 2)\r
-NMI_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; soft breakpoint (INT 3)\r
-BREAKPOINT_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; overflow (INT 4)\r
-OVERFLOW_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; bounds check (INT 5)\r
-BOUNDS_CHECK_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; invalid opcode (INT 6)\r
-INVALID_OPCODE_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; device not available (INT 7)\r
-DEV_NOT_AVAIL_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; double fault (INT 8)\r
-DOUBLE_FAULT_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; Coprocessor segment overrun - reserved (INT 9)\r
-RSVD_INTR_SEL1 equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; invalid TSS (INT 0ah)\r
-INVALID_TSS_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; segment not present (INT 0bh)\r
-SEG_NOT_PRESENT_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; stack fault (INT 0ch)\r
-STACK_FAULT_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; general protection (INT 0dh)\r
-GP_FAULT_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; page fault (INT 0eh)\r
-PAGE_FAULT_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; Intel reserved - do not use (INT 0fh)\r
-RSVD_INTR_SEL2 equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; floating point error (INT 10h)\r
-FLT_POINT_ERR_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; alignment check (INT 11h)\r
-ALIGNMENT_CHECK_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; machine check (INT 12h)\r
-MACHINE_CHECK_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; SIMD floating-point exception (INT 13h)\r
-SIMD_EXCEPTION_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail\r
- db (85 * 8) dup(0)\r
- \r
-; IRQ 0 (System timer) - (INT 68h)\r
-IRQ0_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 1 (8042 Keyboard controller) - (INT 69h)\r
-IRQ1_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)\r
-IRQ2_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 3 (COM 2) - (INT 6bh)\r
-IRQ3_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 4 (COM 1) - (INT 6ch)\r
-IRQ4_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 5 (LPT 2) - (INT 6dh)\r
-IRQ5_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 6 (Floppy controller) - (INT 6eh)\r
-IRQ6_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 7 (LPT 1) - (INT 6fh)\r
-IRQ7_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 8 (RTC Alarm) - (INT 70h)\r
-IRQ8_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 9 - (INT 71h)\r
-IRQ9_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 10 - (INT 72h)\r
-IRQ10_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 11 - (INT 73h)\r
-IRQ11_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 12 (PS/2 mouse) - (INT 74h)\r
-IRQ12_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 13 (Floating point error) - (INT 75h)\r
-IRQ13_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 14 (Secondary IDE) - (INT 76h)\r
-IRQ14_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-; IRQ 15 (Primary IDE) - (INT 77h)\r
-IRQ15_SEL equ $-IDT_BASE\r
- dw 0 ; offset 15:0\r
- dw SYS_CODE_SEL ; selector 15:0\r
- db 0 ; 0 for interrupt gate\r
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present\r
- dw 0 ; offset 31:16\r
-\r
-IDT_END:\r
-\r
- align 02h\r
-\r
-MemoryMapSize dd 0\r
-MemoryMap dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
- dd 0,0,0,0,0,0,0,0\r
-\r
- dd 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
- dd 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
-\r
- org 0fe0h\r
-MyStack: \r
- ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh\r
- ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a\r
- ; known low address (20f00) so it can be set up by PlMapIrqToVect in\r
- ; 8259.c\r
- \r
- int 8\r
- iret\r
- \r
- int 9\r
- iret\r
- \r
- int 10\r
- iret\r
- \r
- int 11\r
- iret\r
- \r
- int 12\r
- iret\r
- \r
- int 13\r
- iret\r
- \r
- int 14\r
- iret\r
- \r
- int 15\r
- iret\r
- \r
- \r
- org 0ffeh\r
-BlockSignature:\r
- dw 0aa55h\r
-\r
- end \r