diff options
author | Guo Mang <mang.guo@intel.com> | 2017-04-27 11:29:39 +0800 |
---|---|---|
committer | Guo Mang <mang.guo@intel.com> | 2017-04-27 13:02:41 +0800 |
commit | 7283449b45d2842b9123ada5129cb073e40b940a (patch) | |
tree | 0978b182ec01469ac7257aa79e9d931cd866872e /DuetPkg/BootSector | |
parent | 09091ace1c1c500db998cff6cd068e78b2c1b2af (diff) | |
download | edk2-platforms-7283449b45d2842b9123ada5129cb073e40b940a.tar.xz |
DuetPkg: Remove unused Package
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Mang <mang.guo@intel.com>
Diffstat (limited to 'DuetPkg/BootSector')
46 files changed, 0 insertions, 19684 deletions
diff --git a/DuetPkg/BootSector/BootSector.inf b/DuetPkg/BootSector/BootSector.inf deleted file mode 100644 index 49f69eb66e..0000000000 --- a/DuetPkg/BootSector/BootSector.inf +++ /dev/null @@ -1,79 +0,0 @@ -## @file
-#
-# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-##
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = BootSector
- FILE_GUID = C89D72CE-E21A-4c71-BA79-770EF373D6DA
- MODULE_TYPE = USER_DEFINED
- VERSION_STRING = 1.0
- CUSTOM_MAKEFILE = MSFT|Makefile
- CUSTOM_MAKEFILE = GCC|GNUmakefile
-
-[Packages]
- MdePkg/MdePkg.dec
- DuetPkg/DuetPkg.dec
-
-[Sources]
- bootsect.asm | INTEL
- bootsect.asm | MSFT
- bootsect.S | GCC
-
- bs16.asm | INTEL
- bs16.asm | MSFT
- bs16.S | GCC
-
- bs32.asm | INTEL
- bs32.asm | MSFT
- bs32.S | GCC
-
- Gpt.asm | INTEL
- Gpt.asm | MSFT
- Gpt.S | GCC
-
- Mbr.asm | INTEL
- Mbr.asm | MSFT
- Mbr.S | GCC
-
- start.asm | INTEL
- start.asm | MSFT
- start.S | GCC
-
- start16.asm | INTEL
- start16.asm | MSFT
- start16.S | GCC
-
- start32.asm | INTEL
- start32.asm | MSFT
- start32.S | GCC
-
- efi32.asm | INTEL
- efi32.asm | MSFT
- efi32.S | GCC
-
- start64.asm | INTEL
- start64.asm | MSFT
- start64.S | GCC
-
- st16_64.asm | INTEL
- st16_64.asm | MSFT
- st16_64.S | GCC
-
- st32_64.asm | INTEL
- st32_64.asm | MSFT
- st32_64.S | GCC
-
- efi64.asm | INTEL
- efi64.asm | MSFT
- efi64.S | GCC
-
diff --git a/DuetPkg/BootSector/FILE.LST b/DuetPkg/BootSector/FILE.LST deleted file mode 100644 index abbe1da17f..0000000000 --- a/DuetPkg/BootSector/FILE.LST +++ /dev/null @@ -1,39 +0,0 @@ -## @file
-#
-# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-#
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-##
-
-IA32
-====
-FAT12 FAT16 FAT32
-bootsect.asm bs16.asm bs32.asm
-start.asm start16.asm start32.asm
- \ | /
- \ | /
- efi32.asm
-
-X64
-===
-FAT12 FAT16 FAT32
-bootsect.asm bs16.asm bs32.asm
-start64.asm st16_64.asm st32_64.asm
- \ | /
- \ | /
- efi64.asm
-
-MBR
-===
-Mbr.asm
-
-
-GPT
-===
-Gpt.asm
\ No newline at end of file diff --git a/DuetPkg/BootSector/GNUmakefile b/DuetPkg/BootSector/GNUmakefile deleted file mode 100644 index da38876a50..0000000000 --- a/DuetPkg/BootSector/GNUmakefile +++ /dev/null @@ -1,140 +0,0 @@ -## @file
-# Just use host GCC to compile boot sector image.
-#
-# Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
-#
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-##
-
-ASM=gcc
-DLINK=ld
-
-ASSEMBLY_CODE_FILE_LIST = $(MODULE_DIR)/bootsect.S \
- $(MODULE_DIR)/bs16.S \
- $(MODULE_DIR)/bs32.S \
- $(MODULE_DIR)/efi32.S \
- $(MODULE_DIR)/efi64.S \
- $(MODULE_DIR)/Gpt.S \
- $(MODULE_DIR)/Mbr.S \
- $(MODULE_DIR)/start.S \
- $(MODULE_DIR)/start16.S \
- $(MODULE_DIR)/start32.S \
- $(MODULE_DIR)/start64.S \
- $(MODULE_DIR)/st16_64.S \
- $(MODULE_DIR)/st32_64.S
-
-TARGET_FILES = $(OUTPUT_DIR)/bootsect.com \
- $(OUTPUT_DIR)/bs16.com \
- $(OUTPUT_DIR)/bs32.com \
- $(OUTPUT_DIR)/Gpt.com \
- $(OUTPUT_DIR)/Mbr.com \
- $(OUTPUT_DIR)/start.com \
- $(OUTPUT_DIR)/start16.com \
- $(OUTPUT_DIR)/start32.com \
- $(OUTPUT_DIR)/efi32.com2 \
- $(OUTPUT_DIR)/start64.com \
- $(OUTPUT_DIR)/st16_64.com \
- $(OUTPUT_DIR)/st32_64.com \
- $(OUTPUT_DIR)/efi64.com2
-
-.PHONY : all
-all: $(TARGET_FILES)
-
-# bootsect.S
-$(OUTPUT_DIR)/bootsect.o: $(MODULE_DIR)/bootsect.S
- $(ASM) -c -o $(OUTPUT_DIR)/bootsect.o $(MODULE_DIR)/bootsect.S
-$(OUTPUT_DIR)/bootsect.com: $(OUTPUT_DIR)/bootsect.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/bootsect.com $(OUTPUT_DIR)/bootsect.o -Ttext 0 -Map $(OUTPUT_DIR)/bootsect.map
-
-# bs16.S
-$(OUTPUT_DIR)/bs16.o: $(MODULE_DIR)/bs16.S
- $(ASM) -c -o $(OUTPUT_DIR)/bs16.o $(MODULE_DIR)/bs16.S
-$(OUTPUT_DIR)/bs16.com: $(OUTPUT_DIR)/bs16.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/bs16.com $(OUTPUT_DIR)/bs16.o -Ttext 0 -Map $(OUTPUT_DIR)/bs16.map
-
-# bs32.S
-$(OUTPUT_DIR)/bs32.o: $(MODULE_DIR)/bs32.S
- $(ASM) -c -o $(OUTPUT_DIR)/bs32.o $(MODULE_DIR)/bs32.S
-$(OUTPUT_DIR)/bs32.com: $(OUTPUT_DIR)/bs32.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/bs32.com $(OUTPUT_DIR)/bs32.o -Ttext 0 -Map $(OUTPUT_DIR)/bs32.map
-
-# Gpt.S
-$(OUTPUT_DIR)/Gpt.o: $(MODULE_DIR)/Gpt.S
- $(ASM) -c -o $(OUTPUT_DIR)/Gpt.o $(MODULE_DIR)/Gpt.S
-$(OUTPUT_DIR)/Gpt.com: $(OUTPUT_DIR)/Gpt.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/Gpt.com $(OUTPUT_DIR)/Gpt.o -Ttext 0 -Map $(OUTPUT_DIR)/Gpt.map
-
-# Mbr.S
-$(OUTPUT_DIR)/Mbr.o: $(MODULE_DIR)/Mbr.S
- $(ASM) -c -o $(OUTPUT_DIR)/Mbr.o $(MODULE_DIR)/Mbr.S
-$(OUTPUT_DIR)/Mbr.com: $(OUTPUT_DIR)/Mbr.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/Mbr.com $(OUTPUT_DIR)/Mbr.o -Ttext 0 -Map $(OUTPUT_DIR)/Mbr.map
-
-# start.S
-$(OUTPUT_DIR)/start.o: $(MODULE_DIR)/start.S
- $(ASM) -c -o $(OUTPUT_DIR)/start.o $(MODULE_DIR)/start.S
-$(OUTPUT_DIR)/start.com: $(OUTPUT_DIR)/start.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/start.com $(OUTPUT_DIR)/start.o -Ttext 0 -Map $(OUTPUT_DIR)/start.map
-
-# start16.S
-$(OUTPUT_DIR)/start16.o: $(MODULE_DIR)/start16.S
- $(ASM) -c -o $(OUTPUT_DIR)/start16.o $(MODULE_DIR)/start16.S
-$(OUTPUT_DIR)/start16.com: $(OUTPUT_DIR)/start16.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/start16.com $(OUTPUT_DIR)/start16.o -Ttext 0 -Map $(OUTPUT_DIR)/start16.map
-
-# start32.S
-$(OUTPUT_DIR)/start32.o: $(MODULE_DIR)/start32.S
- $(ASM) -c -o $(OUTPUT_DIR)/start32.o $(MODULE_DIR)/start32.S
-$(OUTPUT_DIR)/start32.com: $(OUTPUT_DIR)/start32.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/start32.com $(OUTPUT_DIR)/start32.o -Ttext 0 -Map $(OUTPUT_DIR)/start32.map
-
-# start64.S
-$(OUTPUT_DIR)/start64.o: $(MODULE_DIR)/start64.S
- $(ASM) -c -o $(OUTPUT_DIR)/start64.o $(MODULE_DIR)/start64.S
-$(OUTPUT_DIR)/start64.com: $(OUTPUT_DIR)/start64.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/start64.com $(OUTPUT_DIR)/start64.o -Ttext 0 -Map $(OUTPUT_DIR)/start64.map
-
-# start16_64.S
-$(OUTPUT_DIR)/st16_64.o: $(MODULE_DIR)/st16_64.S
- $(ASM) -c -o $(OUTPUT_DIR)/st16_64.o $(MODULE_DIR)/st16_64.S
-$(OUTPUT_DIR)/st16_64.com: $(OUTPUT_DIR)/st16_64.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/st16_64.com $(OUTPUT_DIR)/st16_64.o -Ttext 0 -Map $(OUTPUT_DIR)/st16_64.map
-
-# start32_64.S
-$(OUTPUT_DIR)/st32_64.o: $(MODULE_DIR)/st32_64.S
- $(ASM) -c -o $(OUTPUT_DIR)/st32_64.o $(MODULE_DIR)/st32_64.S
-$(OUTPUT_DIR)/st32_64.com: $(OUTPUT_DIR)/st32_64.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/st32_64.com $(OUTPUT_DIR)/st32_64.o -Ttext 0 -Map $(OUTPUT_DIR)/st32_64.map
-
-# efi32.S
-$(OUTPUT_DIR)/efi32.o: $(MODULE_DIR)/efi32.S
- $(ASM) -c -o $(OUTPUT_DIR)/efi32.o $(MODULE_DIR)/efi32.S
-$(OUTPUT_DIR)/efi32.com: $(OUTPUT_DIR)/efi32.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/efi32.com $(OUTPUT_DIR)/efi32.o -Ttext 0 -Map $(OUTPUT_DIR)/efi32.map
-$(OUTPUT_DIR)/efi32.com2: $(OUTPUT_DIR)/efi32.com
- Split -f $(OUTPUT_DIR)/efi32.com -p $(OUTPUT_DIR) -o efi32.com1 -p $(OUTPUT_DIR) -t efi32.com2 -s 135168
-
-# efi64.S
-$(OUTPUT_DIR)/efi64.o: $(MODULE_DIR)/efi64.S
- $(ASM) -c -o $(OUTPUT_DIR)/efi64.o $(MODULE_DIR)/efi64.S
-$(OUTPUT_DIR)/efi64.com: $(OUTPUT_DIR)/efi64.o
- $(DLINK) --oformat binary -o $(OUTPUT_DIR)/efi64.com $(OUTPUT_DIR)/efi64.o -Ttext 0 -Map $(OUTPUT_DIR)/efi64.map
-$(OUTPUT_DIR)/efi64.com2: $(OUTPUT_DIR)/efi64.com
- Split -f $(OUTPUT_DIR)/efi64.com -p $(OUTPUT_DIR) -o efi64.com1 -p $(OUTPUT_DIR) -t efi64.com2 -s 135168
-
-clean:
-ifneq ($(OUTPUT_DIR), )
- rm -r $(OUTPUT_DIR)
-endif
-ifneq ($(DEBUG_DIR), )
- rm -r $(DEBUG_DIR)
-endif
-
-
diff --git a/DuetPkg/BootSector/Gpt.S b/DuetPkg/BootSector/Gpt.S deleted file mode 100644 index 821ca846f0..0000000000 --- a/DuetPkg/BootSector/Gpt.S +++ /dev/null @@ -1,297 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* gpt.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
- #.MODEL small
-# .dosseg
- .stack:
- .486p:
- .code16
-
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
-# ****************************************************************************
-# Code loaded by BIOS at 0x0000:0x7C00
-# ****************************************************************************
-
- .org 0x00
-Start:
-
-# ****************************************************************************
-# Start Print
-# ****************************************************************************
-
- movw $0xb800, %ax
- movw %ax, %es
- movw $0x7c0, %ax
- movw %ax, %ds
- leaw %cs:StartString, %si
- movw $10, %cx
- movw $160, %di
- rep
- movsw
-
-# ****************************************************************************
-# Print over
-# ****************************************************************************
-
-# ****************************************************************************
-# Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
-# ****************************************************************************
- xorw %ax, %ax # AX = 0x0000
- movw $0x7c00, %bx # BX = 0x7C00
- movw $0x600, %bp # BP = 0x0600
- movw RelocatedStart, %si # SI = Offset(RelocatedStart)
- movw $0x200, %cx # CX = 0x0200
- subw %si, %cx # CS = 0x0200 - Offset(RelocatedStart)
- leaw (%bp,%si,), %di # DI = 0x0600 + Offset(RelocatedStart)
- leaw (%bx,%si,), %si # BX = 0x7C00 + Offset(RelocatedStart)
- movw %ax, %ss # SS = 0x0000
- movw %bx, %sp # SP = 0x7C00
- movw %ax, %es # ES = 0x0000
- movw %ax, %ds # DS = 0x0000
- pushw %ax # PUSH 0x0000
- pushw %di # PUSH 0x0600 + Offset(RelocatedStart)
- cld # Clear the direction flag
- rep
- movsb # Copy 0x0200 bytes from 0x7C00 to 0x0600
- retl # JMP 0x0000:0x0600 + Offset(RelocatedStart)
-
-# ****************************************************************************
-# Code relocated to 0x0000:0x0600
-# ****************************************************************************
-
-RelocatedStart:
-# ****************************************************************************
-# Get Driver Parameters to 0x0000:0x7BFC
-# ****************************************************************************
- xorw %ax, %ax # ax = 0
- movw %ax, %ss # ss = 0
- addw $0x1000, %ax
- movw %ax, %ds
-
- movw $0x7c00, %sp # sp = 0x7c00
- movw %sp, %bp # bp = 0x7c00
-
- movb $8, %ah # ah = 8 - Get Drive Parameters Function
- movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
- int $0x13 # Get Drive Parameters
- xorw %ax, %ax # ax = 0
- movb %dh, %al # al = dh
- incb %al # MaxHead = al + 1
- pushw %ax # 0000:7bfe = MaxHead
- movb %cl, %al # al = cl
- andb $0x3f, %al # MaxSector = al & 0x3f
- pushw %ax # 0000:7bfc = MaxSector
-
-# ****************************************************************************
-# Read GPT Header from hard disk to 0x0000:0x0800
-# ****************************************************************************
- xorw %ax, %ax
- movw %ax, %es # Read to 0x0000:0x0800
- movw $0x800, %di # Read to 0x0000:0x0800
- movl $1, %eax # Read LBA #1
- movl $0, %edx # Read LBA #1
- movw $1, %bx # Read 1 Block
- pushw %es
- call ReadBlocks
- popw %es
-
-# ****************************************************************************
-# Read Target GPT Entry from hard disk to 0x0000:0x0A00
-# ****************************************************************************
- cmpl $0x20494645, %es:(%di) # Check for "EFI "
- jne BadGpt
- cmpl $0x54524150, %es:4(%di) # Check for "PART"
- jne BadGpt
- cmpl $0x00010000, %es:8(%di) # Check Revision - 0x10000
- jne BadGpt
-
- movl %es:84(%di), %eax # EAX = SizeOfPartitionEntry
- mulb GptPartitionIndicator(%bp) # EAX = SizeOfPartitionEntry * GptPartitionIndicator
- movl %eax, %edx # EDX = SizeOfPartitionEntry * GptPartitionIndicator
- shrl $BLOCK_SHIFT, %eax # EAX = (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE
- andl $BLOCK_MASK, %edx # EDX = Targer PartitionEntryLBA Offset
- # = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
- pushl %edx
- movl %es:72(%di), %ecx # ECX = PartitionEntryLBA (Low)
- movl %es:76(%di), %ebx # EBX = PartitionEntryLBA (High)
- addl %ecx, %eax # EAX = Target PartitionEntryLBA (Low)
- # = (PartitionEntryLBA +
- # (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE)
- adcl %ebx, %edx # EDX = Target PartitionEntryLBA (High)
-
- movw $0xA00, %di # Read to 0x0000:0x0A00
- movw $1, %bx # Read 1 Block
- pushw %es
- call ReadBlocks
- popw %es
-
-# ****************************************************************************
-# Read Target DBR from hard disk to 0x0000:0x7C00
-# ****************************************************************************
- popl %edx # EDX = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
- addw %dx, %di # DI = Targer PartitionEntryLBA Offset
- cmpl $0xC12A7328, %es:(%di) # Check for EFI System Partition "C12A7328-F81F-11d2-BA4B-00A0C93EC93B"
- jne BadGpt
- cmpl $0x11d2F81F, %es:4(%di) #
- jne BadGpt
- cmpl $0xA0004BBA, %es:8(%di) #
- jne BadGpt
- cmpl $0x3BC93EC9, %es:0xc(%di) #
- jne BadGpt
-
- movl %es:32(%di), %eax # EAX = StartingLBA (Low)
- movl %es:36(%di), %edx # EDX = StartingLBA (High)
- movw $0x7C00, %di # Read to 0x0000:0x7C00
- movw $1, %bx # Read 1 Block
- call ReadBlocks
-
-# ****************************************************************************
-# Transfer control to BootSector - Jump to 0x0000:0x7C00
-# ****************************************************************************
- xorw %ax, %ax
- pushw %ax # PUSH 0x0000
- movw $0x7c00, %di
- pushw %di # PUSH 0x7C00
- retl # JMP 0x0000:0x7C00
-
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# EDX:EAX = Start LBA
-# BX = Number of Blocks to Read (must < 127)
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# si = DiskAddressPacket
-
-ReadBlocks:
- pushal
- pushw %ds
- xorw %cx, %cx
- movw %cx, %ds
- movw $0x600, %bp # bp = 0x600
- leaw AddressPacket(%bp), %si
- movb %bl, %ds:2(%si) # 02 = Number Of Block transfered
- movw %di, %ds:4(%si) # 04 = Transfer Buffer Offset
- movw %es, %ds:6(%si) # 06 = Transfer Buffer Segment
- movl %eax, %ds:8(%si) # 08 = Starting LBA (Low)
- movl %edx, %ds:0xc(%si) # 0C = Starting LBA (High)
- movb $0x42, %ah # ah = Function 42
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- int $0x13
- jc BadGpt
- popw %ds
- popal
- ret
-
-# ****************************************************************************
-# Address Packet used by ReadBlocks
-# ****************************************************************************
-AddressPacket:
- .byte 0x10 # Size of address packet
- .byte 0x0 # Reserved. Must be 0
- .byte 0x1 # Read blocks at a time (To be fixed each times)
- .byte 0x0 # Reserved. Must be 0
- .word 0x000 # Destination Address offset (To be fixed each times)
- .word 0x000 # Destination Address segment (To be fixed each times)
-AddressPacketLba:
- .long 0x0,0x0 # Start LBA (To be fixed each times)
-AddressPacketEnd:
-
-# ****************************************************************************
-# ERROR Condition:
-# ****************************************************************************
-
-BadGpt:
- movw $0xb800, %ax
- movw %ax, %es
- movw $0x60, %ax
- movw %ax, %ds
- leaw %cs:ErrorString, %si
- movw $10, %cx
- movw $320, %di
- rep
- movsw
-Halt:
- jmp Halt
-
-StartString:
- .byte 'G', 0x0c, 'P', 0x0c, 'T', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
-ErrorString:
- .byte 'G', 0x0c, 'P', 0x0c, 'T', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
-
-# ****************************************************************************
-# PhysicalDrive - Used to indicate which disk to be boot
-# Can be patched by tool
-# ****************************************************************************
- # .org 0x01B6 # Just for passing build.
-PhysicalDrive: .byte 0x80
-
-# ****************************************************************************
-# GptPartitionIndicator - Used to indicate which GPT partition to be boot
-# Can be patched by tool
-# ****************************************************************************
- # .org 0x01B7 # Just for passing build.
-GptPartitionIndicator: .byte 0
-
-# ****************************************************************************
-# Unique MBR signature
-# ****************************************************************************
- # .org 0x01B8 # Just for passing build.
- .ascii "DUET"
-
-# ****************************************************************************
-# Unknown
-# ****************************************************************************
- # .org 0x01BC # Just for passing build.
- .word 0
-
-# ****************************************************************************
-# PMBR Entry - Can be patched by tool
-# ****************************************************************************
- # .org 0x01BE # Just for passing build.
- .byte 0 # Boot Indicator
- .byte 0xff # Start Header
- .byte 0xff # Start Sector
- .byte 0xff # Start Track
- .byte 0xee # OS Type
- .byte 0xff # End Header
- .byte 0xff # End Sector
- .byte 0xff # End Track
- .long 1 # Starting LBA
- .long 0xFFFFFFFF # End LBA
-
- # .org 0x01CE # Just for passing build.
- .long 0,0,0,0
- # .org 0x01DE # Just for passing build.
- .long 0,0,0,0
- # .org 0x01EE # Just for passing build.
- .long 0,0,0,0
-
-# ****************************************************************************
-# Sector Signature
-# ****************************************************************************
-
- # .org 0x01FE # Just for passing build.
-SectorSignature:
- .word 0xaa55 # Boot Sector Signature
-
-
-
diff --git a/DuetPkg/BootSector/Gpt.asm b/DuetPkg/BootSector/Gpt.asm deleted file mode 100644 index e94075308d..0000000000 --- a/DuetPkg/BootSector/Gpt.asm +++ /dev/null @@ -1,294 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* gpt.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
-; .dosseg
- .stack
- .486p
- .code
-
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
-; ****************************************************************************
-; Code loaded by BIOS at 0x0000:0x7C00
-; ****************************************************************************
-
- org 0h
-Start:
-
-; ****************************************************************************
-; Start Print
-; ****************************************************************************
-
- mov ax,0b800h
- mov es,ax
- mov ax, 07c0h
- mov ds, ax
- lea si, cs:[StartString]
- mov cx, 10
- mov di, 160
- rep movsw
-
-; ****************************************************************************
-; Print over
-; ****************************************************************************
-
-; ****************************************************************************
-; Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
-; ****************************************************************************
- xor ax, ax ; AX = 0x0000
- mov bx, 07c00h ; BX = 0x7C00
- mov bp, 0600h ; BP = 0x0600
- mov si, OFFSET RelocatedStart ; SI = Offset(RelocatedStart)
- mov cx, 0200h ; CX = 0x0200
- sub cx, si ; CS = 0x0200 - Offset(RelocatedStart)
- lea di, [bp+si] ; DI = 0x0600 + Offset(RelocatedStart)
- lea si, [bx+si] ; BX = 0x7C00 + Offset(RelocatedStart)
- mov ss, ax ; SS = 0x0000
- mov sp, bx ; SP = 0x7C00
- mov es,ax ; ES = 0x0000
- mov ds,ax ; DS = 0x0000
- push ax ; PUSH 0x0000
- push di ; PUSH 0x0600 + Offset(RelocatedStart)
- cld ; Clear the direction flag
- rep movsb ; Copy 0x0200 bytes from 0x7C00 to 0x0600
- retf ; JMP 0x0000:0x0600 + Offset(RelocatedStart)
-
-; ****************************************************************************
-; Code relocated to 0x0000:0x0600
-; ****************************************************************************
-
-RelocatedStart:
-; ****************************************************************************
-; Get Driver Parameters to 0x0000:0x7BFC
-; ****************************************************************************
- xor ax,ax ; ax = 0
- mov ss,ax ; ss = 0
- add ax,1000h
- mov ds,ax
-
- mov sp,07c00h ; sp = 0x7c00
- mov bp,sp ; bp = 0x7c00
-
- mov ah,8 ; ah = 8 - Get Drive Parameters Function
- mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
- int 13h ; Get Drive Parameters
- xor ax,ax ; ax = 0
- mov al,dh ; al = dh
- inc al ; MaxHead = al + 1
- push ax ; 0000:7bfe = MaxHead
- mov al,cl ; al = cl
- and al,03fh ; MaxSector = al & 0x3f
- push ax ; 0000:7bfc = MaxSector
-
-; ****************************************************************************
-; Read GPT Header from hard disk to 0x0000:0x0800
-; ****************************************************************************
- xor ax, ax
- mov es, ax ; Read to 0x0000:0x0800
- mov di, 0800h ; Read to 0x0000:0x0800
- mov eax, 1 ; Read LBA #1
- mov edx, 0 ; Read LBA #1
- mov bx, 1 ; Read 1 Block
- push es
- call ReadBlocks
- pop es
-
-; ****************************************************************************
-; Read Target GPT Entry from hard disk to 0x0000:0x0A00
-; ****************************************************************************
- cmp dword ptr es:[di], 020494645h ; Check for "EFI "
- jne BadGpt
- cmp dword ptr es:[di + 4], 054524150h ; Check for "PART"
- jne BadGpt
- cmp dword ptr es:[di + 8], 000010000h ; Check Revision - 0x10000
- jne BadGpt
-
- mov eax, dword ptr es:[di + 84] ; EAX = SizeOfPartitionEntry
- mul byte ptr [bp+GptPartitionIndicator] ; EAX = SizeOfPartitionEntry * GptPartitionIndicator
- mov edx, eax ; EDX = SizeOfPartitionEntry * GptPartitionIndicator
- shr eax, BLOCK_SHIFT ; EAX = (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE
- and edx, BLOCK_MASK ; EDX = Targer PartitionEntryLBA Offset
- ; = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
- push edx
- mov ecx, dword ptr es:[di + 72] ; ECX = PartitionEntryLBA (Low)
- mov ebx, dword ptr es:[di + 76] ; EBX = PartitionEntryLBA (High)
- add eax, ecx ; EAX = Target PartitionEntryLBA (Low)
- ; = (PartitionEntryLBA +
- ; (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE)
- adc edx, ebx ; EDX = Target PartitionEntryLBA (High)
-
- mov di, 0A00h ; Read to 0x0000:0x0A00
- mov bx, 1 ; Read 1 Block
- push es
- call ReadBlocks
- pop es
-
-; ****************************************************************************
-; Read Target DBR from hard disk to 0x0000:0x7C00
-; ****************************************************************************
- pop edx ; EDX = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
- add di, dx ; DI = Targer PartitionEntryLBA Offset
- cmp dword ptr es:[di], 0C12A7328h ; Check for EFI System Partition "C12A7328-F81F-11d2-BA4B-00A0C93EC93B"
- jne BadGpt
- cmp dword ptr es:[di + 4], 011d2F81Fh ;
- jne BadGpt
- cmp dword ptr es:[di + 8], 0A0004BBAh ;
- jne BadGpt
- cmp dword ptr es:[di + 0ch], 03BC93EC9h ;
- jne BadGpt
-
- mov eax, dword ptr es:[di + 32] ; EAX = StartingLBA (Low)
- mov edx, dword ptr es:[di + 36] ; EDX = StartingLBA (High)
- mov di, 07C00h ; Read to 0x0000:0x7C00
- mov bx, 1 ; Read 1 Block
- call ReadBlocks
-
-; ****************************************************************************
-; Transfer control to BootSector - Jump to 0x0000:0x7C00
-; ****************************************************************************
- xor ax, ax
- push ax ; PUSH 0x0000
- mov di, 07c00h
- push di ; PUSH 0x7C00
- retf ; JMP 0x0000:0x7C00
-
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; EDX:EAX = Start LBA
-; BX = Number of Blocks to Read (must < 127)
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; si = DiskAddressPacket
-
-ReadBlocks:
- pushad
- push ds
- xor cx, cx
- mov ds, cx
- mov bp, 0600h ; bp = 0x600
- lea si, [bp + OFFSET AddressPacket] ; DS:SI = Disk Address Packet
- mov BYTE PTR ds:[si+2],bl ; 02 = Number Of Block transfered
- mov WORD PTR ds:[si+4],di ; 04 = Transfer Buffer Offset
- mov WORD PTR ds:[si+6],es ; 06 = Transfer Buffer Segment
- mov DWORD PTR ds:[si+8],eax ; 08 = Starting LBA (Low)
- mov DWORD PTR ds:[si+0ch],edx ; 0C = Starting LBA (High)
- mov ah, 42h ; ah = Function 42
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- int 13h
- jc BadGpt
- pop ds
- popad
- ret
-
-; ****************************************************************************
-; Address Packet used by ReadBlocks
-; ****************************************************************************
-AddressPacket:
- db 10h ; Size of address packet
- db 00h ; Reserved. Must be 0
- db 01h ; Read blocks at a time (To be fixed each times)
- db 00h ; Reserved. Must be 0
- dw 0000h ; Destination Address offset (To be fixed each times)
- dw 0000h ; Destination Address segment (To be fixed each times)
-AddressPacketLba:
- dd 0h, 0h ; Start LBA (To be fixed each times)
-AddressPacketEnd:
-
-; ****************************************************************************
-; ERROR Condition:
-; ****************************************************************************
-
-BadGpt:
- mov ax,0b800h
- mov es,ax
- mov ax, 060h
- mov ds, ax
- lea si, cs:[ErrorString]
- mov cx, 10
- mov di, 320
- rep movsw
-Halt:
- jmp Halt
-
-StartString:
- db 'G', 0ch, 'P', 0ch, 'T', 0ch, ' ', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
-ErrorString:
- db 'G', 0ch, 'P', 0ch, 'T', 0ch, ' ', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
-; ****************************************************************************
-; PhysicalDrive - Used to indicate which disk to be boot
-; Can be patched by tool
-; ****************************************************************************
- org 01B6h
-PhysicalDrive db 80h
-
-; ****************************************************************************
-; GptPartitionIndicator - Used to indicate which GPT partition to be boot
-; Can be patched by tool
-; ****************************************************************************
- org 01B7h
-GptPartitionIndicator db 0
-
-; ****************************************************************************
-; Unique MBR signature
-; ****************************************************************************
- org 01B8h
- db 'DUET'
-
-; ****************************************************************************
-; Unknown
-; ****************************************************************************
- org 01BCh
- dw 0
-
-; ****************************************************************************
-; PMBR Entry - Can be patched by tool
-; ****************************************************************************
- org 01BEh
- db 0 ; Boot Indicator
- db 0ffh ; Start Header
- db 0ffh ; Start Sector
- db 0ffh ; Start Track
- db 0eeh ; OS Type
- db 0ffh ; End Header
- db 0ffh ; End Sector
- db 0ffh ; End Track
- dd 1 ; Starting LBA
- dd 0FFFFFFFFh ; End LBA
-
- org 01CEh
- dd 0, 0, 0, 0
- org 01DEh
- dd 0, 0, 0, 0
- org 01EEh
- dd 0, 0, 0, 0
-
-; ****************************************************************************
-; Sector Signature
-; ****************************************************************************
-
- org 01FEh
-SectorSignature:
- dw 0aa55h ; Boot Sector Signature
-
- end
-
diff --git a/DuetPkg/BootSector/Makefile b/DuetPkg/BootSector/Makefile deleted file mode 100644 index cfee9a0941..0000000000 --- a/DuetPkg/BootSector/Makefile +++ /dev/null @@ -1,173 +0,0 @@ -## @file
-#
-# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-#
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-##
-
-BASETOOLS_DIR = $(EDK_TOOLS_PATH)\Bin\Win32
-
-#
-# Build Macro
-#
-ASSEMBLY_CODE_FILE_LIST = $(MODULE_DIR)\bootsect.asm \
- $(MODULE_DIR)\bs16.asm \
- $(MODULE_DIR)\bs32.asm \
- $(MODULE_DIR)\efi32.asm \
- $(MODULE_DIR)\Gpt.asm \
- $(MODULE_DIR)\Mbr.asm \
- $(MODULE_DIR)\start.asm \
- $(MODULE_DIR)\start16.asm \
- $(MODULE_DIR)\start32.asm
-
-TARGET_FILES = $(OUTPUT_DIR)\bootsect.com \
- $(OUTPUT_DIR)\bs16.com \
- $(OUTPUT_DIR)\bs32.com \
- $(OUTPUT_DIR)\Gpt.com \
- $(OUTPUT_DIR)\Mbr.com \
- $(OUTPUT_DIR)\Start.com \
- $(OUTPUT_DIR)\Start16.com \
- $(OUTPUT_DIR)\Start32.com \
- $(OUTPUT_DIR)\Start64.com \
- $(OUTPUT_DIR)\St16_64.com \
- $(OUTPUT_DIR)\St32_64.com \
- $(OUTPUT_DIR)\efi32.com2 \
- $(OUTPUT_DIR)\efi64.com2
-
-INC =
-
-
-#OBJECTS =
-
-LIBS =
-
-COMMON_DEPS =
-
-all: $(TARGET_FILES)
-
-#=============
-$(OUTPUT_DIR)\bootsect.obj:$(MODULE_DIR)\bootsect.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\bootsect.obj" /FR"$(OUTPUT_DIR)\bootsect.txt" "$(MODULE_DIR)\bootsect.asm"
-
-$(OUTPUT_DIR)\bootsect.com:$(OUTPUT_DIR)\bootsect.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\bootsect.obj,$(OUTPUT_DIR)\bootsect.com,$(OUTPUT_DIR)\bootsect.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\bs16.obj:$(MODULE_DIR)\bs16.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\bs16.obj" "$(MODULE_DIR)\bs16.asm"
-
-$(OUTPUT_DIR)\bs16.com:$(OUTPUT_DIR)\bs16.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\bs16.obj,$(OUTPUT_DIR)\bs16.com,$(OUTPUT_DIR)\bs16.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\bs32.obj:$(MODULE_DIR)\bs32.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\bs32.obj" "$(MODULE_DIR)\bs32.asm"
-
-$(OUTPUT_DIR)\bs32.com:$(OUTPUT_DIR)\bs32.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\bs32.obj,$(OUTPUT_DIR)\bs32.com,$(OUTPUT_DIR)\bs32.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\Gpt.obj:$(MODULE_DIR)\Gpt.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Gpt.obj" "$(MODULE_DIR)\Gpt.asm"
-
-$(OUTPUT_DIR)\Gpt.com:$(OUTPUT_DIR)\Gpt.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\Gpt.obj,$(OUTPUT_DIR)\Gpt.com,$(OUTPUT_DIR)\Gpt.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\Mbr.obj:$(MODULE_DIR)\Mbr.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Mbr.obj" "$(MODULE_DIR)\Mbr.asm"
-
-$(OUTPUT_DIR)\Mbr.com:$(OUTPUT_DIR)\Mbr.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\Mbr.obj,$(OUTPUT_DIR)\Mbr.com,$(OUTPUT_DIR)\Mbr.map,,,
-
-#============
-
-$(OUTPUT_DIR)\Start.obj:$(MODULE_DIR)\Start.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start.obj" "$(MODULE_DIR)\Start.asm"
-
-$(OUTPUT_DIR)\Start.com:$(OUTPUT_DIR)\Start.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start.obj,$(OUTPUT_DIR)\Start.com,$(OUTPUT_DIR)\Start.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\Start16.obj:$(MODULE_DIR)\Start16.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start16.obj" "$(MODULE_DIR)\Start16.asm"
-
-$(OUTPUT_DIR)\Start16.com:$(OUTPUT_DIR)\Start16.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start16.obj,$(OUTPUT_DIR)\Start16.com,$(OUTPUT_DIR)\Start16.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\Start32.obj:$(MODULE_DIR)\Start32.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start32.obj" "$(MODULE_DIR)\Start32.asm"
-
-$(OUTPUT_DIR)\Start32.com:$(OUTPUT_DIR)\Start32.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start32.obj,$(OUTPUT_DIR)\Start32.com,$(OUTPUT_DIR)\Start32.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\Start64.obj:$(MODULE_DIR)\Start64.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start64.obj" "$(MODULE_DIR)\Start64.asm"
-
-$(OUTPUT_DIR)\Start64.com:$(OUTPUT_DIR)\Start64.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start64.obj,$(OUTPUT_DIR)\Start64.com,$(OUTPUT_DIR)\Start64.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\St16_64.obj:$(MODULE_DIR)\St16_64.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\St16_64.obj" "$(MODULE_DIR)\St16_64.asm"
-
-$(OUTPUT_DIR)\St16_64.com:$(OUTPUT_DIR)\St16_64.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\St16_64.obj,$(OUTPUT_DIR)\St16_64.com,$(OUTPUT_DIR)\St16_64.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\St32_64.obj:$(MODULE_DIR)\St32_64.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\St32_64.obj" "$(MODULE_DIR)\St32_64.asm"
-
-$(OUTPUT_DIR)\St32_64.com:$(OUTPUT_DIR)\St32_64.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\St32_64.obj,$(OUTPUT_DIR)\St32_64.com,$(OUTPUT_DIR)\St32_64.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\efi32.obj:$(MODULE_DIR)\efi32.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\efi32.obj" "$(MODULE_DIR)\efi32.asm"
-
-$(OUTPUT_DIR)\efi32.com:$(OUTPUT_DIR)\efi32.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\efi32.obj,$(OUTPUT_DIR)\efi32.com,$(OUTPUT_DIR)\efi32.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\efi32.com2:$(OUTPUT_DIR)\efi32.com
- $(BASETOOLS_DIR)\Split.exe -f $(OUTPUT_DIR)\efi32.com -t $(OUTPUT_DIR)\efi32.com2 -s 135168
-
-#=============
-
-$(OUTPUT_DIR)\efi64.obj:$(MODULE_DIR)\efi64.asm
- "$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\efi64.obj" "$(MODULE_DIR)\efi64.asm"
-
-$(OUTPUT_DIR)\efi64.com:$(OUTPUT_DIR)\efi64.obj
- "$(ASMLINK)" /tiny $(OUTPUT_DIR)\efi64.obj,$(OUTPUT_DIR)\efi64.com,$(OUTPUT_DIR)\efi64.map,,,
-
-#=============
-
-$(OUTPUT_DIR)\efi64.com2:$(OUTPUT_DIR)\efi64.com
- $(BASETOOLS_DIR)\Split.exe -f $(OUTPUT_DIR)\efi64.com -t $(OUTPUT_DIR)\efi64.com2 -s 135168
-
-
-clean:
- if exist $(DEBUG_DIR) rmdir /s /q $(DEBUG_DIR)
- if exist $(OUTPUT_DIR) rmdir /s /q $(OUTPUT_DIR)
-
-
diff --git a/DuetPkg/BootSector/Mbr.S b/DuetPkg/BootSector/Mbr.S deleted file mode 100644 index 65c97ea973..0000000000 --- a/DuetPkg/BootSector/Mbr.S +++ /dev/null @@ -1,262 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* Mbr.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
- .code16
-
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
-# ****************************************************************************
-# Code loaded by BIOS at 0x0000:0x7C00
-# ****************************************************************************
-
-.org 0x0
-
-.global _start
-_start:
-
-# ****************************************************************************
-# Start Print
-# ****************************************************************************
-
- movw $0xb800, %ax
- movw %ax, %es
- movw $0x7c0, %ax
- movw %ax, %ds
- leaw %cs:StartString, %si
- movw $10, %cx
- movw $160, %di
- rep
- movsw
-
-# ****************************************************************************
-# Print over
-# ****************************************************************************
-
-# ****************************************************************************
-# Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
-# ****************************************************************************
- xorw %ax, %ax # AX = 0x0000
- movw $0x7c00, %bx # BX = 0x7C00
- movw $0x600, %bp # BP = 0x0600
- movw $RelocatedStart, %si # SI = Offset(RelocatedStart)
- movw $0x200, %cx # CX = 0x0200
- subw %si, %cx # CS = 0x0200 - Offset(RelocatedStart)
- leaw (%bp,%si,), %di # DI = 0x0600 + Offset(RelocatedStart)
- leaw (%bx,%si,), %si # BX = 0x7C00 + Offset(RelocatedStart)
- movw %ax, %ss # SS = 0x0000
- movw %bx, %sp # SP = 0x7C00
- movw %ax, %es # ES = 0x0000
- movw %ax, %ds # DS = 0x0000
- pushw %ax # PUSH 0x0000
- pushw %di # PUSH 0x0600 + Offset(RelocatedStart)
- cld # Clear the direction flag
- rep
- movsb # Copy 0x0200 bytes from 0x7C00 to 0x0600
- retl # JMP 0x0000:0x0600 + Offset(RelocatedStart)
-
-# ****************************************************************************
-# Code relocated to 0x0000:0x0600
-# ****************************************************************************
-
-RelocatedStart:
-# ****************************************************************************
-# Get Driver Parameters to 0x0000:0x7BFC
-# ****************************************************************************
-
- xorw %ax, %ax # AX = 0
- movw %ax, %ss # SS = 0
- addw $0x1000, %ax
- movw %ax, %ds
-
- movw $0x7c00, %sp # SP = 0x7c00
- movw %sp, %bp # BP = 0x7c00
-
- movb $8, %ah # AH = 8 - Get Drive Parameters Function
- movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
- int $0x13 # Get Drive Parameters
- xorw %ax, %ax # AX = 0
- movb %dh, %al # AL = DH
- incb %al # MaxHead = AL + 1
- pushw %ax # 0000:7bfe = MaxHead
- movb %cl, %al # AL = CL
- andb $0x3f, %al # MaxSector = AL & 0x3f
- pushw %ax # 0000:7bfc = MaxSector
-
-# ****************************************************************************
-# Read Target DBR from hard disk to 0x0000:0x7C00
-# ****************************************************************************
-
- xorw %ax, %ax
- movb MbrPartitionIndicator(%bp), %al # AX = MbrPartitionIndex
- cmpb $0xff, %al # 0xFF means do legacy MBR boot
- jnz EfiDbr
-LegacyMbr:
- movl $0x0000600, %eax # Assume LegacyMBR is backuped in Sector 6
- jmp StartReadTo7C00 # EAX = Header/Sector/Tracker/Zero
-
-EfiDbr:
- cmpb $4, %al # MbrPartitionIndex should < 4
- jae BadDbr
- shlw $4, %ax # AX = MBREntrySize * Index
- addw $0x1be, %ax # AX = MBREntryOffset
- movw %ax, %di # DI = MBREntryOffset
-
- # Here we don't use the C/H/S information provided by Partition table
- # but calculate C/H/S from LBA ourselves
- # Ci: Cylinder number
- # Hi: Header number
- # Si: Sector number
- movl %es:8(%bp,%di,), %eax # Start LBA
- movl %eax, %edx
- shrl $16, %edx # DX:AX = Start LBA
- # = Ci * (H * S) + Hi * S + (Si - 1)
-
- # Calculate C/H/S according to LBA
- movw $0x7bfa, %bp
- divw 2(%bp) # AX = Hi + H*Ci
- # DX = Si - 1
- incw %dx # DX = Si
- pushw %dx # 0000:7bfa = Si <----
- xorw %dx, %dx # DX:AX = Hi + H*Ci
- divw 4(%bp) # AX = Ci <----
- # DX = Hi <----
-
-StartReadTo7C00:
-
- movb (%bp), %cl # Si
- movb %al, %ch # Ci[0-7]
- orb %ah, %cl # Ci[8,9]
- movw $0x7c00, %bx # ES:BX = 0000:7C00h
- movb $0x2, %ah # Function 02h
- movb $1, %al # 1 Sector
- movb %dl, %dh # Hi
- movw $0x600, %bp
- movb PhysicalDrive(%bp), %dl # Drive number
- int $0x13
- jc BadDbr
-
-
-
-# ****************************************************************************
-# Transfer control to BootSector - Jump to 0x0000:0x7C00
-# ****************************************************************************
- xorw %ax, %ax
- pushw %ax # PUSH 0x0000 - Segment
- movw $0x7c00, %di
- pushw %di # PUSH 0x7C00 - Offset
- retl # JMP 0x0000:0x7C00
-
-# ****************************************************************************
-# ERROR Condition:
-# ****************************************************************************
-
-BadDbr:
- pushw %ax
- movw $0xb800, %ax
- movw %ax, %es
- movw $0x60, %ax
- movw %ax, %ds
- leaw %cs:ErrorString, %si
- movw $320, %di
- popw %ax
- call A2C
- movb %ah, 16(%si)
- movb %al, 18(%si)
- movw $10, %cx
- rep
- movsw
-Halt:
- jmp Halt
-
-StartString:
-.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
-ErrorString:
-.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, ':', 0x0c, '?', 0x0c, '?', 0x0c
-
-# ****************************************************************************
-# A2C - convert Ascii code stored in AH to character stored in AX
-# ****************************************************************************
-A2C:
- movb %ah, %al
- shrb $4, %ah
- andb $0xF, %al
- addb '0', %ah
- addb '0', %al
-
- cmpb '9', %ah
- jle A2C_L1
- addb $7, %ah
-A2C_L1:
-
- cmpb '9', %al
- jle A2C_L2
- addb $7, %al
-A2C_L2:
- ret
-
-
-# ****************************************************************************
-# PhysicalDrive - Used to indicate which disk to be boot
-# Can be patched by tool
-# ****************************************************************************
-.org 0x01B6
-PhysicalDrive: .byte 0x80
-
-# ****************************************************************************
-# MbrPartitionIndicator - Used to indicate which MBR partition to be boot
-# Can be patched by tool
-# OxFF means boot to legacy MBR. (LBA OFFSET 6)
-# ****************************************************************************
-.org 0x01B7
-MbrPartitionIndicator: .byte 0
-
-# ****************************************************************************
-# Unique MBR signature
-# ****************************************************************************
-.org 0x01B8
- .ascii "DUET"
-
-# ****************************************************************************
-# Unknown
-# ****************************************************************************
-.org 0x01BC
- .word 0
-
-# ****************************************************************************
-# MBR Entry - To be patched
-# ****************************************************************************
-.org 0x01BE
- .long 0,0,0,0
-.org 0x01CE
- .long 0,0,0,0
-.org 0x01DE
- .long 0,0,0,0
-.org 0x01EE
- .long 0,0,0,0
-
-# ****************************************************************************
-# Sector Signature
-# ****************************************************************************
-
-.org 0x01FE
-SectorSignature:
- .word 0xaa55 # Boot Sector Signature
-
-
-
diff --git a/DuetPkg/BootSector/Mbr.asm b/DuetPkg/BootSector/Mbr.asm deleted file mode 100644 index b105c08901..0000000000 --- a/DuetPkg/BootSector/Mbr.asm +++ /dev/null @@ -1,261 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* Mbr.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
-; .dosseg
- .stack
- .486p
- .code
-
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
-; ****************************************************************************
-; Code loaded by BIOS at 0x0000:0x7C00
-; ****************************************************************************
-
- org 0h
-Start:
-
-; ****************************************************************************
-; Start Print
-; ****************************************************************************
-
- mov ax,0b800h
- mov es,ax
- mov ax, 07c0h
- mov ds, ax
- lea si, cs:[StartString]
- mov cx, 10
- mov di, 160
- rep movsw
-
-; ****************************************************************************
-; Print over
-; ****************************************************************************
-
-; ****************************************************************************
-; Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
-; ****************************************************************************
- xor ax, ax ; AX = 0x0000
- mov bx, 07c00h ; BX = 0x7C00
- mov bp, 0600h ; BP = 0x0600
- mov si, OFFSET RelocatedStart ; SI = Offset(RelocatedStart)
- mov cx, 0200h ; CX = 0x0200
- sub cx, si ; CS = 0x0200 - Offset(RelocatedStart)
- lea di, [bp+si] ; DI = 0x0600 + Offset(RelocatedStart)
- lea si, [bx+si] ; BX = 0x7C00 + Offset(RelocatedStart)
- mov ss, ax ; SS = 0x0000
- mov sp, bx ; SP = 0x7C00
- mov es,ax ; ES = 0x0000
- mov ds,ax ; DS = 0x0000
- push ax ; PUSH 0x0000
- push di ; PUSH 0x0600 + Offset(RelocatedStart)
- cld ; Clear the direction flag
- rep movsb ; Copy 0x0200 bytes from 0x7C00 to 0x0600
- retf ; JMP 0x0000:0x0600 + Offset(RelocatedStart)
-
-; ****************************************************************************
-; Code relocated to 0x0000:0x0600
-; ****************************************************************************
-
-RelocatedStart:
-; ****************************************************************************
-; Get Driver Parameters to 0x0000:0x7BFC
-; ****************************************************************************
-
- xor ax,ax ; AX = 0
- mov ss,ax ; SS = 0
- add ax,1000h
- mov ds,ax
-
- mov sp,07c00h ; SP = 0x7c00
- mov bp,sp ; BP = 0x7c00
-
- mov ah,8 ; AH = 8 - Get Drive Parameters Function
- mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
- int 13h ; Get Drive Parameters
- xor ax,ax ; AX = 0
- mov al,dh ; AL = DH
- inc al ; MaxHead = AL + 1
- push ax ; 0000:7bfe = MaxHead
- mov al,cl ; AL = CL
- and al,03fh ; MaxSector = AL & 0x3f
- push ax ; 0000:7bfc = MaxSector
-
-; ****************************************************************************
-; Read Target DBR from hard disk to 0x0000:0x7C00
-; ****************************************************************************
-
- xor ax, ax
- mov al, byte ptr [bp+MbrPartitionIndicator] ; AX = MbrPartitionIndex
- cmp al, 0ffh ; 0xFF means do legacy MBR boot
- jnz EfiDbr
-LegacyMbr:
- mov eax, 00000600h ; Assume LegacyMBR is backuped in Sector 6
- jmp StartReadTo7C00 ; EAX = Header/Sector/Tracker/Zero
-
-EfiDbr:
- cmp al, 4 ; MbrPartitionIndex should < 4
- jae BadDbr
- shl ax, 4 ; AX = MBREntrySize * Index
- add ax, 1beh ; AX = MBREntryOffset
- mov di, ax ; DI = MBREntryOffset
-
- ; Here we don't use the C/H/S information provided by Partition table
- ; but calculate C/H/S from LBA ourselves
- ; Ci: Cylinder number
- ; Hi: Header number
- ; Si: Sector number
- mov eax, dword ptr es:[bp + di + 8] ; Start LBA
- mov edx, eax
- shr edx, 16 ; DX:AX = Start LBA
- ; = Ci * (H * S) + Hi * S + (Si - 1)
-
- ; Calculate C/H/S according to LBA
- mov bp, 7bfah
- div word ptr [bp+2] ; AX = Hi + H*Ci
- ; DX = Si - 1
- inc dx ; DX = Si
- push dx ; 0000:7bfa = Si <----
- xor dx, dx ; DX:AX = Hi + H*Ci
- div word ptr [bp+4] ; AX = Ci <----
- ; DX = Hi <----
-
-StartReadTo7C00:
-
- mov cl, byte ptr [bp] ; Si
- mov ch, al ; Ci[0-7]
- or cl, ah ; Ci[8,9]
- mov bx, 7c00h ; ES:BX = 0000:7C00h
- mov ah, 2h ; Function 02h
- mov al, 1 ; 1 Sector
- mov dh, dl ; Hi
- mov bp, 0600h
- mov dl, byte ptr [bp + PhysicalDrive] ; Drive number
- int 13h
- jc BadDbr
-
-
-
-; ****************************************************************************
-; Transfer control to BootSector - Jump to 0x0000:0x7C00
-; ****************************************************************************
- xor ax, ax
- push ax ; PUSH 0x0000 - Segment
- mov di, 07c00h
- push di ; PUSH 0x7C00 - Offset
- retf ; JMP 0x0000:0x7C00
-
-; ****************************************************************************
-; ERROR Condition:
-; ****************************************************************************
-
-BadDbr:
- push ax
- mov ax, 0b800h
- mov es, ax
- mov ax, 060h
- mov ds, ax
- lea si, cs:[ErrorString]
- mov di, 320
- pop ax
- call A2C
- mov [si+16], ah
- mov [si+18], al
- mov cx, 10
- rep movsw
-Halt:
- jmp Halt
-
-StartString:
- db 'M', 0ch, 'B', 0ch, 'R', 0ch, ' ', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
-ErrorString:
- db 'M', 0ch, 'B', 0ch, 'R', 0ch, ' ', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, ':', 0ch, '?', 0ch, '?', 0ch
-
-; ****************************************************************************
-; A2C - convert Ascii code stored in AH to character stored in AX
-; ****************************************************************************
-A2C:
- mov al, ah
- shr ah, 4
- and al, 0Fh
- add ah, '0'
- add al, '0'
-
- cmp ah, '9'
- jle @f
- add ah, 7
-@@:
-
- cmp al, '9'
- jle @f
- add al, 7
-@@:
- ret
-
-
-; ****************************************************************************
-; PhysicalDrive - Used to indicate which disk to be boot
-; Can be patched by tool
-; ****************************************************************************
- org 01B6h
-PhysicalDrive db 80h
-
-; ****************************************************************************
-; MbrPartitionIndicator - Used to indicate which MBR partition to be boot
-; Can be patched by tool
-; OxFF means boot to legacy MBR. (LBA OFFSET 6)
-; ****************************************************************************
- org 01B7h
-MbrPartitionIndicator db 0
-
-; ****************************************************************************
-; Unique MBR signature
-; ****************************************************************************
- org 01B8h
- db 'DUET'
-
-; ****************************************************************************
-; Unknown
-; ****************************************************************************
- org 01BCh
- dw 0
-
-; ****************************************************************************
-; MBR Entry - To be patched
-; ****************************************************************************
- org 01BEh
- dd 0, 0, 0, 0
- org 01CEh
- dd 0, 0, 0, 0
- org 01DEh
- dd 0, 0, 0, 0
- org 01EEh
- dd 0, 0, 0, 0
-
-; ****************************************************************************
-; Sector Signature
-; ****************************************************************************
-
- org 01FEh
-SectorSignature:
- dw 0aa55h ; Boot Sector Signature
-
- end
-
diff --git a/DuetPkg/BootSector/bin/Gpt.com b/DuetPkg/BootSector/bin/Gpt.com Binary files differdeleted file mode 100644 index f055fd7428..0000000000 --- a/DuetPkg/BootSector/bin/Gpt.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/Mbr.com b/DuetPkg/BootSector/bin/Mbr.com Binary files differdeleted file mode 100644 index ca292a0116..0000000000 --- a/DuetPkg/BootSector/bin/Mbr.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/Readme.txt b/DuetPkg/BootSector/bin/Readme.txt deleted file mode 100644 index 55dd8cd666..0000000000 --- a/DuetPkg/BootSector/bin/Readme.txt +++ /dev/null @@ -1,8 +0,0 @@ -These binaries are used to make the bootable floppy or usb disk.
-The binaries of boot sector are built from DuetPkg\Bootsector\BootSector.inf at r8617 with following steps:
-1) enter edk2 workspace directory from command line windows.
-2) run "edksetup.bat"
-3) run "build -p DuetPkg/DuetPkg.dsc -a IA32 -m DuetPkg/BootSector/BootSector.inf"
-
-
-
diff --git a/DuetPkg/BootSector/bin/St16_64.com b/DuetPkg/BootSector/bin/St16_64.com Binary files differdeleted file mode 100644 index dbb4a9af7e..0000000000 --- a/DuetPkg/BootSector/bin/St16_64.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/St32_64.com b/DuetPkg/BootSector/bin/St32_64.com Binary files differdeleted file mode 100644 index 68b6c76ea2..0000000000 --- a/DuetPkg/BootSector/bin/St32_64.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/Start.com b/DuetPkg/BootSector/bin/Start.com Binary files differdeleted file mode 100644 index 0fd19a14a9..0000000000 --- a/DuetPkg/BootSector/bin/Start.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/Start16.com b/DuetPkg/BootSector/bin/Start16.com Binary files differdeleted file mode 100644 index b2d77c1262..0000000000 --- a/DuetPkg/BootSector/bin/Start16.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/Start32.com b/DuetPkg/BootSector/bin/Start32.com Binary files differdeleted file mode 100644 index ac0e3cb20b..0000000000 --- a/DuetPkg/BootSector/bin/Start32.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/Start64.com b/DuetPkg/BootSector/bin/Start64.com Binary files differdeleted file mode 100644 index 326e3fec3c..0000000000 --- a/DuetPkg/BootSector/bin/Start64.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/bootsect.com b/DuetPkg/BootSector/bin/bootsect.com Binary files differdeleted file mode 100644 index 079978e79e..0000000000 --- a/DuetPkg/BootSector/bin/bootsect.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/bs16.com b/DuetPkg/BootSector/bin/bs16.com Binary files differdeleted file mode 100644 index be40ba817b..0000000000 --- a/DuetPkg/BootSector/bin/bs16.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/bs32.com b/DuetPkg/BootSector/bin/bs32.com Binary files differdeleted file mode 100644 index 9cd368aaa9..0000000000 --- a/DuetPkg/BootSector/bin/bs32.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/efi32.com b/DuetPkg/BootSector/bin/efi32.com Binary files differdeleted file mode 100644 index 4bcd83e2ac..0000000000 --- a/DuetPkg/BootSector/bin/efi32.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/efi32.com2 b/DuetPkg/BootSector/bin/efi32.com2 Binary files differdeleted file mode 100644 index 05522eccc5..0000000000 --- a/DuetPkg/BootSector/bin/efi32.com2 +++ /dev/null diff --git a/DuetPkg/BootSector/bin/efi64.com b/DuetPkg/BootSector/bin/efi64.com Binary files differdeleted file mode 100644 index e534132384..0000000000 --- a/DuetPkg/BootSector/bin/efi64.com +++ /dev/null diff --git a/DuetPkg/BootSector/bin/efi64.com2 b/DuetPkg/BootSector/bin/efi64.com2 Binary files differdeleted file mode 100644 index 689f4ab4a3..0000000000 --- a/DuetPkg/BootSector/bin/efi64.com2 +++ /dev/null diff --git a/DuetPkg/BootSector/bootsect.S b/DuetPkg/BootSector/bootsect.S deleted file mode 100644 index 5993a1ac99..0000000000 --- a/DuetPkg/BootSector/bootsect.S +++ /dev/null @@ -1,303 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* bootsect.S
-#*
-#* bootsect.S is built as 16-bit binary file in 512 bytes and patched to disk/partition's
-#* first section - boot sector.
-#*
-#* The startup sequence for DUET disk boot sector is:
-#*
-#* 1, LegacyBios check 0xAA55 signature at boot sectore offset 0x1FE to judget
-#* whether disk/partition is bootable.
-#* 2, LegacyBios will load boot sector to 0x7c00 in real mode, pass BPB data and
-#* hand off control to 0x7c00 code.
-#* 3, boot sector code simply parse FAT format in boot disk and find EfiLdr binary file
-#* and EfiVar.bin if exists. For first boot, EfiVar.bin does not exist.
-#* 4, boot sector load the first sector of EfiLdr binary which is start.com to
-#* 0x2000:0x0000 address.
-#* 5, boot sector handoff control to 0x2000:0x0000 for start.com binary.
-#*
-#------------------------------------------------------------------------------
-
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
- # "EFILDR_____"
-.equ LOADER_FILENAME_PART1, 0x04c494645 # "EFIL"
-.equ LOADER_FILENAME_PART2, 0x020205244 # "DR__"
-.equ LOADER_FILENAME_PART3, 0x020202020 # "____"
-
- .org 0x0
-.global _start
-_start:
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-# BPB data below will be fixed by tool
-SectorSize: .word 0 # Sector Size - 16 bits
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
-ReservedSectors: .word 0 # Reserved Sectors - 16 bits
-NoFats: .byte 0 # Number of FATs - 8 bits
-RootEntries: .word 0 # Root Entries - 16 bits
-Sectors: .word 0 # Number of Sectors - 16 bits
-Media: .byte 0 # Media - 8 bits - ignored
-SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
-SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
-Heads: .word 0 # Heads - 16 bits - ignored
-HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
-LargeSectors: .long 0 # Large Sectors - 32 bits
-PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
-CurrentHead: .byte 0 # Current Head - 8 bits
-Signature: .byte 0 # Signature - 8 bits - ignored
-VolId: .ascii " " # Volume Serial Number- 4 bytes
-FatLabel: .ascii " " # Label - 11 bytes
-SystemId: .ascii "FAT12 " # SystemId - 8 bytes
-
-BootSectorEntryPoint:
- #ASSUME ds:@code
- #ASSUME ss:@code
-
-# ****************************************************************************
-# Start Print
-# ****************************************************************************
- movw $StartString, %si
- call PrintString
-
-# ****************************************************************************
-# Print over
-# ****************************************************************************
-
- movw %cs, %ax # ax = 0
- movw %ax, %ss # ss = 0
- addw $0x1000, %ax
- movw %ax, %ds
-
- movw $0x7c00, %sp # sp = 0x7c00
- movw %sp, %bp # bp = 0x7c00
-
- movb $8, %ah # ah = 8 - Get Drive Parameters Function
- movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
- int $0x13 # Get Drive Parameters
- xorw %ax, %ax # ax = 0
- movb %dh, %al # al = dh
- incb %al # MaxHead = al + 1
- pushw %ax # 0000:7bfe = MaxHead
- movb %cl, %al # al = cl
- andb $0x3f, %al # MaxSector = al & 0x3f
- pushw %ax # 0000:7bfc = MaxSector
-
- cmpw $0xaa55, SectorSignature(%bp) # Verify Boot Sector Signature
- jne BadBootSector
- movw RootEntries(%bp), %cx # cx = RootEntries
- shlw $FAT_DIRECTORY_ENTRY_SHIFT, %cx # cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
- movw %cx, %bx # bx = size of the Root Directory in bytes
- andw $BLOCK_MASK, %bx # See if it is an even number of sectors long
- jne BadBootSector # If is isn't, then the boot sector is bad.
- movw %cx, %bx # bx = size of the Root Directory in bytes
- shrw $BLOCK_SHIFT, %bx # bx = size of Root Directory in sectors
- movb NoFats(%bp), %al # al = NoFats
- xorb %ah, %ah # ah = 0 ==> ax = NoFats
- mulw SectorsPerFat(%bp) # ax = NoFats * SectorsPerFat
- addw ReservedSectors(%bp), %ax # ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
- pushw %ds
- popw %es
- xorw %di, %di # Store directory in es:di = 1000:0000
- call ReadBlocks # Read entire Root Directory
- addw %bx, %ax # ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
- movw %ax, (%bp) # Save FirstClusterLBA (FirstDataSector) for later use
-
- # dx - variable storage (initial value is 0)
- # bx - loader (initial value is 0)
- xorw %dx, %dx
- xorw %bx, %bx
-
-FindEFILDR:
- cmpl $LOADER_FILENAME_PART1, (%di) # Compare to "EFIL"
- jne FindVARSTORE
- cmpl $LOADER_FILENAME_PART2, 4(%di)
- jne FindVARSTORE
- cmpl $LOADER_FILENAME_PART3, 7(%di)
- jne FindVARSTORE
- movw 26(%di), %bx # bx = Start Cluster for EFILDR <----------------------------------
- testw %dx, %dx
- je FindNext # Efivar.bin is not loaded
- jmp FoundAll
-
-FindVARSTORE:
- ## if the file is not loader file, see if it's "EFIVAR BIN"
- cmpl $0x56494645, (%di) # Compare to "EFIV"
- jne FindNext
- cmpl $0x20205241, 4(%di) # Compare to "AR "
- jne FindNext
- cmpl $0x4e494220, 7(%di) # Compare to " BIN"
- jne FindNext
- movw %di, %dx # dx = Offset of Start Cluster for Efivar.bin <---------------------
- addw $26, %dx
- testw %bx, %bx
- je FindNext # Efildr is not loaded
- jmp FoundAll
-
-FindNext:
- # go to next find
- addw $FAT_DIRECTORY_ENTRY_SIZE, %di # Increment di
- subw $FAT_DIRECTORY_ENTRY_SIZE, %cx # Decrement cx
- # TODO: jump to FindVarStore if ...
- jne FindEFILDR
- jmp NotFoundAll
-
-FoundAll:
-FoundEFILDR:
- movw %bx, %cx # cx = Start Cluster for EFILDR <----------------------------------
- movw %cs, %ax # Destination = 2000:0000
- addw $0x2000, %ax
- movw %ax, %es
- xorw %di, %di
-ReadFirstClusterOfEFILDR:
- movw %cx, %ax # ax = StartCluster
- subw $2, %ax # ax = StartCluster - 2
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- pushw %dx
- mulw %bx
- popw %dx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = Number of Sectors in a cluster
- pushw %es
- call ReadBlocks
- popw %ax
-JumpIntoFirstSectorOfEFILDR:
- movw %ax, JumpSegment(%bp)
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x000
-JumpSegment:
- .word 0x2000
-
-
-PrintString:
- movw $0xb800, %ax
- movw %ax, %es
- movw $0x7c0, %ax
- movw %ax, %ds
- movw $7, %cx
- movw $160, %di
- rep
- movsw
- ret
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax, %esi # esi = Start LBA
- movw %bx, %cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc, %bp # bp = 0x7bfc
- movl %esi, %eax # eax = Start LBA
- xorl %edx, %edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
- subw %dx, %bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx, %bx # bx = Blocks
-LimitTransfer:
- pushw %cx
- movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx, %dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl, %dh # dh = Head
- movw $0x7c00, %bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al, %ch # ch = Cylinder
- movb %bl, %al # al = Blocks
- movb $2, %ah # ah = Function 2
- movw %di, %bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx, %ebx
- addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
- movw %es, %ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx, %ax
- movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0, %cx
- jne ReadCylinderLoop
- popa
- ret
-
-# ****************************************************************************
-# ERROR Condition:
-# ****************************************************************************
-NotFoundAll:
- ## if we found EFILDR, continue
- testw %bx, %bx
- jne FoundEFILDR
-BadBootSector:
-DiskError:
- movw $ErrorString, %si
- call PrintString
-Halt:
- jmp Halt
-
-StartString:
- .byte 'B', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
-ErrorString:
- .byte 'B', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
-
-# ****************************************************************************
-# LBA Offset for BootSector, need patched by tool for HD boot.
-# ****************************************************************************
-
- .org 0x01fa # Comment it for pass build. Should optimise code size.
-LBAOffsetForBootSector:
- .long 0x0
-
-# ****************************************************************************
-# Sector Signature
-# ****************************************************************************
-
- .org 0x01fe # Comment it for pass build.
-SectorSignature:
- .word 0xaa55 # Boot Sector Signature
-
-
-
diff --git a/DuetPkg/BootSector/bootsect.asm b/DuetPkg/BootSector/bootsect.asm deleted file mode 100644 index 3366b7acf7..0000000000 --- a/DuetPkg/BootSector/bootsect.asm +++ /dev/null @@ -1,301 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* bootsect.asm
-;*
-;* bootsect.asm is built as 16-bit binary file in 512 bytes and patched to disk/partition's
-;* first section - boot sector.
-;*
-;* The startup sequence for DUET disk boot sector is:
-;*
-;* 1, LegacyBios check 0xAA55 signature at boot sectore offset 0x1FE to judget
-;* whether disk/partition is bootable.
-;* 2, LegacyBios will load boot sector to 0x7c00 in real mode, pass BPB data and
-;* hand off control to 0x7c00 code.
-;* 3, boot sector code simply parse FAT format in boot disk and find EfiLdr binary file
-;* and EfiVar.bin if exists. For first boot, EfiVar.bin does not exist.
-;* 4, boot sector load the first sector of EfiLdr binary which is start.com to
-;* 0x2000:0x0000 address.
-;* 5, boot sector handoff control to 0x2000:0x0000 for start.com binary.
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
- ; "EFILDR_____"
-LOADER_FILENAME_PART1 EQU 04c494645h ; "EFIL"
-LOADER_FILENAME_PART2 EQU 020205244h ; "DR__"
-LOADER_FILENAME_PART3 EQU 020202020h ; "____"
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-; BPB data below will be fixed by tool
-SectorSize dw 0 ; Sector Size - 16 bits
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits
-NoFats db 0 ; Number of FATs - 8 bits
-RootEntries dw 0 ; Root Entries - 16 bits
-Sectors dw 0 ; Number of Sectors - 16 bits
-Media db 0 ; Media - 8 bits - ignored
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
-Heads dw 0 ; Heads - 16 bits - ignored
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
-LargeSectors dd 0 ; Large Sectors - 32 bits
-PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
-CurrentHead db 0 ; Current Head - 8 bits
-Signature db 0 ; Signature - 8 bits - ignored
-Id db " " ; Id - 4 bytes
-FatLabel db " " ; Label - 11 bytes
-SystemId db "FAT12 " ; SystemId - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
-
-; ****************************************************************************
-; Start Print
-; ****************************************************************************
- lea si, cs:[StartString]
- call PrintString
-
-; ****************************************************************************
-; Print over
-; ****************************************************************************
-
- mov ax,cs ; ax = 0
- mov ss,ax ; ss = 0
- add ax,1000h
- mov ds,ax
-
- mov sp,07c00h ; sp = 0x7c00
- mov bp,sp ; bp = 0x7c00
-
- mov ah,8 ; ah = 8 - Get Drive Parameters Function
- mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
- int 13h ; Get Drive Parameters
- xor ax,ax ; ax = 0
- mov al,dh ; al = dh (number of sides (0 based))
- inc al ; MaxHead = al + 1
- push ax ; 0000:7bfe = MaxHead
- mov al,cl ; al = cl (CL = sectors per track)
- and al,03fh ; MaxSector = al & 0x3f
- push ax ; 0000:7bfc = MaxSector
-
- cmp word ptr [bp+SectorSignature],0aa55h ; Verify Boot Sector Signature
- jne BadBootSector
- mov cx,word ptr [bp+RootEntries] ; cx = RootEntries
- shl cx,FAT_DIRECTORY_ENTRY_SHIFT ; cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
- mov bx,cx ; bx = size of the Root Directory in bytes
- and bx,BLOCK_MASK ; See if it is an even number of sectors long
- jne BadBootSector ; If is isn't, then the boot sector is bad.
- mov bx,cx ; bx = size of the Root Directory in bytes
- shr bx,BLOCK_SHIFT ; bx = size of Root Directory in sectors
- mov al,byte ptr [bp+NoFats] ; al = NoFats
- xor ah,ah ; ah = 0 ==> ax = NoFats
- mul word ptr [bp+SectorsPerFat] ; ax = NoFats * SectorsPerFat
- add ax,word ptr [bp+ReservedSectors] ; ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
- push ds
- pop es
- xor di,di ; Store directory in es:di = 1000:0000
- call ReadBlocks ; Read entire Root Directory
- add ax,bx ; ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
- mov word ptr [bp],ax ; Save FirstClusterLBA (FirstDataSector) for later use
-
- ; dx - variable storage (initial value is 0)
- ; bx - loader (initial value is 0)
- xor dx, dx
- xor bx, bx
-
-FindEFILDR:
- cmp dword ptr [di],LOADER_FILENAME_PART1 ; Compare to "EFIL"
- jne FindVARSTORE
- cmp dword ptr [di+4],LOADER_FILENAME_PART2
- jne FindVARSTORE
- cmp dword ptr [di+7],LOADER_FILENAME_PART3
- jne FindVARSTORE
- mov bx, word ptr [di+26] ; bx = Start Cluster for EFILDR <----------------------------------
- test dx, dx
- je FindNext ; Efivar.bin is not loaded
- jmp FoundAll
-
-FindVARSTORE:
- ; if the file is not loader file, see if it's "EFIVAR BIN"
- cmp dword ptr [di], 056494645h ; Compare to "EFIV"
- jne FindNext
- cmp dword ptr [di+4], 020205241h ; Compare to "AR "
- jne FindNext
- cmp dword ptr [di+7], 04e494220h ; Compare to " BIN"
- jne FindNext
- mov dx, di ; dx = Offset of Start Cluster for Efivar.bin <---------------------
- add dx, 26
- test bx, bx
- je FindNext ; Efildr is not loaded
- jmp FoundAll
-
-FindNext:
- ; go to next find
- add di,FAT_DIRECTORY_ENTRY_SIZE ; Increment di
- sub cx,FAT_DIRECTORY_ENTRY_SIZE ; Decrement cx
- ; TODO: jump to FindVarStore if ...
- jne FindEFILDR
- jmp NotFoundAll
-
-FoundAll:
-FoundEFILDR: ; 0x7cfe
- mov cx,bx ; cx = Start Cluster for EFILDR <----------------------------------
- mov ax,cs ; Destination = 2000:0000
- add ax,2000h
- mov es,ax
- xor di,di
-ReadFirstClusterOfEFILDR:
- mov ax,cx ; ax = StartCluster
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- push dx
- mul bx
- pop dx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = Number of Sectors in a cluster
- push es
- call ReadBlocks
- pop ax
-JumpIntoFirstSectorOfEFILDR:
- mov word ptr [bp+JumpSegment],ax ; 0x7d26
-JumpFarInstruction: ; 0x7d2a
- db 0eah
-JumpOffset:
- dw 0000h
-JumpSegment:
- dw 2000h
-
-
-PrintString:
- mov ax,0b800h
- mov es,ax
- mov ax, 07c0h
- mov ds, ax
- mov cx, 7
- mov di, 160
- rep movsw
- ret
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-; ****************************************************************************
-; ERROR Condition:
-; ****************************************************************************
-NotFoundAll: ; 0x7da6
- ; if we found EFILDR, continue
- test bx,bx
- jne FoundEFILDR
-BadBootSector:
-DiskError:
- lea si, cs:[ErrorString]
- call PrintString
-Halt:
- jmp Halt
-
-StartString:
- db 'B', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
-ErrorString:
- db 'B', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
-; ****************************************************************************
-; LBA Offset for BootSector, need patched by tool for HD boot.
-; ****************************************************************************
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
-; ****************************************************************************
-; Sector Signature
-; ****************************************************************************
-
- org 01feh
-SectorSignature:
- dw 0aa55h ; Boot Sector Signature
-
- end
-
diff --git a/DuetPkg/BootSector/bs16.S b/DuetPkg/BootSector/bs16.S deleted file mode 100644 index 039e25666c..0000000000 --- a/DuetPkg/BootSector/bs16.S +++ /dev/null @@ -1,291 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* bs16.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
- #.MODEL small
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
- # "EFILDR_____"
-.equ LOADER_FILENAME_PART1, 0x04c494645 # "EFIL"
-.equ LOADER_FILENAME_PART2, 0x036315244 # "DR16"
-.equ LOADER_FILENAME_PART3, 0x020202036 # "6___"
-
- .org 0x0
-.global _start
-_start:
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-# BPB data below will be fixed by tool
-SectorSize: .word 0 # Sector Size - 16 bits
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
-ReservedSectors: .word 0 # Reserved Sectors - 16 bits
-NoFats: .byte 0 # Number of FATs - 8 bits
-RootEntries: .word 0 # Root Entries - 16 bits
-Sectors: .word 0 # Number of Sectors - 16 bits
-Media: .byte 0 # Media - 8 bits - ignored
-SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
-SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
-Heads: .word 0 # Heads - 16 bits - ignored
-HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
-LargeSectors: .long 0 # Large Sectors - 32 bits
-PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
-CurrentHead: .byte 0 # Current Head - 8 bits
-Signature: .byte 0 # Signature - 8 bits - ignored
-VolId: .ascii " " # Volume Serial Number- 4 bytes
-FatLabel: .ascii " " # Label - 11 bytes
-SystemId: .ascii "FAT12 " # SystemId - 8 bytes
-
-BootSectorEntryPoint:
- #ASSUME ds:@code
- #ASSUME ss:@code
-
-# ****************************************************************************
-# Start Print
-# ****************************************************************************
- movw $StartString, %si
- call PrintString
-
-# ****************************************************************************
-# Print over
-# ****************************************************************************
-
- movw %cs, %ax # ax = 0
- movw %ax, %ss # ss = 0
- addw $0x1000, %ax
- movw %ax, %ds
-
- movw $0x7c00, %sp # sp = 0x7c00
- movw %sp, %bp # bp = 0x7c00
-
- movb $8, %ah # ah = 8 - Get Drive Parameters Function
- movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
- int $0x13 # Get Drive Parameters
- xorw %ax, %ax # ax = 0
- movb %dh, %al # al = dh
- incb %al # MaxHead = al + 1
- pushw %ax # 0000:7bfe = MaxHead
- movb %cl, %al # al = cl
- andb $0x3f, %al # MaxSector = al & 0x3f
- pushw %ax # 0000:7bfc = MaxSector
-
- cmpw $0xaa55, SectorSignature(%bp) # Verify Boot Sector Signature
- jne BadBootSector
- movw RootEntries(%bp), %cx # cx = RootEntries
- shlw $FAT_DIRECTORY_ENTRY_SHIFT, %cx # cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
- movw %cx, %bx # bx = size of the Root Directory in bytes
- andw $BLOCK_MASK, %bx # See if it is an even number of sectors long
- jne BadBootSector # If is isn't, then the boot sector is bad.
- movw %cx, %bx # bx = size of the Root Directory in bytes
- shrw $BLOCK_SHIFT, %bx # bx = size of Root Directory in sectors
- movb NoFats(%bp), %al # al = NoFats
- xorb %ah, %ah # ah = 0 ==> ax = NoFats
- mulw SectorsPerFat(%bp) # ax = NoFats * SectorsPerFat
- addw ReservedSectors(%bp), %ax # ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
- pushw %ds
- popw %es
- xorw %di, %di # Store directory in es:di = 1000:0000
- call ReadBlocks # Read entire Root Directory
- addw %bx, %ax # ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
- movw %ax, (%bp) # Save FirstClusterLBA (FirstDataSector) for later use
-
- # dx - variable storage (initial value is 0)
- # bx - loader (initial value is 0)
- xorw %dx, %dx
- xorw %bx, %bx
-
-FindEFILDR:
- cmpl $LOADER_FILENAME_PART1, (%di) # Compare to "EFIL"
- jne FindVARSTORE
- cmpl $LOADER_FILENAME_PART2, 4(%di)
- jne FindVARSTORE
- cmpl $LOADER_FILENAME_PART3, 7(%di)
- jne FindVARSTORE
- movw 26(%di), %bx # bx = Start Cluster for EFILDR <----------------------------------
- testw %dx, %dx
- je FindNext # Efivar.bin is not loaded
- jmp FoundAll
-
-FindVARSTORE:
- ##if the file is not loader file, see if it's "EFIVAR BIN"
- cmpl $0x56494645, (%di) # Compare to "EFIV"
- jne FindNext
- cmpl $0x20205241, 4(%di) # Compare to "AR "
- jne FindNext
- cmpl $0x4e494220, 7(%di) # Compare to " BIN"
- jne FindNext
- movw %di, %dx # dx = Offset of Start Cluster for Efivar.bin <---------------------
- addw $26, %dx
- testw %bx, %bx
- je FindNext # Efildr is not loaded
- jmp FoundAll
-
-FindNext:
- # go to next find
- addw $FAT_DIRECTORY_ENTRY_SIZE, %di # Increment di
- subw $FAT_DIRECTORY_ENTRY_SIZE, %cx # Decrement cx
- # TODO: jump to FindVarStore if ...
- jne FindEFILDR
- jmp NotFoundAll
-
-FoundAll:
-FoundEFILDR:
- movw %bx, %cx # cx = Start Cluster for EFILDR <----------------------------------
- movw %cs, %ax # Destination = 2000:0000
- addw $0x2000, %ax
- movw %ax, %es
- xorw %di, %di
-ReadFirstClusterOfEFILDR:
- movw %cx, %ax # ax = StartCluster
- subw $2, %ax # ax = StartCluster - 2
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- pushw %dx
- mulw %bx
- popw %dx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = Number of Sectors in a cluster
- pushw %es
- call ReadBlocks
- popw %ax
-JumpIntoFirstSectorOfEFILDR:
- movw %ax, JumpSegment(%bp)
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x000
-JumpSegment:
- .word 0x2000
-
-
-PrintString:
- movw $0xb800, %ax
- movw %ax, %es
- movw $0x7c0, %ax
- movw %ax, %ds
- movw $7, %cx
- movw $160, %di
- rep
- movsw
- ret
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax, %esi # esi = Start LBA
- movw %bx, %cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc, %bp # bp = 0x7bfc
- movl %esi, %eax # eax = Start LBA
- xorl %edx, %edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
- subw %dx, %bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx, %bx # bx = Blocks
-LimitTransfer:
- pushw %cx
- movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx, %dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl, %dh # dh = Head
- movw $0x7c00, %bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al, %ch # ch = Cylinder
- movb %bl, %al # al = Blocks
- movb $2, %ah # ah = Function 2
- movw %di, %bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx, %ebx
- addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
- movw %es, %ax
- shlw $(BLOCK_SHIFT-4),%bx
- addw %bx, %ax
- movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0, %cx
- jne ReadCylinderLoop
- popa
- ret
-
-# ****************************************************************************
-# ERROR Condition:
-# ****************************************************************************
-NotFoundAll:
- ## if we found EFILDR, continue
- testw %bx, %bx
- jne FoundEFILDR
-BadBootSector:
-DiskError:
- movw $ErrorString, %si
- call PrintString
-Halt:
- jmp Halt
-
-StartString:
- .byte 'B', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
-ErrorString:
- .byte 'B', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
-
-# ****************************************************************************
-# LBA Offset for BootSector, need patched by tool for HD boot.
-# ****************************************************************************
-
- .org 0x01fa
-LBAOffsetForBootSector:
- .long 0x0
-
-# ****************************************************************************
-# Sector Signature
-# ****************************************************************************
-
- .org 0x01fe
-SectorSignature:
- .word 0xaa55 # Boot Sector Signature
-
-
-
diff --git a/DuetPkg/BootSector/bs16.asm b/DuetPkg/BootSector/bs16.asm deleted file mode 100644 index 87b76db58c..0000000000 --- a/DuetPkg/BootSector/bs16.asm +++ /dev/null @@ -1,288 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* bs16.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
- ; "EFILDR_____"
-LOADER_FILENAME_PART1 EQU 04c494645h ; "EFIL"
-LOADER_FILENAME_PART2 EQU 036315244h ; "DR16"
-LOADER_FILENAME_PART3 EQU 020202036h ; "6___"
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-; BPB data below will be fixed by tool
-SectorSize dw 0 ; Sector Size - 16 bits
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits
-NoFats db 0 ; Number of FATs - 8 bits
-RootEntries dw 0 ; Root Entries - 16 bits
-Sectors dw 0 ; Number of Sectors - 16 bits
-Media db 0 ; Media - 8 bits - ignored
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
-Heads dw 0 ; Heads - 16 bits - ignored
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
-LargeSectors dd 0 ; Large Sectors - 32 bits
-PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
-CurrentHead db 0 ; Current Head - 8 bits
-Signature db 0 ; Signature - 8 bits - ignored
-Id db " " ; Id - 4 bytes
-FatLabel db " " ; Label - 11 bytes
-SystemId db "FAT16 " ; SystemId - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
-
-; ****************************************************************************
-; Start Print
-; ****************************************************************************
- lea si, cs:[StartString]
- call PrintString
-
-; ****************************************************************************
-; Print over
-; ****************************************************************************
-
- mov ax,cs ; ax = 0
- mov ss,ax ; ss = 0
- add ax,1000h
- mov ds,ax
-
- mov sp,07c00h ; sp = 0x7c00
- mov bp,sp ; bp = 0x7c00
-
- mov ah,8 ; ah = 8 - Get Drive Parameters Function
- mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
- int 13h ; Get Drive Parameters
- xor ax,ax ; ax = 0
- mov al,dh ; al = dh
- inc al ; MaxHead = al + 1
- push ax ; 0000:7bfe = MaxHead
- mov al,cl ; al = cl
- and al,03fh ; MaxSector = al & 0x3f
- push ax ; 0000:7bfc = MaxSector
-
- cmp word ptr [bp+SectorSignature],0aa55h ; Verify Boot Sector Signature
- jne BadBootSector
- mov cx,word ptr [bp+RootEntries] ; cx = RootEntries
- shl cx,FAT_DIRECTORY_ENTRY_SHIFT ; cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
- mov bx,cx ; bx = size of the Root Directory in bytes
- and bx,BLOCK_MASK ; See if it is an even number of sectors long
- jne BadBootSector ; If is isn't, then the boot sector is bad.
- mov bx,cx ; bx = size of the Root Directory in bytes
- shr bx,BLOCK_SHIFT ; bx = size of Root Directory in sectors
- mov al,byte ptr [bp+NoFats] ; al = NoFats
- xor ah,ah ; ah = 0 ==> ax = NoFats
- mul word ptr [bp+SectorsPerFat] ; ax = NoFats * SectorsPerFat
- add ax,word ptr [bp+ReservedSectors] ; ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
- push ds
- pop es
- xor di,di ; Store directory in es:di = 1000:0000
- call ReadBlocks ; Read entire Root Directory
- add ax,bx ; ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
- mov word ptr [bp],ax ; Save FirstClusterLBA (FirstDataSector) for later use
-
- ; dx - variable storage (initial value is 0)
- ; bx - loader (initial value is 0)
- xor dx, dx
- xor bx, bx
-
-FindEFILDR:
- cmp dword ptr [di],LOADER_FILENAME_PART1 ; Compare to "EFIL"
- jne FindVARSTORE
- cmp dword ptr [di+4],LOADER_FILENAME_PART2
- jne FindVARSTORE
- cmp dword ptr [di+7],LOADER_FILENAME_PART3
- jne FindVARSTORE
- mov bx, word ptr [di+26] ; bx = Start Cluster for EFILDR <----------------------------------
- test dx, dx
- je FindNext ; Efivar.bin is not loaded
- jmp FoundAll
-
-FindVARSTORE:
- ; if the file is not loader file, see if it's "EFIVAR BIN"
- cmp dword ptr [di], 056494645h ; Compare to "EFIV"
- jne FindNext
- cmp dword ptr [di+4], 020205241h ; Compare to "AR "
- jne FindNext
- cmp dword ptr [di+7], 04e494220h ; Compare to " BIN"
- jne FindNext
- mov dx, di ; dx = Offset of Start Cluster for Efivar.bin <---------------------
- add dx, 26
- test bx, bx
- je FindNext ; Efildr is not loaded
- jmp FoundAll
-
-FindNext:
- ; go to next find
- add di,FAT_DIRECTORY_ENTRY_SIZE ; Increment di
- sub cx,FAT_DIRECTORY_ENTRY_SIZE ; Decrement cx
- ; TODO: jump to FindVarStore if ...
- jne FindEFILDR
- jmp NotFoundAll
-
-FoundAll:
-FoundEFILDR:
- mov cx,bx ; cx = Start Cluster for EFILDR <----------------------------------
- mov ax,cs ; Destination = 2000:0000
- add ax,2000h
- mov es,ax
- xor di,di
-ReadFirstClusterOfEFILDR:
- mov ax,cx ; ax = StartCluster
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- push dx
- mul bx
- pop dx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = Number of Sectors in a cluster
- push es
- call ReadBlocks
- pop ax
-JumpIntoFirstSectorOfEFILDR:
- mov word ptr [bp+JumpSegment],ax
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0000h
-JumpSegment:
- dw 2000h
-
-
-PrintString:
- mov ax,0b800h
- mov es,ax
- mov ax, 07c0h
- mov ds, ax
- mov cx, 7
- mov di, 160
- rep movsw
- ret
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-; ****************************************************************************
-; ERROR Condition:
-; ****************************************************************************
-NotFoundAll:
- ; if we found EFILDR, continue
- test bx,bx
- jne FoundEFILDR
-BadBootSector:
-DiskError:
- lea si, cs:[ErrorString]
- call PrintString
-Halt:
- jmp Halt
-
-StartString:
- db 'B', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
-ErrorString:
- db 'B', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
-; ****************************************************************************
-; LBA Offset for BootSector, need patched by tool for HD boot.
-; ****************************************************************************
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
-; ****************************************************************************
-; Sector Signature
-; ****************************************************************************
-
- org 01feh
-SectorSignature:
- dw 0aa55h ; Boot Sector Signature
-
- end
-
diff --git a/DuetPkg/BootSector/bs32.S b/DuetPkg/BootSector/bs32.S deleted file mode 100644 index 2584517386..0000000000 --- a/DuetPkg/BootSector/bs32.S +++ /dev/null @@ -1,312 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* bs32.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
- #.MODEL small
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x0020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
- # "EFILDR_____"
-.equ LOADER_FILENAME_PART1, 0x4c494645 # "EFIL"
-.equ LOADER_FILENAME_PART2, 0x30325244 # "DR20"
-.equ LOADER_FILENAME_PART3, 0x20202030 # "0___"
-
- .org 0x0
-.global _start
-_start:
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-# BPB data below will be fixed by tool
-SectorSize: .word 0 # Sector Size - 16 bits
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
-ReservedSectors: .word 0 # Reserved Sectors - 16 bits
-NoFats: .byte 0 # Number of FATs - 8 bits
-RootEntries: .word 0 # Root Entries - 16 bits
-Sectors: .word 0 # Number of Sectors - 16 bits
-Media: .byte 0 # Media - 8 bits - ignored
-SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
-SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
-Heads: .word 0 # Heads - 16 bits - ignored
-HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
-LargeSectors: .long 0 # Large Sectors - 32 bits
-
-#******************************************************************************
-#
-#The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
-#the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
-#
-#******************************************************************************
-
-SectorsPerFat32: .long 0 # Sectors Per FAT for FAT32 - 4 bytes
-ExtFlags: .word 0 # Mirror Flag - 2 bytes
-FSVersion: .word 0 # File System Version - 2 bytes
-RootCluster: .long 0 # 1st Cluster Number of Root Dir - 4 bytes
-FSInfo: .word 0 # Sector Number of FSINFO - 2 bytes
-BkBootSector: .word 0 # Sector Number of Bk BootSector - 2 bytes
-Reserved: .fill 12, 1, 0 # Reserved Field - 12 bytes
-PhysicalDrive: .byte 0 # Physical Drive Number - 1 byte
-Reserved1: .byte 0 # Reserved Field - 1 byte
-Signature: .byte 0 # Extended Boot Signature - 1 byte
-VolId: .ascii " " # Volume Serial Number - 4 bytes
-FatLabel: .ascii " " # Volume Label - 11 bytes
-FileSystemType: .ascii "FAT32 " # File System Type - 8 bytes
-BootSectorEntryPoint:
- #ASSUME ds:@code
- #ASSUME ss:@code
-
-# ****************************************************************************
-# Start Print
-# ****************************************************************************
- movw $StartString, %si
- call PrintString
-
-# ****************************************************************************
-# Print over
-# ****************************************************************************
-
- movw %cs, %ax # ax = 0
- movw %ax, %ss # ss = 0
- addw $0x1000, %ax
- movw %ax, %ds
-
- movw $0x7c00, %sp # sp = 0x7c00
- movw %sp, %bp # bp = 0x7c00
-
- movb $8, %ah # ah = 8 - Get Drive Parameters Function
- movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
- int $0x13 # Get Drive Parameters
- xorw %ax, %ax # ax = 0
- movb %dh, %al # al = dh
- incb %al # MaxHead = al + 1
- pushw %ax # 0000:7bfe = MaxHead
- movb %cl, %al # al = cl
- andb $0x3f, %al # MaxSector = al & 0x3f
- pushw %ax # 0000:7bfc = MaxSector
-
- cmpw $0xaa55, SectorSignature(%bp) # Verify Boot Sector Signature
- jne BadBootSector
- movw RootEntries(%bp), %cx # cx = RootEntries
- shlw $FAT_DIRECTORY_ENTRY_SHIFT, %cx # cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
- movw %cx, %bx # bx = size of the Root Directory in bytes
- andw $BLOCK_MASK, %bx # See if it is an even number of sectors long
- jne BadBootSector # If is isn't, then the boot sector is bad.
- movw %cx, %bx # bx = size of the Root Directory in bytes
- shrw $BLOCK_SHIFT, %bx # bx = size of Root Directory in sectors
- movb NoFats(%bp), %al # al = NoFats
- xorb %ah, %ah # ah = 0 ==> ax = NoFats
- mulw SectorsPerFat32(%bp) # ax = NoFats * SectorsPerFat
- addw ReservedSectors(%bp), %ax # ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
- addw %bx, %ax # ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA
- movw %ax, (%bp) # Save FirstClusterLBA for later use
-
- movw RootCluster(%bp), %ax # ax = StartCluster of Root Directory
- subw $2, %ax # ax = StartCluster - 2
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- pushw %ds
- popw %es
- xorw %di, %di # Store directory in es:di = 1000:0000
- call ReadBlocks # Read StartCluster of Root Directory
-
- # dx - variable storage (initial value is 0)
- # bx - loader (initial value is 0)
- xorw %dx, %dx
- xorw %bx, %bx
-
-FindEFILDR:
- cmpl $LOADER_FILENAME_PART1, (%di)
- jne FindVARSTORE
- cmpl $LOADER_FILENAME_PART2, 4(%di)
- jne FindVARSTORE
- cmpl $LOADER_FILENAME_PART3, 7(%di)
- jne FindVARSTORE
- movw 26(%di), %bx # bx = Start Cluster for EFILDR <----------------------------------
- testw %dx, %dx
- je FindNext # Efivar.bin is not loaded
- jmp FoundAll
-
-FindVARSTORE:
- ## if the file is not loader file, see if it's "EFIVAR BIN"
- cmpl $0x56494645, (%di) # Compare to "EFIV"
- jne FindNext
- cmpl $0x20205241, 4(%di) # Compare to "AR "
- jne FindNext
- cmpl $0x4e494220, 7(%di) # Compare to " BIN"
- jne FindNext
- movw %di, %dx # dx = Offset of Start Cluster for Efivar.bin <---------------------
- addw $26, %dx
- testw %bx, %bx
- je FindNext # Efildr is not loaded
- jmp FoundAll
-
-FindNext:
- # go to next find
- addw $FAT_DIRECTORY_ENTRY_SIZE, %di # Increment di
- subw $FAT_DIRECTORY_ENTRY_SIZE, %cx # Decrement cx
- # TODO: jump to FindVarStore if ...
- jne FindEFILDR
- jmp NotFoundAll
-
-FoundAll:
-FoundEFILDR:
- movw %bx, %cx # cx = Start Cluster for EFILDR <----------------------------------
- movw %cs, %ax # Destination = 2000:0000
- addw $0x2000, %ax
- movw %ax, %es
- xorw %di, %di
-ReadFirstClusterOfEFILDR:
- movw %cx, %ax # ax = StartCluster
- subw $2, %ax # ax = StartCluster - 2
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- pushw %dx
- mulw %bx
- popw %dx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = Number of Sectors in a cluster
- pushw %es
- call ReadBlocks
- popw %ax
-JumpIntoFirstSectorOfEFILDR:
- movw %ax, JumpSegment(%bp)
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x000
-JumpSegment:
- .word 0x2000
-
-
-PrintString:
- movw $0xb800, %ax
- movw %ax, %es
- movw $0x7c0, %ax
- movw %ax, %ds
- movw $6, %cx
- movw $160, %di
- rep
- movsw
- ret
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax, %esi # esi = Start LBA
- movw %bx, %cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc, %bp # bp = 0x7bfc
- movl %esi, %eax # eax = Start LBA
- xorl %edx, %edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
- subw %dx, %bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx, %bx # bx = Blocks
-LimitTransfer:
- pushw %cx
- movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx, %dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl, %dh # dh = Head
- movw $0x7c00, %bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al, %ch # ch = Cylinder
- movb %bl, %al # al = Blocks
- movb $2, %ah # ah = Function 2
- movw %di, %bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx, %ebx
- addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
- movw %es, %ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx, %ax
- movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0, %cx
- jne ReadCylinderLoop
- popa
- ret
-
-# ****************************************************************************
-# ERROR Condition:
-# ****************************************************************************
-NotFoundAll:
- ## if we found EFILDR, continue
- testw %bx, %bx
- jne FoundEFILDR
-BadBootSector:
-DiskError:
- movw $ErrorString, %si
- call PrintString
-Halt:
- jmp Halt
-
-StartString:
- .byte 'B', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c
-ErrorString:
- .byte 'B', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c
-
-# ****************************************************************************
-# LBA Offset for BootSector, need patched by tool for HD boot.
-# ****************************************************************************
-
- .org 0x01fa
-LBAOffsetForBootSector:
- .long 0x0
-
-# ****************************************************************************
-# Sector Signature
-# ****************************************************************************
-
- .org 0x01fe
-SectorSignature:
- .word 0xaa55 # Boot Sector Signature
-
-
-
diff --git a/DuetPkg/BootSector/bs32.asm b/DuetPkg/BootSector/bs32.asm deleted file mode 100644 index 7105ae6030..0000000000 --- a/DuetPkg/BootSector/bs32.asm +++ /dev/null @@ -1,310 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* bs32.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
- ; "EFILDR_____"
-LOADER_FILENAME_PART1 EQU 04c494645h ; "EFIL"
-LOADER_FILENAME_PART2 EQU 030325244h ; "DR20"
-LOADER_FILENAME_PART3 EQU 020202030h ; "0___"
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-; BPB data below will be fixed by tool
-SectorSize dw 0 ; Sector Size - 16 bits
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits
-NoFats db 0 ; Number of FATs - 8 bits
-RootEntries dw 0 ; Root Entries - 16 bits
-Sectors dw 0 ; Number of Sectors - 16 bits
-Media db 0 ; Media - 8 bits - ignored
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
-Heads dw 0 ; Heads - 16 bits - ignored
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
-LargeSectors dd 0 ; Large Sectors - 32 bits
-
-;******************************************************************************
-;
-;The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
-;the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
-;
-;******************************************************************************
-
-SectorsPerFat32 dd 0 ; Sectors Per FAT for FAT32 - 4 bytes
-ExtFlags dw 0 ; Mirror Flag - 2 bytes
-FSVersion dw 0 ; File System Version - 2 bytes
-RootCluster dd 0 ; 1st Cluster Number of Root Dir - 4 bytes
-FSInfo dw 0 ; Sector Number of FSINFO - 2 bytes
-BkBootSector dw 0 ; Sector Number of Bk BootSector - 2 bytes
-Reserved db 12 dup(0) ; Reserved Field - 12 bytes
-PhysicalDrive db 0 ; Physical Drive Number - 1 byte
-Reserved1 db 0 ; Reserved Field - 1 byte
-Signature db 0 ; Extended Boot Signature - 1 byte
-VolId db " " ; Volume Serial Number - 4 bytes
-FatLabel db " " ; Volume Label - 11 bytes
-FileSystemType db "FAT32 " ; File System Type - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
-
-; ****************************************************************************
-; Start Print
-; ****************************************************************************
- mov si, offset StartString
- call PrintString
-
-; ****************************************************************************
-; Print over
-; ****************************************************************************
-
- mov ax,cs ; ax = 0
- mov ss,ax ; ss = 0
- add ax,1000h
- mov ds,ax
-
- mov sp,07c00h ; sp = 0x7c00
- mov bp,sp ; bp = 0x7c00
-
- mov ah,8 ; ah = 8 - Get Drive Parameters Function
- mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
- int 13h ; Get Drive Parameters
- xor ax,ax ; ax = 0
- mov al,dh ; al = dh
- inc al ; MaxHead = al + 1
- push ax ; 0000:7bfe = MaxHead
- mov al,cl ; al = cl
- and al,03fh ; MaxSector = al & 0x3f
- push ax ; 0000:7bfc = MaxSector
-
- cmp word ptr [bp+SectorSignature],0aa55h ; Verify Boot Sector Signature
- jne BadBootSector
- mov cx,word ptr [bp+RootEntries] ; cx = RootEntries
- shl cx,FAT_DIRECTORY_ENTRY_SHIFT ; cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
- mov bx,cx ; bx = size of the Root Directory in bytes
- and bx,BLOCK_MASK ; See if it is an even number of sectors long
- jne BadBootSector ; If is isn't, then the boot sector is bad.
- mov bx,cx ; bx = size of the Root Directory in bytes
- shr bx,BLOCK_SHIFT ; bx = size of Root Directory in sectors
- mov al,byte ptr [bp+NoFats] ; al = NoFats
- xor ah,ah ; ah = 0 ==> ax = NoFats
- mul word ptr [bp+SectorsPerFat32] ; ax = NoFats * SectorsPerFat
- add ax,word ptr [bp+ReservedSectors] ; ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
- add ax,bx ; ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA
- mov word ptr [bp],ax ; Save FirstClusterLBA for later use
-
- mov ax,word ptr [bp+RootCluster] ; ax = StartCluster of Root Directory
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster]; bx = SectorsPerCluster
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- push ds
- pop es
- xor di,di ; Store directory in es:di = 1000:0000
- call ReadBlocks ; Read StartCluster of Root Directory
-
- ; dx - variable storage (initial value is 0)
- ; bx - loader (initial value is 0)
- xor dx, dx
- xor bx, bx
-
-FindEFILDR:
- cmp dword ptr [di],LOADER_FILENAME_PART1 ; Compare to "EFIL"
- jne FindVARSTORE
- cmp dword ptr [di+4],LOADER_FILENAME_PART2
- jne FindVARSTORE
- cmp dword ptr [di+7],LOADER_FILENAME_PART3
- jne FindVARSTORE
- mov bx, word ptr [di+26] ; bx = Start Cluster for EFILDR <----------------------------------
- test dx, dx
- je FindNext ; Efivar.bin is not loaded
- jmp FoundAll
-
-FindVARSTORE:
- ; if the file is not loader file, see if it's "EFIVAR BIN"
- cmp dword ptr [di], 056494645h ; Compare to "EFIV"
- jne FindNext
- cmp dword ptr [di+4], 020205241h ; Compare to "AR "
- jne FindNext
- cmp dword ptr [di+7], 04e494220h ; Compare to " BIN"
- jne FindNext
- mov dx, di ; dx = Offset of Start Cluster for Efivar.bin <---------------------
- add dx, 26
- test bx, bx
- je FindNext ; Efildr is not loaded
- jmp FoundAll
-
-FindNext:
- ; go to next find
- add di,FAT_DIRECTORY_ENTRY_SIZE ; Increment di
- sub cx,FAT_DIRECTORY_ENTRY_SIZE ; Decrement cx
- ; TODO: jump to FindVarStore if ...
- jne FindEFILDR
- jmp NotFoundAll
-
-FoundAll:
-FoundEFILDR:
- mov cx,bx ; cx = Start Cluster for EFILDR <----------------------------------
- mov ax,cs ; Destination = 2000:0000
- add ax,2000h
- mov es,ax
- xor di,di
-ReadFirstClusterOfEFILDR:
- mov ax,cx ; ax = StartCluster
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- push dx
- mul bx
- pop dx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = Number of Sectors in a cluster
- push es
- call ReadBlocks
- pop ax
-JumpIntoFirstSectorOfEFILDR:
- mov word ptr [bp+JumpSegment],ax
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0000h
-JumpSegment:
- dw 2000h
-
-
-PrintString:
- mov ax,0b800h
- mov es,ax
- mov ax, 07c0h
- mov ds, ax
- mov cx, 6
- mov di, 160
- rep movsw
- ret
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-; ****************************************************************************
-; ERROR Condition:
-; ****************************************************************************
-NotFoundAll:
- ; if we found EFILDR, continue
- test bx,bx
- jne FoundEFILDR
-BadBootSector:
-DiskError:
- mov si, offset ErrorString
- call PrintString
-Halt:
- jmp Halt
-
-StartString:
- db 'B', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch
-ErrorString:
- db 'B', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch
-
-; ****************************************************************************
-; LBA Offset for BootSector, need patched by tool for HD boot.
-; ****************************************************************************
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
-; ****************************************************************************
-; Sector Signature
-; ****************************************************************************
-
- org 01feh
-SectorSignature:
- dw 0aa55h ; Boot Sector Signature
-
- end
-
diff --git a/DuetPkg/BootSector/efi32.S b/DuetPkg/BootSector/efi32.S deleted file mode 100644 index ebbc450950..0000000000 --- a/DuetPkg/BootSector/efi32.S +++ /dev/null @@ -1,1176 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* efi32.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
-##############################################################################
-# Now in 32-bit protected mode.
-##############################################################################
-
- .org 0x21000
-
-.global _start
-_start:
-
-.equ DEFAULT_HANDLER_SIZE, INT1 - INT0
-
-.macro jmpCommonIdtEntry
- # jmp commonIdtEntry - this must be hand coded to keep the assembler from
- # using a 8 bit reletive jump when the entries are
- # within 255 bytes of the common entry. This must
- # be done to maintain the consistency of the size
- # of entry points...
- .byte 0xe9 # jmp 16 bit relative
- .long commonIdtEntry - . - 4 # offset to jump to
-.endm
-
-Start:
- movw %bx, %ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %fs
- movw %ax, %gs
- movw %ax, %ss
- movl $0x001ffff0, %esp
-
- call ClearScreen
-
- # Populate IDT with meaningful offsets for exception handlers...
- sidt Idtr
-
- movl Halt, %eax
- movl %eax, %ebx # use bx to copy 15..0 to descriptors
- shrl $16, %eax # use ax to copy 31..16 to descriptors
- movl $0x78, %ecx # 78h IDT entries to initialize with unique entry points (exceptions)
- movl (Idtr + 2), %esi
- movl (%esi), %edi
-
-LOOP_1: # loop through all IDT entries exception handlers and initialize to default handler
- movw %bx, (%edi) # write bits 15..0 of offset
- movw $0x20, 2(%edi) # SYS_CODE_SEL from GDT
- movw $(0x0e00 | 0x8000), 4(%edi) # type = 386 interrupt gate, present
- movw %ax, 6(%edi) # write bits 31..16 of offset
- addl $8, %edi # move up to next descriptor
- addw DEFAULT_HANDLER_SIZE, %bx # move to next entry point
- loopl LOOP_1 # loop back through again until all descriptors are initialized
-
- ## at this point edi contains the offset of the descriptor for INT 20
- ## and bx contains the low 16 bits of the offset of the default handler
- ## so initialize all the rest of the descriptors with these two values...
-# mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
-#@@: ; loop through all IDT entries exception handlers and initialize to default handler
-# mov word ptr [edi], bx ; write bits 15..0 of offset
-# mov word ptr [edi+2], 20h ; SYS_CODE_SEL from GDT
-# mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
-# mov word ptr [edi+6], ax ; write bits 31..16 of offset
-# add edi, 8 ; move up to next descriptor
-# loop @b ; loop back through again until all descriptors are initialized
-
-
-## DUMP location of IDT and several of the descriptors
-# mov ecx, 8
-# mov eax, [offset Idtr + 2]
-# mov eax, [eax]
-# mov edi, 0b8000h
-# call PrintDword
-# mov esi, eax
-# mov edi, 0b80a0h
-# jmp OuterLoop
-
-##
-## just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
-# mov eax, 011111111h
-# mov ebx, 022222222h
-# mov ecx, 033333333h
-# mov edx, 044444444h
-# mov ebp, 055555555h
-# mov esi, 066666666h
-# mov edi, 077777777h
-# push 011111111h
-# push 022222222h
-# push 033333333h
-# int 119
-
-
- movl $0x22000, %esi # esi = 22000
- movl 0x14(%esi), %eax # eax = [22014]
- addl %eax, %esi # esi = 22000 + [22014] = Base of EFILDR.C
- movl 0x3c(%esi), %ebp # ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
- addl %esi, %ebp
- movl 0x34(%ebp), %edi # edi = [[22000 + [22014] + 3c] + 30] = ImageBase
- movl 0x28(%ebp), %eax # eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
- addl %edi, %eax # eax = ImageBase + EntryPoint
- movl %eax, EfiLdrOffset # Modify far jump instruction for correct entry point
-
- movw 6(%ebp), %bx # bx = Number of sections
- xorl %eax, %eax
- movw 0x14(%ebp), %ax # ax = Optional Header Size
- addl %eax, %ebp
- addl $0x18, %ebp # ebp = Start of 1st Section
-
-SectionLoop:
- pushl %esi # Save Base of EFILDR.C
- pushl %edi # Save ImageBase
- addl 0x14(%ebp), %esi # esi = Base of EFILDR.C + PointerToRawData
- addl 0x0c(%ebp), %edi # edi = ImageBase + VirtualAddress
- movl 0x10(%ebp), %ecx # ecs = SizeOfRawData
-
- cld
- shrl $2, %ecx
- rep
- movsl
-
- popl %edi # Restore ImageBase
- popl %esi # Restore Base of EFILDR.C
-
- addw $0x28, %bp # ebp = ebp + 028h = Pointer to next section record
- decw %bx
- cmpw $0, %bx
- jne SectionLoop
-
- movzwl (Idtr), %eax # get size of IDT
- incl %eax
- addl (Idtr + 2), %eax # add to base of IDT to get location of memory map...
- pushl %eax # push memory map location on stack for call to EFILDR...
-
- pushl %eax # push return address (useless, just for stack balance)
- .byte 0xb8
-EfiLdrOffset:
- .long 0x00401000 # Offset of EFILDR
-# mov eax, 401000h
- pushl %eax
- ret
-
-# db "**** DEFAULT IDT ENTRY ***",0
- .p2align 1
-Halt:
-INT0:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x0
- jmpCommonIdtEntry
-# db 0e9h ; jmp 16 bit reletive
-# dd commonIdtEntry - $ - 4 ; offset to jump to
-
-INT1:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x1
- jmpCommonIdtEntry
-
-INT2:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x2
- jmpCommonIdtEntry
-
-INT3:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x3
- jmpCommonIdtEntry
-
-INT4:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x4
- jmpCommonIdtEntry
-
-INT5:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x5
- jmpCommonIdtEntry
-
-INT6:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x6
- jmpCommonIdtEntry
-
-INT7:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x7
- jmpCommonIdtEntry
-
-INT8:
-# Double fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $0x8
- jmpCommonIdtEntry
-
-INT9:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x9
- jmpCommonIdtEntry
-
-INT10:
-# Invalid TSS causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $10
- jmpCommonIdtEntry
-
-INT11:
-# Segment Not Present causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $11
- jmpCommonIdtEntry
-
-INT12:
-# Stack fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $12
- jmpCommonIdtEntry
-
-INT13:
-# GP fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $13
- jmpCommonIdtEntry
-
-INT14:
-# Page fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $14
- jmpCommonIdtEntry
-
-INT15:
- pushl $0x0 # push error code place holder on the stack
- pushl $15
- jmpCommonIdtEntry
-
-INT16:
- pushl $0x0 # push error code place holder on the stack
- pushl $16
- jmpCommonIdtEntry
-
-INT17:
-# Alignment check causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $17
- jmpCommonIdtEntry
-
-INT18:
- pushl $0x0 # push error code place holder on the stack
- pushl $18
- jmpCommonIdtEntry
-
-INT19:
- pushl $0x0 # push error code place holder on the stack
- pushl $19
- jmpCommonIdtEntry
-
-INTUnknown:
-# The following segment repeats (0x78 - 20) times:
-# No. 1
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 2
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 3
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 4
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 5
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 6
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 7
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 8
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 9
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 10
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 11
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 12
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 13
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 14
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 15
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 16
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 17
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 18
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 19
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 20
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 21
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 22
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 23
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 24
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 25
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 26
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 27
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 28
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 29
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 30
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 31
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 32
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 33
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 34
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 35
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 36
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 37
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 38
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 39
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 40
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 41
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 42
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 43
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 44
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 45
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 46
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 47
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 48
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 49
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 50
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 51
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 52
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 53
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 54
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 55
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 56
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 57
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 58
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 59
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 60
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 61
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 62
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 63
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 64
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 65
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 66
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 67
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 68
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 69
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 70
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 71
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 72
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 73
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 74
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 75
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 76
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 77
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 78
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 79
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 80
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 81
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 82
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 83
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 84
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 85
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 86
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 87
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 88
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 89
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 90
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 91
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 92
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 93
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 94
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 95
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 96
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 97
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 98
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 99
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 100
- pushl $0x0 # push error code place holder on the stack
-# push $0xxx # push vector number
- .byte 0x6a
- .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-
-
-commonIdtEntry:
- pushal
- movl %esp, %ebp
-##
-## At this point the stack looks like this:
-##
-## eflags
-## Calling CS
-## Calling EIP
-## Error code or 0
-## Int num or 0ffh for unknown int num
-## eax
-## ecx
-## edx
-## ebx
-## esp
-## ebp
-## esi
-## edi <------- ESP, EBP
-##
-
- call ClearScreen
- movl String1, %esi
- call PrintString
- movl 32(%ebp), %eax ## move Int number into EAX
- cmpl $19, %eax
- ja PrintDefaultString
-PrintExceptionString:
- shll $2, %eax ## multiply by 4 to get offset from StringTable to actual string address
- addl StringTable, %eax
- movl (%eax), %esi
- jmp PrintTheString
-PrintDefaultString:
- movl IntUnknownString, %esi
- # patch Int number
- movl %eax, %edx
- call A2C
- movb %al, 1(%esi)
- movl %edx, %eax
- shrl $4, %eax
- call A2C
- movb %al, (%esi)
-PrintTheString:
- call PrintString
- movl String2, %esi
- call PrintString
- movl 44(%ebp), %eax # CS
- call PrintDword
- movb ':', %al
- movb %al, (%edi)
- addl $2, %edi
- movl 40(%ebp), %eax # EIP
- call PrintDword
- movl String3, %esi
- call PrintString
-
- movl $0xb8140, %edi
-
- movl StringEax, %esi # eax
- call PrintString
- movl 28(%ebp), %eax
- call PrintDword
-
- movl StringEbx, %esi # ebx
- call PrintString
- movl 16(%ebp), %eax
- call PrintDword
-
- movl StringEcx, %esi # ecx
- call PrintString
- movl 24(%ebp), %eax
- call PrintDword
-
- movl StringEdx, %esi # edx
- call PrintString
- movl 20(%ebp), %eax
- call PrintDword
-
- movl StringEcode, %esi # error code
- call PrintString
- movl 36(%ebp), %eax
- call PrintDword
-
- movl $0xb81e0, %edi
-
- movl StringEsp, %esi # esp
- call PrintString
- movl 12(%ebp), %eax
- call PrintDword
-
- movl StringEbp, %esi # ebp
- call PrintString
- movl 8(%ebp), %eax
- call PrintDword
-
- movl StringEsi, %esi # esi
- call PrintString
- movl 4(%ebp), %eax
- call PrintDword
-
- movl StringEdi, %esi # edi
- call PrintString
- movl (%ebp), %eax
- call PrintDword
-
- movl StringEflags, %esi # eflags
- call PrintString
- movl 48(%ebp), %eax
- call PrintDword
-
- movl $0xb8320, %edi
-
- movl %ebp, %esi
- addl $52, %esi
- movl $8, %ecx
-
-
-OuterLoop:
- pushl %ecx
- movl $8, %ecx
- movl %edi, %edx
-
-InnerLoop:
- movl (%esi), %eax
- call PrintDword
- addl $4, %esi
- movb ' ', %al
- movb %al, (%edi)
- addl $2, %edi
- loop InnerLoop
-
- popl %ecx
- addl $0xa0, %edx
- movl %edx, %edi
- loop OuterLoop
-
-
- movl $0xb8960, %edi
-
- movl 40(%ebp), %eax # EIP
- subl $32*4, %eax
- movl %eax, %esi # esi = eip - 32 DWORD linear (total 64 DWORD)
-
- movl $8, %ecx
-
-OuterLoop1:
- pushl %ecx
- movl $8, %ecx
- movl %edi, %edx
-
-InnerLoop1:
- movl (%esi), %eax
- call PrintDword
- addl $4, %esi
- movb ' ', %al
- movb %al, (%edi)
- addl $2, %edi
- loop InnerLoop1
-
- popl %ecx
- addl $0xa0, %edx
- movl %edx, %edi
- loop OuterLoop1
-
-
-
-# wbinvd ; this intruction does not support in early than 486 arch
-LN_C1:
- jmp LN_C1
-#
-# return
-#
- movl %ebp, %esp
- popal
- addl $8, %esp # error code and INT number
-
- iretl
-
-
-PrintString:
- pushl %eax
-LN_C2:
- movb (%esi), %al
- cmpb $0, %al
- je LN_C3
- movb %al, (%edi)
- incl %esi
- addl $2, %edi
- jmp LN_C2
-LN_C3:
- popl %eax
- ret
-
-## EAX contains dword to print
-## EDI contains memory location (screen location) to print it to
-PrintDword:
- pushl %ecx
- pushl %ebx
- pushl %eax
-
- movl $8, %ecx
-looptop:
- roll $4, %eax
- movb %al, %bl
- andb $0xf, %bl
- addb '0', %bl
- cmpb '9', %bl
- jle LN_C4
- addb $7, %bl
-LN_C4:
- movb %bl, (%edi)
- addl $2, %edi
- loop looptop
- #wbinvd
-
- popl %eax
- popl %ebx
- popl %ecx
- ret
-
-ClearScreen:
- pushl %eax
- pushl %ecx
-
- movb $0x00, %al
- movb $0xc, %ah
- movl $0xb8000, %edi
- movl $80*24, %ecx
-LN_C5:
- movw %ax, (%edi)
- addl $2, %edi
- loop LN_C5
- movl $0xb8000, %edi
-
- popl %ecx
- popl %eax
-
- ret
-
-A2C:
- andb $0xf, %al
- addb '0', %al
- cmpb '9', %al
- jle LN_C6
- addb $7, %al
-LN_C6:
- ret
-
-String1: .asciz "*** INT "
-
-Int0String: .asciz "00h Divide by 0 -"
-Int1String: .asciz "01h Debug exception -"
-Int2String: .asciz "02h NMI -"
-Int3String: .asciz "03h Breakpoint -"
-Int4String: .asciz "04h Overflow -"
-Int5String: .asciz "05h Bound -"
-Int6String: .asciz "06h Invalid opcode -"
-Int7String: .asciz "07h Device not available -"
-Int8String: .asciz "08h Double fault -"
-Int9String: .asciz "09h Coprocessor seg overrun (reserved) -"
-Int10String: .asciz "0Ah Invalid TSS -"
-Int11String: .asciz "0Bh Segment not present -"
-Int12String: .asciz "0Ch Stack fault -"
-Int13String: .asciz "0Dh General protection fault -"
-Int14String: .asciz "0Eh Page fault -"
-Int15String: .asciz "0Fh (Intel reserved) -"
-Int16String: .asciz "10h Floating point error -"
-Int17String: .asciz "11h Alignment check -"
-Int18String: .asciz "12h Machine check -"
-Int19String: .asciz "13h SIMD Floating-Point Exception -"
-IntUnknownString: .asciz "??h Unknown interrupt -"
-
-StringTable: .long Int0String, Int1String, Int2String, Int3String, \
- Int4String, Int5String, Int6String, Int7String, \
- Int8String, Int9String, Int10String, Int11String, \
- Int12String, Int13String, Int14String, Int15String,\
- Int16String, Int17String, Int18String, Int19String
-
-String2: .asciz " HALT!! *** ("
-String3: .asciz ")"
-StringEax: .asciz "EAX="
-StringEbx: .asciz "EBX="
-StringEcx: .asciz "ECX="
-StringEdx: .asciz "EDX="
-StringEcode: .asciz "ECODE="
-StringEsp: .asciz "ESP="
-StringEbp: .asciz "EBP="
-StringEsi: .asciz "ESI="
-StringEdi: .asciz "EDI="
-StringEflags: .asciz "EFLAGS="
-
-Idtr: .float 0
-
- .org 0x21ffe
-BlockSignature:
- .word 0xaa55
-
-
diff --git a/DuetPkg/BootSector/efi32.asm b/DuetPkg/BootSector/efi32.asm deleted file mode 100644 index 7ccf86f0eb..0000000000 --- a/DuetPkg/BootSector/efi32.asm +++ /dev/null @@ -1,582 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* efi32.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; Now in 32-bit protected mode.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- .486
- .model flat
- .stack
- .code
- org 21000h
-
-DEFAULT_HANDLER_SIZE EQU INT1 - INT0
-
-JmpCommonIdtEntry macro
- ; jmp commonIdtEntry - this must be hand coded to keep the assembler from
- ; using a 8 bit reletive jump when the entries are
- ; within 255 bytes of the common entry. This must
- ; be done to maintain the consistency of the size
- ; of entry points...
- db 0e9h ; jmp 16 bit relative
- dd commonIdtEntry - $ - 4 ; offset to jump to
-endm
-
-
-Start:
- mov ax,bx ; flat data descriptor in BX
- mov ds,ax
- mov es,ax
- mov fs,ax
- mov gs,ax
- mov ss,ax
- mov esp,0001ffff0h
-
- call ClearScreen
-
- ; Populate IDT with meaningful offsets for exception handlers...
- sidt fword ptr [Idtr] ; get fword address of IDT
-
- mov eax, offset Halt
- mov ebx, eax ; use bx to copy 15..0 to descriptors
- shr eax, 16 ; use ax to copy 31..16 to descriptors
- mov ecx, 78h ; 78h IDT entries to initialize with unique entry points (exceptions)
- mov esi, [offset Idtr + 2]
- mov edi, [esi]
-
-@@: ; loop through all IDT entries exception handlers and initialize to default handler
- mov word ptr [edi], bx ; write bits 15..0 of offset
- mov word ptr [edi+2], 20h ; SYS_CODE_SEL from GDT
- mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
- mov word ptr [edi+6], ax ; write bits 31..16 of offset
- add edi, 8 ; move up to next descriptor
- add bx, DEFAULT_HANDLER_SIZE ; move to next entry point
- loop @b ; loop back through again until all descriptors are initialized
-
- ;; at this point edi contains the offset of the descriptor for INT 20
- ;; and bx contains the low 16 bits of the offset of the default handler
- ;; so initialize all the rest of the descriptors with these two values...
-; mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
-;@@: ; loop through all IDT entries exception handlers and initialize to default handler
-; mov word ptr [edi], bx ; write bits 15..0 of offset
-; mov word ptr [edi+2], 20h ; SYS_CODE_SEL from GDT
-; mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
-; mov word ptr [edi+6], ax ; write bits 31..16 of offset
-; add edi, 8 ; move up to next descriptor
-; loop @b ; loop back through again until all descriptors are initialized
-
-
-;; DUMP location of IDT and several of the descriptors
-; mov ecx, 8
-; mov eax, [offset Idtr + 2]
-; mov eax, [eax]
-; mov edi, 0b8000h
-; call PrintDword
-; mov esi, eax
-; mov edi, 0b80a0h
-; jmp OuterLoop
-
-;;
-;; just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
-; mov eax, 011111111h
-; mov ebx, 022222222h
-; mov ecx, 033333333h
-; mov edx, 044444444h
-; mov ebp, 055555555h
-; mov esi, 066666666h
-; mov edi, 077777777h
-; push 011111111h
-; push 022222222h
-; push 033333333h
-; int 119
-
-
- mov esi,022000h ; esi = 22000
- mov eax,[esi+014h] ; eax = [22014]
- add esi,eax ; esi = 22000 + [22014] = Base of EFILDR.C
- mov ebp,[esi+03ch] ; ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
- add ebp,esi
- mov edi,[ebp+034h] ; edi = [[22000 + [22014] + 3c] + 30] = ImageBase
- mov eax,[ebp+028h] ; eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
- add eax,edi ; eax = ImageBase + EntryPoint
- mov dword ptr [EfiLdrOffset],eax ; Modify far jump instruction for correct entry point
-
- mov bx,word ptr[ebp+6] ; bx = Number of sections
- xor eax,eax
- mov ax,word ptr[ebp+014h] ; ax = Optional Header Size
- add ebp,eax
- add ebp,018h ; ebp = Start of 1st Section
-
-SectionLoop:
- push esi ; Save Base of EFILDR.C
- push edi ; Save ImageBase
- add esi,[ebp+014h] ; esi = Base of EFILDR.C + PointerToRawData
- add edi,[ebp+00ch] ; edi = ImageBase + VirtualAddress
- mov ecx,[ebp+010h] ; ecs = SizeOfRawData
-
- cld
- shr ecx,2
- rep movsd
-
- pop edi ; Restore ImageBase
- pop esi ; Restore Base of EFILDR.C
-
- add bp,028h ; ebp = ebp + 028h = Pointer to next section record
- dec bx
- cmp bx,0
- jne SectionLoop
-
- movzx eax, word ptr [Idtr] ; get size of IDT
- inc eax
- add eax, dword ptr [Idtr + 2] ; add to base of IDT to get location of memory map...
- push eax ; push memory map location on stack for call to EFILDR...
-
- push eax ; push return address (useless, just for stack balance)
- db 0b8h
-EfiLdrOffset:
- dd 000401000h ; Offset of EFILDR
-; mov eax, 401000h
- push eax
- ret
-
-; db "**** DEFAULT IDT ENTRY ***",0
- align 02h
-Halt:
-INT0:
- push 0h ; push error code place holder on the stack
- push 0h
- JmpCommonIdtEntry
-; db 0e9h ; jmp 16 bit reletive
-; dd commonIdtEntry - $ - 4 ; offset to jump to
-
-INT1:
- push 0h ; push error code place holder on the stack
- push 1h
- JmpCommonIdtEntry
-
-INT2:
- push 0h ; push error code place holder on the stack
- push 2h
- JmpCommonIdtEntry
-
-INT3:
- push 0h ; push error code place holder on the stack
- push 3h
- JmpCommonIdtEntry
-
-INT4:
- push 0h ; push error code place holder on the stack
- push 4h
- JmpCommonIdtEntry
-
-INT5:
- push 0h ; push error code place holder on the stack
- push 5h
- JmpCommonIdtEntry
-
-INT6:
- push 0h ; push error code place holder on the stack
- push 6h
- JmpCommonIdtEntry
-
-INT7:
- push 0h ; push error code place holder on the stack
- push 7h
- JmpCommonIdtEntry
-
-INT8:
-; Double fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 8h
- JmpCommonIdtEntry
-
-INT9:
- push 0h ; push error code place holder on the stack
- push 9h
- JmpCommonIdtEntry
-
-INT10:
-; Invalid TSS causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 10
- JmpCommonIdtEntry
-
-INT11:
-; Segment Not Present causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 11
- JmpCommonIdtEntry
-
-INT12:
-; Stack fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 12
- JmpCommonIdtEntry
-
-INT13:
-; GP fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 13
- JmpCommonIdtEntry
-
-INT14:
-; Page fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 14
- JmpCommonIdtEntry
-
-INT15:
- push 0h ; push error code place holder on the stack
- push 15
- JmpCommonIdtEntry
-
-INT16:
- push 0h ; push error code place holder on the stack
- push 16
- JmpCommonIdtEntry
-
-INT17:
-; Alignment check causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 17
- JmpCommonIdtEntry
-
-INT18:
- push 0h ; push error code place holder on the stack
- push 18
- JmpCommonIdtEntry
-
-INT19:
- push 0h ; push error code place holder on the stack
- push 19
- JmpCommonIdtEntry
-
-INTUnknown:
-REPEAT (78h - 20)
- push 0h ; push error code place holder on the stack
-; push xxh ; push vector number
- db 06ah
- db ( $ - INTUnknown - 3 ) / 9 + 20 ; vector number
- JmpCommonIdtEntry
-ENDM
-
-commonIdtEntry:
- pushad
- mov ebp, esp
-;;
-;; At this point the stack looks like this:
-;;
-;; eflags
-;; Calling CS
-;; Calling EIP
-;; Error code or 0
-;; Int num or 0ffh for unknown int num
-;; eax
-;; ecx
-;; edx
-;; ebx
-;; esp
-;; ebp
-;; esi
-;; edi <------- ESP, EBP
-;;
-
- call ClearScreen
- mov esi, offset String1
- call PrintString
- mov eax, [ebp + 32] ;; move Int number into EAX
- cmp eax, 19
- ja PrintDefaultString
-PrintExceptionString:
- shl eax, 2 ;; multiply by 4 to get offset from StringTable to actual string address
- add eax, offset StringTable
- mov esi, [eax]
- jmp PrintTheString
-PrintDefaultString:
- mov esi, offset IntUnknownString
- ; patch Int number
- mov edx, eax
- call A2C
- mov [esi + 1], al
- mov eax, edx
- shr eax, 4
- call A2C
- mov [esi], al
-PrintTheString:
- call PrintString
- mov esi, offset String2
- call PrintString
- mov eax, [ebp+44] ; CS
- call PrintDword
- mov al, ':'
- mov byte ptr [edi], al
- add edi, 2
- mov eax, [ebp+40] ; EIP
- call PrintDword
- mov esi, offset String3
- call PrintString
-
- mov edi, 0b8140h
-
- mov esi, offset StringEax ; eax
- call PrintString
- mov eax, [ebp+28]
- call PrintDword
-
- mov esi, offset StringEbx ; ebx
- call PrintString
- mov eax, [ebp+16]
- call PrintDword
-
- mov esi, offset StringEcx ; ecx
- call PrintString
- mov eax, [ebp+24]
- call PrintDword
-
- mov esi, offset StringEdx ; edx
- call PrintString
- mov eax, [ebp+20]
- call PrintDword
-
- mov esi, offset StringEcode ; error code
- call PrintString
- mov eax, [ebp+36]
- call PrintDword
-
- mov edi, 0b81e0h
-
- mov esi, offset StringEsp ; esp
- call PrintString
- mov eax, [ebp+12]
- call PrintDword
-
- mov esi, offset StringEbp ; ebp
- call PrintString
- mov eax, [ebp+8]
- call PrintDword
-
- mov esi, offset StringEsi ; esi
- call PrintString
- mov eax, [ebp+4]
- call PrintDword
-
- mov esi, offset StringEdi ; edi
- call PrintString
- mov eax, [ebp]
- call PrintDword
-
- mov esi, offset StringEflags ; eflags
- call PrintString
- mov eax, [ebp+48]
- call PrintDword
-
- mov edi, 0b8320h
-
- mov esi, ebp
- add esi, 52
- mov ecx, 8
-
-
-OuterLoop:
- push ecx
- mov ecx, 8
- mov edx, edi
-
-InnerLoop:
- mov eax, [esi]
- call PrintDword
- add esi, 4
- mov al, ' '
- mov [edi], al
- add edi, 2
- loop InnerLoop
-
- pop ecx
- add edx, 0a0h
- mov edi, edx
- loop OuterLoop
-
-
- mov edi, 0b8960h
-
- mov eax, [ebp+40] ; EIP
- sub eax, 32 * 4
- mov esi, eax ; esi = eip - 32 DWORD linear (total 64 DWORD)
-
- mov ecx, 8
-
-OuterLoop1:
- push ecx
- mov ecx, 8
- mov edx, edi
-
-InnerLoop1:
- mov eax, [esi]
- call PrintDword
- add esi, 4
- mov al, ' '
- mov [edi], al
- add edi, 2
- loop InnerLoop1
-
- pop ecx
- add edx, 0a0h
- mov edi, edx
- loop OuterLoop1
-
-
-
-; wbinvd ; Ken: this intruction does not support in early than 486 arch
-@@:
- jmp @b
-;
-; return
-;
- mov esp, ebp
- popad
- add esp, 8 ; error code and INT number
-
- iretd
-
-
-PrintString:
- push eax
-@@:
- mov al, byte ptr [esi]
- cmp al, 0
- je @f
- mov byte ptr [edi], al
- inc esi
- add edi, 2
- jmp @b
-@@:
- pop eax
- ret
-
-;; EAX contains dword to print
-;; EDI contains memory location (screen location) to print it to
-PrintDword:
- push ecx
- push ebx
- push eax
-
- mov ecx, 8
-looptop:
- rol eax, 4
- mov bl, al
- and bl, 0fh
- add bl, '0'
- cmp bl, '9'
- jle @f
- add bl, 7
-@@:
- mov byte ptr [edi], bl
- add edi, 2
- loop looptop
- ;wbinvd
-
- pop eax
- pop ebx
- pop ecx
- ret
-
-ClearScreen:
- push eax
- push ecx
-
- mov al, ' '
- mov ah, 0ch
- mov edi, 0b8000h
- mov ecx, 80 * 24
-@@:
- mov word ptr [edi], ax
- add edi, 2
- loop @b
- mov edi, 0b8000h
-
- pop ecx
- pop eax
-
- ret
-
-A2C:
- and al, 0fh
- add al, '0'
- cmp al, '9'
- jle @f
- add al, 7
-@@:
- ret
-
-String1 db "*** INT ",0
-
-Int0String db "00h Divide by 0 -",0
-Int1String db "01h Debug exception -",0
-Int2String db "02h NMI -",0
-Int3String db "03h Breakpoint -",0
-Int4String db "04h Overflow -",0
-Int5String db "05h Bound -",0
-Int6String db "06h Invalid opcode -",0
-Int7String db "07h Device not available -",0
-Int8String db "08h Double fault -",0
-Int9String db "09h Coprocessor seg overrun (reserved) -",0
-Int10String db "0Ah Invalid TSS -",0
-Int11String db "0Bh Segment not present -",0
-Int12String db "0Ch Stack fault -",0
-Int13String db "0Dh General protection fault -",0
-Int14String db "0Eh Page fault -",0
-Int15String db "0Fh (Intel reserved) -",0
-Int16String db "10h Floating point error -",0
-Int17String db "11h Alignment check -",0
-Int18String db "12h Machine check -",0
-Int19String db "13h SIMD Floating-Point Exception -",0
-IntUnknownString db "??h Unknown interrupt -",0
-
-StringTable dd offset Int0String, offset Int1String, offset Int2String, offset Int3String,
- offset Int4String, offset Int5String, offset Int6String, offset Int7String,
- offset Int8String, offset Int9String, offset Int10String, offset Int11String,
- offset Int12String, offset Int13String, offset Int14String, offset Int15String,
- offset Int16String, offset Int17String, offset Int18String, offset Int19String
-
-String2 db " HALT!! *** (",0
-String3 db ")",0
-StringEax db "EAX=",0
-StringEbx db " EBX=",0
-StringEcx db " ECX=",0
-StringEdx db " EDX=",0
-StringEcode db " ECODE=",0
-StringEsp db "ESP=",0
-StringEbp db " EBP=",0
-StringEsi db " ESI=",0
-StringEdi db " EDI=",0
-StringEflags db " EFLAGS=",0
-
-Idtr df 0
-
- org 21ffeh
-BlockSignature:
- dw 0aa55h
-
- end
diff --git a/DuetPkg/BootSector/efi64.S b/DuetPkg/BootSector/efi64.S deleted file mode 100644 index 34bd7521b9..0000000000 --- a/DuetPkg/BootSector/efi64.S +++ /dev/null @@ -1,1385 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* efi64.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
-##############################################################################
-# Now in 64-bit long mode.
-##############################################################################
-
- .486:
- .stack:
- .code:
- .org 0x21000
-
-.global _start
-_start:
-
-.equ DEFAULT_HANDLER_SIZE, INT1 - INT0
-
-.macro jmpCommonIdtEntry
- # jmp commonIdtEntry - this must be hand coded to keep the assembler from
- # using a 8 bit reletive jump when the entries are
- # within 255 bytes of the common entry. This must
- # be done to maintain the consistency of the size
- # of entry points...
- .byte 0xe9 # jmp 16 bit relative
- .long commonIdtEntry - . - 4 # offset to jump to
-.endm
-
-
-Start:
-
- movl $0x001fffe8,%esp # make final stack aligned
-
- # set OSFXSR and OSXMMEXCPT because some code will use XMM register
- .byte 0xf
- .byte 0x20
- .byte 0xe0
-# mov rax, cr4
- btsl $9,%eax
- btsl $0xa,%eax
- .byte 0xf
- .byte 0x22
- .byte 0xe0
-# mov cr4, rax
-
- call ClearScreen
-
- # Populate IDT with meaningful offsets for exception handlers...
- movl $Idtr, %eax
- sidt (%eax) # get fword address of IDT
-
-
- movl $Halt, %eax
- movl %eax,%ebx # use bx to copy 15..0 to descriptors
- shrl $16,%eax # use ax to copy 31..16 to descriptors
- # 63..32 of descriptors is 0
- movl $0x78,%ecx # 78h IDT entries to initialize with unique entry points (exceptions)
- movl $(Idtr + 2), %esi
- movl (%esi),%edi
-
-LOOP_1: # loop through all IDT entries exception handlers and initialize to default handler
- movw %bx, (%edi) # write bits 15..0 of offset
- movw $0x38, 2(%edi) # SYS_CODE_SEL64 from GDT
- movw $(0x0e00 | 0x8000), 4(%edi) # type = 386 interrupt gate, present
- movw %ax, 6(%edi) # write bits 31..16 of offset
- movl $0, 8(%edi) # write bits 31..16 of offset
- addl $16, %edi # move up to next descriptor
- addw $DEFAULT_HANDLER_SIZE, %bx # move to next entry point
- loopl LOOP_1 # loop back through again until all descriptors are initialized
-
- ## at this point edi contains the offset of the descriptor for INT 20
- ## and bx contains the low 16 bits of the offset of the default handler
- ## so initialize all the rest of the descriptors with these two values...
-# mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
-#@@: ; loop through all IDT entries exception handlers and initialize to default handler
-# mov word ptr [edi], bx ; write bits 15..0 of offset
-# mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT
-# mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
-# mov word ptr [edi+6], ax ; write bits 31..16 of offset
-# mov dword ptr [edi+8], 0 ; write bits 63..32 of offset
-# add edi, 16 ; move up to next descriptor
-# loop @b ; loop back through again until all descriptors are initialized
-
-
-## DUMP location of IDT and several of the descriptors
-# mov ecx, 8
-# mov eax, [offset Idtr + 2]
-# mov eax, [eax]
-# mov edi, 0b8000h
-# call PrintQword
-# mov esi, eax
-# mov edi, 0b80a0h
-# jmp OuterLoop
-
-##
-## just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
-# mov eax, 011111111h
-# mov ebx, 022222222h
-# mov ecx, 033333333h
-# mov edx, 044444444h
-# mov ebp, 055555555h
-# mov esi, 066666666h
-# mov edi, 077777777h
-# push 011111111h
-# push 022222222h
-# push 033333333h
-# int 119
-
- movl $0x22000,%esi # esi = 22000
- movl 0x14(%esi),%eax # eax = [22014]
- addl %eax,%esi # esi = 22000 + [22014] = Base of EFILDR.C
- movl 0x3c(%esi),%ebp # ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
- addl %esi,%ebp
- movl 0x30(%ebp),%edi # edi = [[22000 + [22014] + 3c] + 2c] = ImageBase (63..32 is zero, ignore)
- movl 0x28(%ebp),%eax # eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
- addl %edi,%eax # eax = ImageBase + EntryPoint
- movl $EfiLdrOffset, %ebx
- movl %eax, (%ebx) # Modify far jump instruction for correct entry point
-
- movw 6(%ebp), %bx # bx = Number of sections
- xorl %eax,%eax
- movw 0x14(%ebp), %ax # ax = Optional Header Size
- addl %eax,%ebp
- addl $0x18,%ebp # ebp = Start of 1st Section
-
-SectionLoop:
- pushl %esi # Save Base of EFILDR.C
- pushl %edi # Save ImageBase
- addl 0x14(%ebp),%esi # esi = Base of EFILDR.C + PointerToRawData
- addl 0x0c(%ebp),%edi # edi = ImageBase + VirtualAddress
- movl 0x10(%ebp),%ecx # ecs = SizeOfRawData
-
- cld
- shrl $2,%ecx
- rep
- movsl
-
- popl %edi # Restore ImageBase
- popl %esi # Restore Base of EFILDR.C
-
- addw $0x28,%bp # ebp = ebp + 028h = Pointer to next section record
- .byte 0x66
- .byte 0xff
- .byte 0xcb
-# dec bx
- cmpw $0,%bx
- jne SectionLoop
-
- movl $Idtr, %edx # get size of IDT
- movzxw (%edx), %eax
- .byte 0xff
- .byte 0xc0
-# inc eax
- addl 2(%edx), %eax # add to base of IDT to get location of memory map...
- xorl %ecx,%ecx
- movl %eax,%ecx # put argument to RCX
-
- .byte 0x48
- .byte 0xc7
- .byte 0xc0
-EfiLdrOffset:
- .long 0x00401000 # Offset of EFILDR
-# mov rax, 401000h
- .byte 0x50
-# push rax
-
-# ret
- .byte 0xc3
-
-# db "**** DEFAULT IDT ENTRY ***",0
- .p2align 1
-Halt:
-INT0:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x0
- jmpCommonIdtEntry
-# db 0e9h ; jmp 16 bit reletive
-# dd commonIdtEntry - $ - 4 ; offset to jump to
-
-INT1:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x1
- jmpCommonIdtEntry
-
-INT2:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x2
- jmpCommonIdtEntry
-
-INT3:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x3
- jmpCommonIdtEntry
-
-INT4:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x4
- jmpCommonIdtEntry
-
-INT5:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x5
- jmpCommonIdtEntry
-
-INT6:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x6
- jmpCommonIdtEntry
-
-INT7:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x7
- jmpCommonIdtEntry
-
-INT8:
-# Double fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $0x8
- jmpCommonIdtEntry
-
-INT9:
- pushl $0x0 # push error code place holder on the stack
- pushl $0x9
- jmpCommonIdtEntry
-
-INT10:
-# Invalid TSS causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $10
- jmpCommonIdtEntry
-
-INT11:
-# Segment Not Present causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $11
- jmpCommonIdtEntry
-
-INT12:
-# Stack fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $12
- jmpCommonIdtEntry
-
-INT13:
-# GP fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $13
- jmpCommonIdtEntry
-
-INT14:
-# Page fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $14
- jmpCommonIdtEntry
-
-INT15:
- pushl $0x0 # push error code place holder on the stack
- pushl $15
- jmpCommonIdtEntry
-
-INT16:
- pushl $0x0 # push error code place holder on the stack
- pushl $16
- jmpCommonIdtEntry
-
-INT17:
-# Alignment check causes an error code to be pushed so no phony push necessary
- nop
- nop
- pushl $17
- jmpCommonIdtEntry
-
-INT18:
- pushl $0x0 # push error code place holder on the stack
- pushl $18
- jmpCommonIdtEntry
-
-INT19:
- pushl $0x0 # push error code place holder on the stack
- pushl $19
- jmpCommonIdtEntry
-
-INTUnknown:
-# The following segment repeats (0x78 - 20) times:
-# No. 1
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 2
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 3
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 4
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 5
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 6
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 7
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 8
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 9
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 10
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 11
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 12
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 13
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 14
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 15
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 16
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 17
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 18
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 19
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 20
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 21
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 22
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 23
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 24
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 25
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 26
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 27
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 28
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 29
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 30
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 31
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 32
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 33
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 34
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 35
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 36
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 37
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 38
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 39
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 40
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 41
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 42
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 43
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 44
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 45
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 46
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 47
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 48
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 49
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 50
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 51
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 52
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 53
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 54
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 55
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 56
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 57
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 58
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 59
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 60
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 61
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 62
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 63
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 64
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 65
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 66
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 67
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 68
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 69
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 70
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 71
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 72
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 73
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 74
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 75
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 76
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 77
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 78
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 79
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 80
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 81
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 82
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 83
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 84
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 85
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 86
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 87
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 88
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 89
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 90
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 91
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 92
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 93
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 94
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 95
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 96
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 97
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 98
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 99
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-# No. 100
- pushl $0x0 # push error code place holder on the stack
-# push xxh ; push vector number
- .byte 0x6a
- .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
- jmpCommonIdtEntry
-
-
-commonIdtEntry:
- pushl %eax
- pushl %ecx
- pushl %edx
- pushl %ebx
- pushl %esp
- pushl %ebp
- pushl %esi
- pushl %edi
- .byte 0x41
- .byte 0x50
-# push r8
- .byte 0x41
- .byte 0x51
-# push r9
- .byte 0x41
- .byte 0x52
-# push r10
- .byte 0x41
- .byte 0x53
-# push r11
- .byte 0x41
- .byte 0x54
-# push r12
- .byte 0x41
- .byte 0x55
-# push r13
- .byte 0x41
- .byte 0x56
-# push r14
- .byte 0x41
- .byte 0x57
-# push r15
- .byte 0x48
- movl %esp,%ebp
-# mov rbp, rsp
-
-##
-## At this point the stack looks like this:
-##
-## Calling SS
-## Calling RSP
-## rflags
-## Calling CS
-## Calling RIP
-## Error code or 0
-## Int num or 0ffh for unknown int num
-## rax
-## rcx
-## rdx
-## rbx
-## rsp
-## rbp
-## rsi
-## rdi
-## r8
-## r9
-## r10
-## r11
-## r12
-## r13
-## r14
-## r15 <------- RSP, RBP
-##
-
- call ClearScreen
- movl $String1, %esi
- call PrintString
- .byte 0x48
- movl 16*8(%ebp),%eax ## move Int number into RAX
- .byte 0x48
- cmpl $18,%eax
- ja PrintDefaultString
-PrintExceptionString:
- shll $3,%eax ## multiply by 8 to get offset from StringTable to actual string address
- addl $StringTable, %eax
- movl (%eax),%esi
- jmp PrintTheString
-PrintDefaultString:
- movl $IntUnknownString, %esi
- # patch Int number
- movl %eax,%edx
- call A2C
- movb %al,1(%esi)
- movl %edx,%eax
- shrl $4,%eax
- call A2C
- movb %al,(%esi)
-PrintTheString:
- call PrintString
- movl $String2, %esi
- call PrintString
- .byte 0x48
- movl 19*8(%ebp),%eax # CS
- call PrintQword
- movb $':', %al
- movb %al, (%edi)
- addl $2,%edi
- .byte 0x48
- movl 18*8(%ebp),%eax # RIP
- call PrintQword
- movl $String3, %esi
- call PrintString
-
- movl $0xb8140,%edi
-
- movl $StringRax, %esi
- call PrintString
- .byte 0x48
- movl 15*8(%ebp),%eax
- call PrintQword
-
- movl $StringRcx, %esi
- call PrintString
- .byte 0x48
- movl 14*8(%ebp),%eax
- call PrintQword
-
- movl $StringRdx, %esi
- call PrintString
- .byte 0x48
- movl 13*8(%ebp),%eax
- call PrintQword
-
- movl $0xb81e0,%edi
-
- movl $StringRbx, %esi
- call PrintString
- .byte 0x48
- movl 12*8(%ebp),%eax
- call PrintQword
-
- movl $StringRsp, %esi
- call PrintString
- .byte 0x48
- movl 21*8(%ebp),%eax
- call PrintQword
-
- movl $StringRbp, %esi
- call PrintString
- .byte 0x48
- movl 10*8(%ebp),%eax
- call PrintQword
-
- movl $0xb8280,%edi
-
- movl $StringRsi, %esi
- call PrintString
- .byte 0x48
- movl 9*8(%ebp),%eax
- call PrintQword
-
- movl $StringRdi, %esi
- call PrintString
- .byte 0x48
- movl 8*8(%ebp),%eax
- call PrintQword
-
- movl $StringEcode, %esi
- call PrintString
- .byte 0x48
- movl 17*8(%ebp),%eax
- call PrintQword
-
- movl $0xb8320,%edi
-
- movl $StringR8, %esi
- call PrintString
- .byte 0x48
- movl 7*8(%ebp),%eax
- call PrintQword
-
- movl $StringR9, %esi
- call PrintString
- .byte 0x48
- movl 6*8(%ebp),%eax
- call PrintQword
-
- movl $StringR10, %esi
- call PrintString
- .byte 0x48
- movl 5*8(%ebp),%eax
- call PrintQword
-
- movl $0xb83c0,%edi
-
- movl $StringR11, %esi
- call PrintString
- .byte 0x48
- movl 4*8(%ebp),%eax
- call PrintQword
-
- movl $StringR12, %esi
- call PrintString
- .byte 0x48
- movl 3*8(%ebp),%eax
- call PrintQword
-
- movl $StringR13, %esi
- call PrintString
- .byte 0x48
- movl 2*8(%ebp),%eax
- call PrintQword
-
- movl $0xb8460,%edi
-
- movl $StringR14, %esi
- call PrintString
- .byte 0x48
- movl 1*8(%ebp),%eax
- call PrintQword
-
- movl $StringR15, %esi
- call PrintString
- .byte 0x48
- movl 0*8(%ebp),%eax
- call PrintQword
-
- movl $StringSs, %esi
- call PrintString
- .byte 0x48
- movl 22*8(%ebp),%eax
- call PrintQword
-
- movl $0xb8500,%edi
-
- movl $StringRflags, %esi
- call PrintString
- .byte 0x48
- movl 20*8(%ebp),%eax
- call PrintQword
-
- movl $0xb8640,%edi
-
- movl %ebp,%esi
- addl $23*8,%esi
- movl $4,%ecx
-
-
-OuterLoop:
- pushl %ecx
- movl $4,%ecx
- .byte 0x48
- movl %edi,%edx
-
-InnerLoop:
- .byte 0x48
- movl (%esi),%eax
- call PrintQword
- addl $8,%esi
- movb $0x20, %al # blank character
- movb %al,(%edi)
- addl $2,%edi
- loop InnerLoop
-
- popl %ecx
- addl $0xa0,%edx
- movl %edx,%edi
- loop OuterLoop
-
-
- movl $0xb8960,%edi
-
- .byte 0x48
- movl 18*8(%ebp),%eax # RIP
- subl $8*8,%eax
- .byte 0x48
- movl %eax,%esi # esi = rip - 8 QWORD linear (total 16 QWORD)
-
- movl $4,%ecx
-
-OuterLoop1:
- pushl %ecx
- movl $4,%ecx
- movl %edi,%edx
-
-InnerLoop1:
- .byte 0x48
- movl (%esi),%eax
- call PrintQword
- addl $8,%esi
- movb $0x20, %al # blank character
- movb %al,(%edi)
- addl $2,%edi
- loop InnerLoop1
-
- popl %ecx
- addl $0xa0,%edx
- movl %edx,%edi
- loop OuterLoop1
-
-
-
- #wbinvd
-LN_C1:
- jmp LN_C1
-
-#
-# return
-#
- movl %ebp,%esp
-# mov rsp, rbp
- .byte 0x41
- .byte 0x5f
-# pop r15
- .byte 0x41
- .byte 0x5e
-# pop r14
- .byte 0x41
- .byte 0x5d
-# pop r13
- .byte 0x41
- .byte 0x5c
-# pop r12
- .byte 0x41
- .byte 0x5b
-# pop r11
- .byte 0x41
- .byte 0x5a
-# pop r10
- .byte 0x41
- .byte 0x59
-# pop r9
- .byte 0x41
- .byte 0x58
-# pop r8
- popl %edi
- popl %esi
- popl %ebp
- popl %eax # esp
- popl %ebx
- popl %edx
- popl %ecx
- popl %eax
-
- .byte 0x48
- .byte 0x83
- .byte 0xc4
- .byte 0x10
-# add esp, 16 ; error code and INT number
-
- .byte 0x48
- .byte 0xcf
-# iretq
-
-PrintString:
- pushl %eax
-LN_C2:
- movb (%esi), %al
- cmpb $0,%al
- je LN_C3
- movb %al, (%edi)
- .byte 0xff
- .byte 0xc6
-# inc esi
- addl $2,%edi
- jmp LN_C2
-LN_C3:
- popl %eax
- ret
-
-## RAX contains qword to print
-## RDI contains memory location (screen location) to print it to
-PrintQword:
- pushl %ecx
- pushl %ebx
- pushl %eax
-
- .byte 0x48
- .byte 0xc7
- .byte 0xc1
- .long 16
-# mov rcx, 16
-looptop:
- .byte 0x48
- roll $4,%eax
- movb %al,%bl
- andb $0xf,%bl
- addb $'0', %bl
- cmpb $'9', %bl
- jle LN_C4
- addb $7,%bl
-LN_C4:
- movb %bl, (%edi)
- addl $2,%edi
- loop looptop
- #wbinvd
-
- popl %eax
- popl %ebx
- popl %ecx
- ret
-
-ClearScreen:
- pushl %eax
- pushl %ecx
-
- movb $0x20, %al # blank character
- movb $0xc,%ah
- movl $0xb8000,%edi
- movl $80*24,%ecx
-LN_C5:
- movw %ax, (%edi)
- addl $2,%edi
- loop LN_C5
- movl $0xb8000,%edi
-
- popl %ecx
- popl %eax
-
- ret
-
-A2C:
- andb $0xf,%al
- addb $'0', %al
- cmpb $'9', %al
- jle LN_C6
- addb $7,%al
-LN_C6:
- ret
-
-String1: .asciz "*** INT "
-
-Int0String: .asciz "00h Divide by 0 -"
-Int1String: .asciz "01h Debug exception -"
-Int2String: .asciz "02h NMI -"
-Int3String: .asciz "03h Breakpoint -"
-Int4String: .asciz "04h Overflow -"
-Int5String: .asciz "05h Bound -"
-Int6String: .asciz "06h Invalid opcode -"
-Int7String: .asciz "07h Device not available -"
-Int8String: .asciz "08h Double fault -"
-Int9String: .asciz "09h Coprocessor seg overrun (reserved) -"
-Int10String: .asciz "0Ah Invalid TSS -"
-Int11String: .asciz "0Bh Segment not present -"
-Int12String: .asciz "0Ch Stack fault -"
-Int13String: .asciz "0Dh General protection fault -"
-Int14String: .asciz "0Eh Page fault -"
-Int15String: .asciz "0Fh (Intel reserved) -"
-Int16String: .asciz "10h Floating point error -"
-Int17String: .asciz "11h Alignment check -"
-Int18String: .asciz "12h Machine check -"
-Int19String: .asciz "13h SIMD Floating-Point Exception -"
-IntUnknownString: .asciz "??h Unknown interrupt -"
-
-StringTable: .long Int0String, 0, Int1String, 0, Int2String, 0, Int3String, 0, \
- Int4String, 0, Int5String, 0, Int6String, 0, Int7String, 0, \
- Int8String, 0, Int9String, 0, Int10String, 0, Int11String, 0, \
- Int12String, 0, Int13String, 0, Int14String, 0, Int15String, 0, \
- Int16String, 0, Int17String, 0, Int18String, 0, Int19String, 0
-
-String2: .asciz " HALT!! *** ("
-String3: .asciz ")"
-StringRax: .asciz "RAX="
-StringRcx: .asciz " RCX="
-StringRdx: .asciz " RDX="
-StringRbx: .asciz "RBX="
-StringRsp: .asciz " RSP="
-StringRbp: .asciz " RBP="
-StringRsi: .asciz "RSI="
-StringRdi: .asciz " RDI="
-StringEcode: .asciz " ECODE="
-StringR8: .asciz "R8 ="
-StringR9: .asciz " R9 ="
-StringR10: .asciz " R10="
-StringR11: .asciz "R11="
-StringR12: .asciz " R12="
-StringR13: .asciz " R13="
-StringR14: .asciz "R14="
-StringR15: .asciz " R15="
-StringSs: .asciz " SS ="
-StringRflags: .asciz "RFLAGS="
-
-Idtr: .float 0
- .float 0
-
- .org 0x21ffe
-BlockSignature:
- .word 0xaa55
-
diff --git a/DuetPkg/BootSector/efi64.asm b/DuetPkg/BootSector/efi64.asm deleted file mode 100644 index ee6f9fda86..0000000000 --- a/DuetPkg/BootSector/efi64.asm +++ /dev/null @@ -1,787 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* efi64.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; Now in 64-bit long mode.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- .486
- .model flat
- .stack
- .code
- org 21000h
-
-DEFAULT_HANDLER_SIZE EQU INT1 - INT0
-
-JmpCommonIdtEntry macro
- ; jmp commonIdtEntry - this must be hand coded to keep the assembler from
- ; using a 8 bit reletive jump when the entries are
- ; within 255 bytes of the common entry. This must
- ; be done to maintain the consistency of the size
- ; of entry points...
- db 0e9h ; jmp 16 bit reletive
- dd commonIdtEntry - $ - 4 ; offset to jump to
-endm
-
-
-Start:
-
- mov esp,0001fffe8h ; make final stack aligned
-
- ; set OSFXSR and OSXMMEXCPT because some code will use XMM register
- db 0fh
- db 20h
- db 0e0h
-; mov rax, cr4
- bts eax, 9
- bts eax, 0ah
- db 0fh
- db 22h
- db 0e0h
-; mov cr4, rax
-
- call ClearScreen
-
- ; Populate IDT with meaningful offsets for exception handlers...
- mov eax, offset Idtr
- sidt fword ptr [eax] ; get fword address of IDT
-
- mov eax, offset Halt
- mov ebx, eax ; use bx to copy 15..0 to descriptors
- shr eax, 16 ; use ax to copy 31..16 to descriptors
- ; 63..32 of descriptors is 0
- mov ecx, 78h ; 78h IDT entries to initialize with unique entry points (exceptions)
- mov esi, [offset Idtr + 2]
- mov edi, [esi]
-
-@@: ; loop through all IDT entries exception handlers and initialize to default handler
- mov word ptr [edi], bx ; write bits 15..0 of offset
- mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT
- mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
- mov word ptr [edi+6], ax ; write bits 31..16 of offset
- mov dword ptr [edi+8], 0 ; write bits 63..32 of offset
- add edi, 16 ; move up to next descriptor
- add bx, DEFAULT_HANDLER_SIZE ; move to next entry point
- loop @b ; loop back through again until all descriptors are initialized
-
- ;; at this point edi contains the offset of the descriptor for INT 20
- ;; and bx contains the low 16 bits of the offset of the default handler
- ;; so initialize all the rest of the descriptors with these two values...
-; mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
-;@@: ; loop through all IDT entries exception handlers and initialize to default handler
-; mov word ptr [edi], bx ; write bits 15..0 of offset
-; mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT
-; mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
-; mov word ptr [edi+6], ax ; write bits 31..16 of offset
-; mov dword ptr [edi+8], 0 ; write bits 63..32 of offset
-; add edi, 16 ; move up to next descriptor
-; loop @b ; loop back through again until all descriptors are initialized
-
-
-;; DUMP location of IDT and several of the descriptors
-; mov ecx, 8
-; mov eax, [offset Idtr + 2]
-; mov eax, [eax]
-; mov edi, 0b8000h
-; call PrintQword
-; mov esi, eax
-; mov edi, 0b80a0h
-; jmp OuterLoop
-
-;;
-;; just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
-; mov eax, 011111111h
-; mov ebx, 022222222h
-; mov ecx, 033333333h
-; mov edx, 044444444h
-; mov ebp, 055555555h
-; mov esi, 066666666h
-; mov edi, 077777777h
-; push 011111111h
-; push 022222222h
-; push 033333333h
-; int 119
-
- mov esi,022000h ; esi = 22000
- mov eax,[esi+014h] ; eax = [22014]
- add esi,eax ; esi = 22000 + [22014] = Base of EFILDR.C
- mov ebp,[esi+03ch] ; ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
- add ebp,esi
- mov edi,[ebp+030h] ; edi = [[22000 + [22014] + 3c] + 2c] = ImageBase (63..32 is zero, ignore)
- mov eax,[ebp+028h] ; eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
- add eax,edi ; eax = ImageBase + EntryPoint
- mov ebx, offset EfiLdrOffset
- mov dword ptr [ebx],eax ; Modify far jump instruction for correct entry point
-
- mov bx,word ptr[ebp+6] ; bx = Number of sections
- xor eax,eax
- mov ax,word ptr[ebp+014h] ; ax = Optional Header Size
- add ebp,eax
- add ebp,018h ; ebp = Start of 1st Section
-
-SectionLoop:
- push esi ; Save Base of EFILDR.C
- push edi ; Save ImageBase
- add esi,[ebp+014h] ; esi = Base of EFILDR.C + PointerToRawData
- add edi,[ebp+00ch] ; edi = ImageBase + VirtualAddress
- mov ecx,[ebp+010h] ; ecs = SizeOfRawData
-
- cld
- shr ecx,2
- rep movsd
-
- pop edi ; Restore ImageBase
- pop esi ; Restore Base of EFILDR.C
-
- add bp,028h ; ebp = ebp + 028h = Pointer to next section record
- db 66h
- db 0ffh
- db 0cbh
-; dec bx
- cmp bx,0
- jne SectionLoop
-
- mov edx, offset Idtr
- movzx eax, word ptr [edx] ; get size of IDT
- db 0ffh
- db 0c0h
-; inc eax
- add eax, dword ptr [edx + 2] ; add to base of IDT to get location of memory map...
- xor ecx, ecx
- mov ecx, eax ; put argument to RCX
-
- db 48h
- db 0c7h
- db 0c0h
-EfiLdrOffset:
- dd 000401000h ; Offset of EFILDR
-; mov rax, 401000h
- db 50h
-; push rax
-
-; ret
- db 0c3h
-
-; db "**** DEFAULT IDT ENTRY ***",0
- align 02h
-Halt:
-INT0:
- push 0h ; push error code place holder on the stack
- push 0h
- JmpCommonIdtEntry
-; db 0e9h ; jmp 16 bit reletive
-; dd commonIdtEntry - $ - 4 ; offset to jump to
-
-INT1:
- push 0h ; push error code place holder on the stack
- push 1h
- JmpCommonIdtEntry
-
-INT2:
- push 0h ; push error code place holder on the stack
- push 2h
- JmpCommonIdtEntry
-
-INT3:
- push 0h ; push error code place holder on the stack
- push 3h
- JmpCommonIdtEntry
-
-INT4:
- push 0h ; push error code place holder on the stack
- push 4h
- JmpCommonIdtEntry
-
-INT5:
- push 0h ; push error code place holder on the stack
- push 5h
- JmpCommonIdtEntry
-
-INT6:
- push 0h ; push error code place holder on the stack
- push 6h
- JmpCommonIdtEntry
-
-INT7:
- push 0h ; push error code place holder on the stack
- push 7h
- JmpCommonIdtEntry
-
-INT8:
-; Double fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 8h
- JmpCommonIdtEntry
-
-INT9:
- push 0h ; push error code place holder on the stack
- push 9h
- JmpCommonIdtEntry
-
-INT10:
-; Invalid TSS causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 10
- JmpCommonIdtEntry
-
-INT11:
-; Segment Not Present causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 11
- JmpCommonIdtEntry
-
-INT12:
-; Stack fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 12
- JmpCommonIdtEntry
-
-INT13:
-; GP fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 13
- JmpCommonIdtEntry
-
-INT14:
-; Page fault causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 14
- JmpCommonIdtEntry
-
-INT15:
- push 0h ; push error code place holder on the stack
- push 15
- JmpCommonIdtEntry
-
-INT16:
- push 0h ; push error code place holder on the stack
- push 16
- JmpCommonIdtEntry
-
-INT17:
-; Alignment check causes an error code to be pushed so no phony push necessary
- nop
- nop
- push 17
- JmpCommonIdtEntry
-
-INT18:
- push 0h ; push error code place holder on the stack
- push 18
- JmpCommonIdtEntry
-
-INT19:
- push 0h ; push error code place holder on the stack
- push 19
- JmpCommonIdtEntry
-
-INTUnknown:
-REPEAT (78h - 20)
- push 0h ; push error code place holder on the stack
-; push xxh ; push vector number
- db 06ah
- db ( $ - INTUnknown - 3 ) / 9 + 20 ; vector number
- JmpCommonIdtEntry
-ENDM
-
-commonIdtEntry:
- push eax
- push ecx
- push edx
- push ebx
- push esp
- push ebp
- push esi
- push edi
- db 41h
- db 50h
-; push r8
- db 41h
- db 51h
-; push r9
- db 41h
- db 52h
-; push r10
- db 41h
- db 53h
-; push r11
- db 41h
- db 54h
-; push r12
- db 41h
- db 55h
-; push r13
- db 41h
- db 56h
-; push r14
- db 41h
- db 57h
-; push r15
- db 48h
- mov ebp, esp
-; mov rbp, rsp
-
-;;
-;; At this point the stack looks like this:
-;;
-;; Calling SS
-;; Calling RSP
-;; rflags
-;; Calling CS
-;; Calling RIP
-;; Error code or 0
-;; Int num or 0ffh for unknown int num
-;; rax
-;; rcx
-;; rdx
-;; rbx
-;; rsp
-;; rbp
-;; rsi
-;; rdi
-;; r8
-;; r9
-;; r10
-;; r11
-;; r12
-;; r13
-;; r14
-;; r15 <------- RSP, RBP
-;;
-
- call ClearScreen
- mov esi, offset String1
- call PrintString
- db 48h
- mov eax, [ebp + 16*8] ;; move Int number into RAX
- db 48h
- cmp eax, 18
- ja PrintDefaultString
-PrintExceptionString:
- shl eax, 3 ;; multiply by 8 to get offset from StringTable to actual string address
- add eax, offset StringTable
- mov esi, [eax]
- jmp PrintTheString
-PrintDefaultString:
- mov esi, offset IntUnknownString
- ; patch Int number
- mov edx, eax
- call A2C
- mov [esi + 1], al
- mov eax, edx
- shr eax, 4
- call A2C
- mov [esi], al
-PrintTheString:
- call PrintString
- mov esi, offset String2
- call PrintString
- db 48h
- mov eax, [ebp+19*8] ; CS
- call PrintQword
- mov al, ':'
- mov byte ptr [edi], al
- add edi, 2
- db 48h
- mov eax, [ebp+18*8] ; RIP
- call PrintQword
- mov esi, offset String3
- call PrintString
-
- mov edi, 0b8140h
-
- mov esi, offset StringRax ; rax
- call PrintString
- db 48h
- mov eax, [ebp+15*8]
- call PrintQword
-
- mov esi, offset StringRcx ; rcx
- call PrintString
- db 48h
- mov eax, [ebp+14*8]
- call PrintQword
-
- mov esi, offset StringRdx ; rdx
- call PrintString
- db 48h
- mov eax, [ebp+13*8]
- call PrintQword
-
- mov edi, 0b81e0h
-
- mov esi, offset StringRbx ; rbx
- call PrintString
- db 48h
- mov eax, [ebp+12*8]
- call PrintQword
-
- mov esi, offset StringRsp ; rsp
- call PrintString
- db 48h
- mov eax, [ebp+21*8]
- call PrintQword
-
- mov esi, offset StringRbp ; rbp
- call PrintString
- db 48h
- mov eax, [ebp+10*8]
- call PrintQword
-
- mov edi, 0b8280h
-
- mov esi, offset StringRsi ; rsi
- call PrintString
- db 48h
- mov eax, [ebp+9*8]
- call PrintQword
-
- mov esi, offset StringRdi ; rdi
- call PrintString
- db 48h
- mov eax, [ebp+8*8]
- call PrintQword
-
- mov esi, offset StringEcode ; error code
- call PrintString
- db 48h
- mov eax, [ebp+17*8]
- call PrintQword
-
- mov edi, 0b8320h
-
- mov esi, offset StringR8 ; r8
- call PrintString
- db 48h
- mov eax, [ebp+7*8]
- call PrintQword
-
- mov esi, offset StringR9 ; r9
- call PrintString
- db 48h
- mov eax, [ebp+6*8]
- call PrintQword
-
- mov esi, offset StringR10 ; r10
- call PrintString
- db 48h
- mov eax, [ebp+5*8]
- call PrintQword
-
- mov edi, 0b83c0h
-
- mov esi, offset StringR11 ; r11
- call PrintString
- db 48h
- mov eax, [ebp+4*8]
- call PrintQword
-
- mov esi, offset StringR12 ; r12
- call PrintString
- db 48h
- mov eax, [ebp+3*8]
- call PrintQword
-
- mov esi, offset StringR13 ; r13
- call PrintString
- db 48h
- mov eax, [ebp+2*8]
- call PrintQword
-
- mov edi, 0b8460h
-
- mov esi, offset StringR14 ; r14
- call PrintString
- db 48h
- mov eax, [ebp+1*8]
- call PrintQword
-
- mov esi, offset StringR15 ; r15
- call PrintString
- db 48h
- mov eax, [ebp+0*8]
- call PrintQword
-
- mov esi, offset StringSs ; ss
- call PrintString
- db 48h
- mov eax, [ebp+22*8]
- call PrintQword
-
- mov edi, 0b8500h
-
- mov esi, offset StringRflags ; rflags
- call PrintString
- db 48h
- mov eax, [ebp+20*8]
- call PrintQword
-
- mov edi, 0b8640h
-
- mov esi, ebp
- add esi, 23*8
- mov ecx, 4
-
-
-OuterLoop:
- push ecx
- mov ecx, 4
- db 48h
- mov edx, edi
-
-InnerLoop:
- db 48h
- mov eax, [esi]
- call PrintQword
- add esi, 8
- mov al, ' '
- mov [edi], al
- add edi, 2
- loop InnerLoop
-
- pop ecx
- add edx, 0a0h
- mov edi, edx
- loop OuterLoop
-
-
- mov edi, 0b8960h
-
- db 48h
- mov eax, [ebp+18*8] ; RIP
- sub eax, 8 * 8
- db 48h
- mov esi, eax ; esi = rip - 8 QWORD linear (total 16 QWORD)
-
- mov ecx, 4
-
-OuterLoop1:
- push ecx
- mov ecx, 4
- mov edx, edi
-
-InnerLoop1:
- db 48h
- mov eax, [esi]
- call PrintQword
- add esi, 8
- mov al, ' '
- mov [edi], al
- add edi, 2
- loop InnerLoop1
-
- pop ecx
- add edx, 0a0h
- mov edi, edx
- loop OuterLoop1
-
-
-
- ;wbinvd
-@@:
- jmp @b
-
-;
-; return
-;
- mov esp, ebp
-; mov rsp, rbp
- db 41h
- db 5fh
-; pop r15
- db 41h
- db 5eh
-; pop r14
- db 41h
- db 5dh
-; pop r13
- db 41h
- db 5ch
-; pop r12
- db 41h
- db 5bh
-; pop r11
- db 41h
- db 5ah
-; pop r10
- db 41h
- db 59h
-; pop r9
- db 41h
- db 58h
-; pop r8
- pop edi
- pop esi
- pop ebp
- pop eax ; esp
- pop ebx
- pop edx
- pop ecx
- pop eax
-
- db 48h
- db 83h
- db 0c4h
- db 10h
-; add esp, 16 ; error code and INT number
-
- db 48h
- db 0cfh
-; iretq
-
-PrintString:
- push eax
-@@:
- mov al, byte ptr [esi]
- cmp al, 0
- je @f
- mov byte ptr [edi], al
- db 0ffh
- db 0c6h
-; inc esi
- add edi, 2
- jmp @b
-@@:
- pop eax
- ret
-
-;; RAX contains qword to print
-;; RDI contains memory location (screen location) to print it to
-PrintQword:
- push ecx
- push ebx
- push eax
-
- db 48h
- db 0c7h
- db 0c1h
- dd 16
-; mov rcx, 16
-looptop:
- db 48h
- rol eax, 4
- mov bl, al
- and bl, 0fh
- add bl, '0'
- cmp bl, '9'
- jle @f
- add bl, 7
-@@:
- mov byte ptr [edi], bl
- add edi, 2
- loop looptop
- ;wbinvd
-
- pop eax
- pop ebx
- pop ecx
- ret
-
-ClearScreen:
- push eax
- push ecx
-
- mov al, ' '
- mov ah, 0ch
- mov edi, 0b8000h
- mov ecx, 80 * 24
-@@:
- mov word ptr [edi], ax
- add edi, 2
- loop @b
- mov edi, 0b8000h
-
- pop ecx
- pop eax
-
- ret
-
-A2C:
- and al, 0fh
- add al, '0'
- cmp al, '9'
- jle @f
- add al, 7
-@@:
- ret
-
-String1 db "*** INT ",0
-
-Int0String db "00h Divide by 0 -",0
-Int1String db "01h Debug exception -",0
-Int2String db "02h NMI -",0
-Int3String db "03h Breakpoint -",0
-Int4String db "04h Overflow -",0
-Int5String db "05h Bound -",0
-Int6String db "06h Invalid opcode -",0
-Int7String db "07h Device not available -",0
-Int8String db "08h Double fault -",0
-Int9String db "09h Coprocessor seg overrun (reserved) -",0
-Int10String db "0Ah Invalid TSS -",0
-Int11String db "0Bh Segment not present -",0
-Int12String db "0Ch Stack fault -",0
-Int13String db "0Dh General protection fault -",0
-Int14String db "0Eh Page fault -",0
-Int15String db "0Fh (Intel reserved) -",0
-Int16String db "10h Floating point error -",0
-Int17String db "11h Alignment check -",0
-Int18String db "12h Machine check -",0
-Int19String db "13h SIMD Floating-Point Exception -",0
-IntUnknownString db "??h Unknown interrupt -",0
-
-StringTable dq offset Int0String, offset Int1String, offset Int2String, offset Int3String,
- offset Int4String, offset Int5String, offset Int6String, offset Int7String,
- offset Int8String, offset Int9String, offset Int10String, offset Int11String,
- offset Int12String, offset Int13String, offset Int14String, offset Int15String,
- offset Int16String, offset Int17String, offset Int18String, offset Int19String
-
-String2 db " HALT!! *** (",0
-String3 db ")",0
-StringRax db "RAX=",0
-StringRcx db " RCX=",0
-StringRdx db " RDX=",0
-StringRbx db "RBX=",0
-StringRsp db " RSP=",0
-StringRbp db " RBP=",0
-StringRsi db "RSI=",0
-StringRdi db " RDI=",0
-StringEcode db " ECODE=",0
-StringR8 db "R8 =",0
-StringR9 db " R9 =",0
-StringR10 db " R10=",0
-StringR11 db "R11=",0
-StringR12 db " R12=",0
-StringR13 db " R13=",0
-StringR14 db "R14=",0
-StringR15 db " R15=",0
-StringSs db " SS =",0
-StringRflags db "RFLAGS=",0
-
-Idtr df 0
- df 0
-
- org 21ffeh
-BlockSignature:
- dw 0aa55h
-
- end
diff --git a/DuetPkg/BootSector/st16_64.S b/DuetPkg/BootSector/st16_64.S deleted file mode 100644 index 8eadd28d35..0000000000 --- a/DuetPkg/BootSector/st16_64.S +++ /dev/null @@ -1,1142 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* st16_64.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
-
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
- .org 0x0
-
-.global _start
-_start:
-
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-
-SectorSize: .word 0 # Sector Size - 16 bits
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
-ReservedSectors: .word 0 # Reserved Sectors - 16 bits
-NoFats: .byte 0 # Number of FATs - 8 bits
-RootEntries: .word 0 # Root Entries - 16 bits
-Sectors: .word 0 # Number of Sectors - 16 bits
-Media: .byte 0 # Media - 8 bits - ignored
-SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
-SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
-Heads: .word 0 # Heads - 16 bits - ignored
-HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
-LargeSectors: .long 0 # Large Sectors - 32 bits
-PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
-CurrentHead: .byte 0 # Current Head - 8 bits
-Signature: .byte 0 # Signature - 8 bits - ignored
-VolId: .ascii " " # Volume Serial Number- 4 bytes
-FatLabel: .ascii " " # Label - 11 bytes
-SystemId: .ascii "FAT16 " # SystemId - 8 bytes
-
-BootSectorEntryPoint:
- # ASSUME ds:@code
- # ASSUME ss:@code
- # ds = 1000, es = 2000 + x (size of first cluster >> 4)
- # cx = Start Cluster of EfiLdr
- # dx = Start Cluster of Efivar.bin
-
-# Re use the BPB data stored in Boot Sector
- movw $0x7c00,%bp
-
- pushw %cx
-# Read Efivar.bin
-# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- movw $0x1900,%ax
- movw %ax,%es
- testw %dx,%dx
- jnz CheckVarStoreSize
-
- movb $1,%al
-NoVarStore:
- pushw %es
-# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- movb %al, %es:(4)
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- movw %dx,%di
- cmpl $0x4000, %ds:2(%di)
- movb $2,%al
- jne NoVarStore
-
-LoadVarStore:
- movb $0,%al
- movb %al, %es:(4)
- movw (%di), %cx
-# ES:DI = 1500:0
- xorw %di,%di
- pushw %es
- movw $0x1500,%ax
- movw %ax,%es
- call ReadFile
-SaveVolumeId:
- popw %es
- movw VolId(%bp), %ax
- movw %ax, %es:(0) # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- movw VolId+2(%bp), %ax
- movw %ax, %es:(2)
-
-# Read Efildr
- popw %cx
-# cx = Start Cluster of Efildr -> BS.com has filled already
-# ES:DI = 2000:0, first cluster will be read again
- xorw %di,%di # di = 0
- movw $0x2000,%ax
- movw %ax,%es
- call ReadFile
- movw %cs,%ax
- movw %ax, %cs:JumpSegment
-
-CheckEm64T:
- movl $0x80000001,%eax
-# cpuid
- .word 0xA20F
- btl $29,%edx
- jc CheckEm64TPass
- pushw %cs
- popw %ds
- leaw Em64String,%si
- movw $18,%cx
- jmp PrintStringAndHalt
-CheckEm64TPass:
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x200
-JumpSegment:
- .word 0x2000
-
-
-
-# ****************************************************************************
-# ReadFile
-#
-# Arguments:
-# CX = Start Cluster of File
-# ES:DI = Buffer to store file content read from disk
-#
-# Return:
-# (ES << 4 + DI) = end of file content Buffer
-#
-# ****************************************************************************
-ReadFile:
-# si = NumberOfClusters
-# cx = ClusterNumber
-# dx = CachedFatSectorNumber
-# ds:0000 = CacheFatSectorBuffer
-# es:di = Buffer to load file
-# bx = NextClusterNumber
- pusha
- movw $1,%si # NumberOfClusters = 1
- pushw %cx # Push Start Cluster onto stack
- movw $0xfff,%dx # CachedFatSectorNumber = 0xfff
-FatChainLoop:
- movw %cx,%ax # ax = ClusterNumber
- andw $0xfff8,%ax # ax = ax & 0xfff8
- cmpw $0xfff8,%ax # See if this is the last cluster
- je FoundLastCluster # Jump if last cluster found
- movw %cx,%ax # ax = ClusterNumber
- shlw %ax # FatOffset = ClusterNumber * 2
- pushw %si # Save si
- movw %ax,%si # si = FatOffset
- shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
- addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK
- cmpw %dx,%ax # Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- movw $2,%bx
- pushw %es
- pushw %ds
- popw %es
- call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
- popw %es
- movw %ax,%dx # CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- movw (%si), %bx # bx = NextClusterNumber
- movw %cx,%ax # ax = ClusterNumber
- popw %si # Restore si
- decw %bx # bx = NextClusterNumber - 1
- cmpw %cx,%bx # See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- incw %bx # bx = NextClusterNumber
- incw %si # NumberOfClusters++
- movw %bx,%cx # ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- incw %bx
- popw %ax # ax = StartCluster
- pushw %bx # StartCluster = NextClusterNumber
- movw %bx,%cx # ClusterNumber = NextClusterNumber
- subw $2,%ax # ax = StartCluster - 2
- xorb %bh,%bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- pushw %ax # save start sector
- movw %si,%ax # ax = NumberOfClusters
- mulw %bx # ax = NumberOfClusters * SectorsPerCluster
- movw %ax,%bx # bx = Number of Sectors
- popw %ax # ax = Start Sector
- call ReadBlocks
- movw $1,%si # NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- popw %cx
- popa
- ret
-
-
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax,%esi # esi = Start LBA
- movw %bx,%cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc,%bp # bp = 0x7bfc
- movl %esi,%eax # eax = Start LBA
- xorl %edx,%edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
-
- movw (%bp), %bx # bx = MaxSector
- subw %dx,%bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx,%cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx,%bx # bx = Blocks
-LimitTransfer:
- pushw %ax # save ax
- movw %es,%ax # ax = es
- shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
- andw $0x7f,%ax # ax = Number of blocks into current seg
- addw %bx,%ax # ax = End Block number of transfer
- cmpw $0x80,%ax # See if it crosses a 64K boundry
- jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
- subw $0x80,%ax # ax = Number of blocks past 64K boundry
- subw %ax,%bx # Decrease transfer size by block overage
-NotCrossing64KBoundry:
- popw %ax # restore ax
-
- pushw %cx
- movb %dl,%cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx,%dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl,%dh # dh = Head
- movw $0x7c00,%bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al,%ch # ch = Cylinder
- movb %bl,%al # al = Blocks
- movb $2,%ah # ah = Function 2
- movw %di,%bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx,%ebx
- addl %ebx,%esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx,%cx # Blocks = Blocks - NumberOfBlocks
- movw %es,%ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx,%ax
- movw %ax,%es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0,%cx
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- pushw %cs
- popw %ds
- leaw ErrorString,%si
- movw $7,%cx
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- movw $0xb800,%ax
- movw %ax,%es
- movw $160,%di
- rep
- movsw
-Halt:
- jmp Halt
-
-ErrorString:
- .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c
-
- .org 0x01fa
-LBAOffsetForBootSector:
- .long 0x0
-
- .org 0x01fe
- .word 0xaa55
-
-#******************************************************************************
-#******************************************************************************
-#******************************************************************************
-
-.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
-.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
-.equ KBD_STATUS_PORT, 0x064 # 8042 status port
-.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
-.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
-
- .org 0x200
- jmp start
-Em64String:
-.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
-
-start:
- movw %cs,%ax
- movw %ax,%ds
- movw %ax,%es
- movw %ax,%ss
- movw $MyStack, %sp
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[160],'a'
-# mov ax,cs
-# mov es,ax
-
- movl $0,%ebx
- leal MemoryMap, %edi
-MemMapLoop:
- movl $0xe820,%eax
- movl $20,%ecx
- movl $0x534d4150, %edx # SMAP
- int $0x15
- jc MemMapDone
- addl $20,%edi
- cmpl $0,%ebx
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- leal MemoryMap, %eax
- subl %eax,%edi # Get the address of the memory map
- movl %edi, MemoryMapSize # Save the size of the memory map
-
- xorl %ebx,%ebx
- movw %cs,%bx # BX=segment
- shll $4,%ebx # BX="linear" address of segment base
- leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
- movl %eax, (gdtr + 2) # Put address of gdt into the gdtr
- leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
- movl %eax, (idtr + 2) # Put address of idt into the idtr
- leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[162],'b'
-# mov ax,cs
-# mov es,ax
-
-#
-# Enable A20 Gate
-#
-
- movw $0x2401,%ax # Enable A20 Gate
- int $0x15
- jnc A20GateEnabled # Jump if it suceeded
-
-#
-# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-#
-
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- outw %ax, $DELAY_PORT # Delay 1 uS
- movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
- outb %al, $KBD_STATUS_PORT # Send command to the 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- movb $ENABLE_A20_CMD, %al # gate address bit 20 on
- outb %al, $KBD_CONTROL_PORT # Send command to thre 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- movw $25,%cx # Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- outw %ax, $DELAY_PORT # Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
-
-#
-# DISABLE INTERRUPTS - Entering Protected Mode
-#
-
- cli
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[164],'c'
-# mov ax,cs
-# mov es,ax
-
- leal OffsetIn32BitProtectedMode, %eax
- addl $0x20000+0x6,%eax
- movl %eax, OffsetIn32BitProtectedMode
-
- leal OffsetInLongMode, %eax
- addl $0x20000+0x6,%eax
- movl %eax, OffsetInLongMode
-
- #
- # load GDT
- #
- .byte 0x66
- lgdt gdtr
-
- #
- # Enable Protect Mode (set CR0.PE=1)
- #
- movl %cr0, %eax # Read CR0.
- orl $0x1,%eax # Set PE=1
- movl %eax, %cr0 # Write CR0.
- .byte 0x66
- .byte 0xea # jmp far 16:32
-OffsetIn32BitProtectedMode:
- .long 0x0000000 # offset $+8 (In32BitProtectedMode)
- .word 0x10 # selector (flat CS)
-In32BitProtectedMode:
-
-#
-# Entering Long Mode
-#
- .byte 0x66
- movw $8,%ax
- movw %ax,%ds
- movw %ax,%es
- movw %ax,%ss
-
- #
- # Enable the 64-bit page-translation-table entries by
- # setting CR4.PAE=1 (this is _required_ before activating
- # long mode). Paging is not enabled until after long mode
- # is enabled.
- #
- .byte 0xf
- .byte 0x20
- .byte 0xe0
-# mov eax, cr4
- btsl $5,%eax
- .byte 0xf
- .byte 0x22
- .byte 0xe0
-# mov cr4, eax
-
- #
- # This is the Trapolean Page Tables that are guarenteed
- # under 4GB.
- #
- # Address Map:
- # 10000 ~ 12000 - efildr (loaded)
- # 20000 ~ 21000 - start64.com
- # 21000 ~ 22000 - efi64.com
- # 22000 ~ 90000 - efildr
- # 90000 ~ 96000 - 4G pagetable (will be reload later)
- #
- .byte 0xb8
- .long 0x90000
-# mov eax, 90000h
- movl %eax, %cr3
-
- #
- # Enable long mode (set EFER.LME=1).
- #
- .byte 0xb9
- .long 0xc0000080
-# mov ecx, 0c0000080h ; EFER MSR number.
- .byte 0xf
- .byte 0x32
-# rdmsr ; Read EFER.
- .byte 0xf
- .byte 0xba
- .byte 0xe8
- .byte 0x8
-# bts eax, 8 ; Set LME=1.
- .byte 0xf
- .byte 0x30
-# wrmsr ; Write EFER.
-
- #
- # Enable paging to activate long mode (set CR0.PG=1)
- #
- movl %cr0, %eax # Read CR0.
- .byte 0xf
- .byte 0xba
- .byte 0xe8
- .byte 0x1f
-# bts eax, 31 ; Set PG=1.
- movl %eax, %cr0 # Write CR0.
- jmp GoToLongMode
-GoToLongMode:
-
- .byte 0x67
- .byte 0xea # Far Jump $+9:Selector to reload CS
-OffsetInLongMode:
- .long 00000000 # $+9 Offset is ensuing instruction boundary
- .word 0x38 # Selector is our code selector, 38h
-
-InLongMode:
- .byte 0x66
- movw $0x30,%ax
- movw %ax,%ds
-
- .byte 0x66
- movw $0x18,%ax
- movw %ax,%es
- movw %ax,%ss
- movw %ax,%ds
-
- .byte 0xbd
- .long 0x400000
-# mov ebp,000400000h ; Destination of EFILDR32
- .byte 0xbb
- .long 0x70000
-# mov ebx,000070000h ; Length of copy
-
- #
- # load idt later
- #
- .byte 0x48
- .byte 0x33
- .byte 0xc0
-# xor rax, rax
- .byte 0x66
- movw $idtr, %ax
- .byte 0x48
- .byte 0x5
- .long 0x20000
-# add rax, 20000h
-
- .byte 0xf
- .byte 0x1
- .byte 0x18
-# lidt fword ptr [rax]
-
- .byte 0x48
- .byte 0xc7
- .byte 0xc0
- .long 0x21000
-# mov rax, 21000h
- .byte 0x50
-# push rax
-
-# ret
- .byte 0xc3
-
-Empty8042InputBuffer:
- movw $0,%cx
-Empty8042Loop:
- outw %ax, $DELAY_PORT # Delay 1us
- inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port
- andb $0x2,%al # Check the Input Buffer Full Flag
- loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-##############################################################################
-# data
-##############################################################################
-
- .p2align 1
-
- gdtr: .long GDT_END - GDT_BASE - 1 # GDT limit
- .long 0 # (GDT base gets set above)
-##############################################################################
-# global descriptor table (GDT)
-##############################################################################
-
- .p2align 1
-
-GDT_BASE:
-# null descriptor
-.equ NULL_SEL, .-GDT_BASE # Selector [0x0]
- .word 0 # limit 15:0
- .word 0 # base 15:0
- .byte 0 # base 23:16
- .byte 0 # type
- .byte 0 # limit 19:16, flags
- .byte 0 # base 31:24
-
-# linear data segment descriptor
-.equ LINEAR_SEL, .-GDT_BASE # Selector [0x8]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# linear code segment descriptor
-.equ LINEAR_CODE_SEL, .-GDT_BASE # Selector [0x10]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system data segment descriptor
-.equ SYS_DATA_SEL, .-GDT_BASE # Selector [0x18]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system code segment descriptor
-.equ SYS_CODE_SEL, .-GDT_BASE # Selector [0x20]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE3_SEL, .-GDT_BASE # Selector [0x28]
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-#
-# system data segment descriptor
-#
-.equ SYS_DATA64_SEL, .-GDT_BASE # Selector [0x30]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # P | DPL [1..2] | 1 | 1 | C | R | A
- .byte 0xCF # G | D | L | AVL | Segment [19..16]
- .byte 0
-
-#
-# system code segment descriptor
-#
-.equ SYS_CODE64_SEL, .-GDT_BASE # Selector [0x38]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # P | DPL [1..2] | 1 | 1 | C | R | A
- .byte 0xAF # G | D | L | AVL | Segment [19..16]
- .byte 0
-
-# spare segment descriptor
-.equ SPARE4_SEL, .-GDT_BASE # Selector [0x40]
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-GDT_END:
-
- .p2align 1
-
-
-
-idtr: .long IDT_END - IDT_BASE - 1 # IDT limit
- .quad 0 # (IDT base gets set above)
-
-##############################################################################
-# interrupt descriptor table (IDT)
-#
-# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-# mappings. This implementation only uses the system timer and all other
-# IRQs will remain masked. The descriptors for vectors 33+ are provided
-# for convenience.
-##############################################################################
-
-#idt_tag db "IDT",0
- .p2align 1
-
-
-IDT_BASE:
-# divide by zero (INT 0)
-.equ DIV_ZERO_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# debug exception (INT 1)
-.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# NMI (INT 2)
-.equ NMI_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# soft breakpoint (INT 3)
-.equ BREAKPOINT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# overflow (INT 4)
-.equ OVERFLOW_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# bounds check (INT 5)
-.equ BOUNDS_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# invalid opcode (INT 6)
-.equ INVALID_OPCODE_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# device not available (INT 7)
-.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# double fault (INT 8)
-.equ DOUBLE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Coprocessor segment overrun - reserved (INT 9)
-.equ RSVD_INTR_SEL1, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# invalid TSS (INT 0ah)
-.equ INVALID_TSS_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# segment not present (INT 0bh)
-.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# stack fault (INT 0ch)
-.equ STACK_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# general protection (INT 0dh)
-.equ GP_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# page fault (INT 0eh)
-.equ PAGE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Intel reserved - do not use (INT 0fh)
-.equ RSVD_INTR_SEL2, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# floating point error (INT 10h)
-.equ FLT_POINT_ERR_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# alignment check (INT 11h)
-.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# machine check (INT 12h)
-.equ MACHINE_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# SIMD floating-point exception (INT 13h)
-.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- .fill 85 * 16, 1, 0 # db (85 * 16) dup(0)
-
-# IRQ 0 (System timer) - (INT 68h)
-.equ IRQ0_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 1 (8042 Keyboard controller) - (INT 69h)
-.equ IRQ1_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-.equ IRQ2_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 3 (COM 2) - (INT 6bh)
-.equ IRQ3_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 4 (COM 1) - (INT 6ch)
-.equ IRQ4_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 5 (LPT 2) - (INT 6dh)
-.equ IRQ5_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 6 (Floppy controller) - (INT 6eh)
-.equ IRQ6_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 7 (LPT 1) - (INT 6fh)
-.equ IRQ7_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 8 (RTC Alarm) - (INT 70h)
-.equ IRQ8_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 9 - (INT 71h)
-.equ IRQ9_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 10 - (INT 72h)
-.equ IRQ10_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 11 - (INT 73h)
-.equ IRQ11_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 12 (PS/2 mouse) - (INT 74h)
-.equ IRQ12_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 13 (Floating point error) - (INT 75h)
-.equ IRQ13_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 14 (Secondary IDE) - (INT 76h)
-.equ IRQ14_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 15 (Primary IDE) - (INT 77h)
-.equ IRQ15_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-IDT_END:
-
- .p2align 1
-
-MemoryMapSize: .long 0
-MemoryMap: .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
-
- .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
-
- .org 0x0fe0
-MyStack:
- # below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- # back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- # known low address (20f00) so it can be set up by PlMapIrqToVect in
- # 8259.c
-
- int $8
- iret
-
- int $9
- iret
-
- int $10
- iret
-
- int $11
- iret
-
- int $12
- iret
-
- int $13
- iret
-
- int $14
- iret
-
- int $15
- iret
-
-
- .org 0x0ffe
-BlockSignature:
- .word 0xaa55
-
diff --git a/DuetPkg/BootSector/st16_64.asm b/DuetPkg/BootSector/st16_64.asm deleted file mode 100644 index 93a73d46bc..0000000000 --- a/DuetPkg/BootSector/st16_64.asm +++ /dev/null @@ -1,1140 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* st16_64.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-
-SectorSize dw 0 ; Sector Size - 16 bits
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits
-NoFats db 0 ; Number of FATs - 8 bits
-RootEntries dw 0 ; Root Entries - 16 bits
-Sectors dw 0 ; Number of Sectors - 16 bits
-Media db 0 ; Media - 8 bits - ignored
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
-Heads dw 0 ; Heads - 16 bits - ignored
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
-LargeSectors dd 0 ; Large Sectors - 32 bits
-PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
-CurrentHead db 0 ; Current Head - 8 bits
-Signature db 0 ; Signature - 8 bits - ignored
-VolId db " " ; Volume Serial Number- 4 bytes
-FatLabel db " " ; Label - 11 bytes
-SystemId db "FAT16 " ; SystemId - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
- ; ds = 1000, es = 2000 + x (size of first cluster >> 4)
- ; cx = Start Cluster of EfiLdr
- ; dx = Start Cluster of Efivar.bin
-
-; Re use the BPB data stored in Boot Sector
- mov bp,07c00h
-
- push cx
-; Read Efivar.bin
-; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- mov ax,01900h
- mov es,ax
- test dx,dx
- jnz CheckVarStoreSize
-
- mov al,1
-NoVarStore:
- push es
-; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- mov byte ptr es:[4],al
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- mov di,dx
- cmp dword ptr ds:[di+2], 04000h
- mov al,2
- jne NoVarStore
-
-LoadVarStore:
- mov al,0
- mov byte ptr es:[4],al
- mov cx,word ptr[di]
-; ES:DI = 1500:0
- xor di,di
- push es
- mov ax,01500h
- mov es,ax
- call ReadFile
-SaveVolumeId:
- pop es
- mov ax,word ptr [bp+VolId]
- mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- mov ax,word ptr [bp+VolId+2]
- mov word ptr es:[2],ax
-
-; Read Efildr
- pop cx
-; cx = Start Cluster of Efildr -> BS.com has filled already
-; ES:DI = 2000:0, first cluster will be read again
- xor di,di ; di = 0
- mov ax,02000h
- mov es,ax
- call ReadFile
- mov ax,cs
- mov word ptr cs:[JumpSegment],ax
-
-CheckEm64T:
- mov eax, 080000001h
-; cpuid
- dw 0A20Fh
- bt edx, 29
- jc CheckEm64TPass
- push cs
- pop ds
- lea si, [Em64String]
- mov cx, 18
- jmp PrintStringAndHalt
-CheckEm64TPass:
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0200h
-JumpSegment:
- dw 2000h
-
-
-
-; ****************************************************************************
-; ReadFile
-;
-; Arguments:
-; CX = Start Cluster of File
-; ES:DI = Buffer to store file content read from disk
-;
-; Return:
-; (ES << 4 + DI) = end of file content Buffer
-;
-; ****************************************************************************
-ReadFile:
-; si = NumberOfClusters
-; cx = ClusterNumber
-; dx = CachedFatSectorNumber
-; ds:0000 = CacheFatSectorBuffer
-; es:di = Buffer to load file
-; bx = NextClusterNumber
- pusha
- mov si,1 ; NumberOfClusters = 1
- push cx ; Push Start Cluster onto stack
- mov dx,0fffh ; CachedFatSectorNumber = 0xfff
-FatChainLoop:
- mov ax,cx ; ax = ClusterNumber
- and ax,0fff8h ; ax = ax & 0xfff8
- cmp ax,0fff8h ; See if this is the last cluster
- je FoundLastCluster ; Jump if last cluster found
- mov ax,cx ; ax = ClusterNumber
- shl ax,1 ; FatOffset = ClusterNumber * 2
- push si ; Save si
- mov si,ax ; si = FatOffset
- shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
- add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
- cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- mov bx,2
- push es
- push ds
- pop es
- call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
- pop es
- mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- mov bx,word ptr [si] ; bx = NextClusterNumber
- mov ax,cx ; ax = ClusterNumber
- pop si ; Restore si
- dec bx ; bx = NextClusterNumber - 1
- cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- inc bx ; bx = NextClusterNumber
- inc si ; NumberOfClusters++
- mov cx,bx ; ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- inc bx
- pop ax ; ax = StartCluster
- push bx ; StartCluster = NextClusterNumber
- mov cx,bx ; ClusterNumber = NextClusterNumber
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- push ax ; save start sector
- mov ax,si ; ax = NumberOfClusters
- mul bx ; ax = NumberOfClusters * SectorsPerCluster
- mov bx,ax ; bx = Number of Sectors
- pop ax ; ax = Start Sector
- call ReadBlocks
- mov si,1 ; NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- pop cx
- popa
- ret
-
-
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
-
- mov bx,word ptr [bp] ; bx = MaxSector
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push ax ; save ax
- mov ax,es ; ax = es
- shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
- and ax,07fh ; ax = Number of blocks into current seg
- add ax,bx ; ax = End Block number of transfer
- cmp ax,080h ; See if it crosses a 64K boundry
- jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
- sub ax,080h ; ax = Number of blocks past 64K boundry
- sub bx,ax ; Decrease transfer size by block overage
-NotCrossing64KBoundry:
- pop ax ; restore ax
-
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- push cs
- pop ds
- lea si, [ErrorString]
- mov cx, 7
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- mov ax,0b800h
- mov es,ax
- mov di,160
- rep movsw
-Halt:
- jmp Halt
-
-ErrorString:
- db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
- org 01feh
- dw 0aa55h
-
-;******************************************************************************
-;******************************************************************************
-;******************************************************************************
-
-DELAY_PORT equ 0edh ; Port to use for 1uS delay
-KBD_CONTROL_PORT equ 060h ; 8042 control port
-KBD_STATUS_PORT equ 064h ; 8042 status port
-WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
-ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
-
- org 200h
- jmp start
-Em64String:
- 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
-
-start:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,MyStack
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[160],'a'
-; mov ax,cs
-; mov es,ax
-
- mov ebx,0
- lea edi,MemoryMap
-MemMapLoop:
- mov eax,0e820h
- mov ecx,20
- mov edx,'SMAP'
- int 15h
- jc MemMapDone
- add edi,20
- cmp ebx,0
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- lea eax,MemoryMap
- sub edi,eax ; Get the address of the memory map
- mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
-
- xor ebx,ebx
- mov bx,cs ; BX=segment
- shl ebx,4 ; BX="linear" address of segment base
- lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
- mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
- lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
- mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
- lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[162],'b'
-; mov ax,cs
-; mov es,ax
-
-;
-; Enable A20 Gate
-;
-
- mov ax,2401h ; Enable A20 Gate
- int 15h
- jnc A20GateEnabled ; Jump if it suceeded
-
-;
-; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-;
-
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- out DELAY_PORT,ax ; Delay 1 uS
- mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
- out KBD_STATUS_PORT,al ; Send command to the 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- mov al,ENABLE_A20_CMD ; gate address bit 20 on
- out KBD_CONTROL_PORT,al ; Send command to thre 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- mov cx,25 ; Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- out DELAY_PORT,ax ; Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
-
-;
-; DISABLE INTERRUPTS - Entering Protected Mode
-;
-
- cli
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[164],'c'
-; mov ax,cs
-; mov es,ax
-
- lea eax, OffsetIn32BitProtectedMode
- add eax, 20000h + 6h
- mov dword ptr[OffsetIn32BitProtectedMode], eax
-
- lea eax, OffsetInLongMode
- add eax, 20000h + 6h
- mov dword ptr[OffsetInLongMode], eax
-
- ;
- ; load GDT
- ;
- db 66h
- lgdt fword ptr [gdtr]
-
- ;
- ; Enable Protect Mode (set CR0.PE=1)
- ;
- mov eax, cr0 ; Read CR0.
- or eax, 1h ; Set PE=1
- mov cr0, eax ; Write CR0.
- db 066h
- db 0eah ; jmp far 16:32
-OffsetIn32BitProtectedMode:
- dd 00000000h ; offset $+8 (In32BitProtectedMode)
- dw 10h ; selector (flat CS)
-In32BitProtectedMode:
-
-;
-; Entering Long Mode
-;
- db 66h
- mov ax, 8
- mov ds, ax
- mov es, ax
- mov ss, ax
-
- ;
- ; Enable the 64-bit page-translation-table entries by
- ; setting CR4.PAE=1 (this is _required_ before activating
- ; long mode). Paging is not enabled until after long mode
- ; is enabled.
- ;
- db 0fh
- db 20h
- db 0e0h
-; mov eax, cr4
- bts eax, 5
- db 0fh
- db 22h
- db 0e0h
-; mov cr4, eax
-
- ;
- ; This is the Trapolean Page Tables that are guarenteed
- ; under 4GB.
- ;
- ; Address Map:
- ; 10000 ~ 12000 - efildr (loaded)
- ; 20000 ~ 21000 - start64.com
- ; 21000 ~ 22000 - efi64.com
- ; 22000 ~ 90000 - efildr
- ; 90000 ~ 96000 - 4G pagetable (will be reload later)
- ;
- db 0b8h
- dd 90000h
-; mov eax, 90000h
- mov cr3, eax
-
- ;
- ; Enable long mode (set EFER.LME=1).
- ;
- db 0b9h
- dd 0c0000080h
-; mov ecx, 0c0000080h ; EFER MSR number.
- db 0fh
- db 32h
-; rdmsr ; Read EFER.
- db 0fh
- db 0bah
- db 0e8h
- db 08h
-; bts eax, 8 ; Set LME=1.
- db 0fh
- db 30h
-; wrmsr ; Write EFER.
-
- ;
- ; Enable paging to activate long mode (set CR0.PG=1)
- ;
- mov eax, cr0 ; Read CR0.
- db 0fh
- db 0bah
- db 0e8h
- db 01fh
-; bts eax, 31 ; Set PG=1.
- mov cr0, eax ; Write CR0.
- jmp GoToLongMode
-GoToLongMode:
-
- db 067h
- db 0eah ; Far Jump $+9:Selector to reload CS
-OffsetInLongMode:
- dd 00000000 ; $+9 Offset is ensuing instruction boundary
- dw 038h ; Selector is our code selector, 38h
-
-InLongMode:
- db 66h
- mov ax, 30h
- mov ds, ax
-
- db 66h
- mov ax, 18h
- mov es, ax
- mov ss, ax
- mov ds, ax
-
- db 0bdh
- dd 400000h
-; mov ebp,000400000h ; Destination of EFILDR32
- db 0bbh
- dd 70000h
-; mov ebx,000070000h ; Length of copy
-
- ;
- ; load idt later
- ;
- db 48h
- db 33h
- db 0c0h
-; xor rax, rax
- db 66h
- mov ax, offset idtr
- db 48h
- db 05h
- dd 20000h
-; add rax, 20000h
-
- db 0fh
- db 01h
- db 18h
-; lidt fword ptr [rax]
-
- db 48h
- db 0c7h
- db 0c0h
- dd 21000h
-; mov rax, 21000h
- db 50h
-; push rax
-
-; ret
- db 0c3h
-
-Empty8042InputBuffer:
- mov cx,0
-Empty8042Loop:
- out DELAY_PORT,ax ; Delay 1us
- in al,KBD_STATUS_PORT ; Read the 8042 Status Port
- and al,02h ; Check the Input Buffer Full Flag
- loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; data
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
- dd 0 ; (GDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; global descriptor table (GDT)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-public GDT_BASE
-GDT_BASE:
-; null descriptor
-NULL_SEL equ $-GDT_BASE ; Selector [0x0]
- dw 0 ; limit 15:0
- dw 0 ; base 15:0
- db 0 ; base 23:16
- db 0 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
-
-; linear data segment descriptor
-LINEAR_SEL equ $-GDT_BASE ; Selector [0x8]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; linear code segment descriptor
-LINEAR_CODE_SEL equ $-GDT_BASE ; Selector [0x10]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system data segment descriptor
-SYS_DATA_SEL equ $-GDT_BASE ; Selector [0x18]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system code segment descriptor
-SYS_CODE_SEL equ $-GDT_BASE ; Selector [0x20]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE3_SEL equ $-GDT_BASE ; Selector [0x28]
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-;
-; system data segment descriptor
-;
-SYS_DATA64_SEL equ $-GDT_BASE ; Selector [0x30]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; P | DPL [1..2] | 1 | 1 | C | R | A
- db 0CFh ; G | D | L | AVL | Segment [19..16]
- db 0
-
-;
-; system code segment descriptor
-;
-SYS_CODE64_SEL equ $-GDT_BASE ; Selector [0x38]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; P | DPL [1..2] | 1 | 1 | C | R | A
- db 0AFh ; G | D | L | AVL | Segment [19..16]
- db 0
-
-; spare segment descriptor
-SPARE4_SEL equ $-GDT_BASE ; Selector [0x40]
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-GDT_END:
-
- align 02h
-
-
-
-idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
- dq 0 ; (IDT base gets set above)
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; interrupt descriptor table (IDT)
-;
-; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-; mappings. This implementation only uses the system timer and all other
-; IRQs will remain masked. The descriptors for vectors 33+ are provided
-; for convenience.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;idt_tag db "IDT",0
- align 02h
-
-public IDT_BASE
-IDT_BASE:
-; divide by zero (INT 0)
-DIV_ZERO_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; debug exception (INT 1)
-DEBUG_EXCEPT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; NMI (INT 2)
-NMI_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; soft breakpoint (INT 3)
-BREAKPOINT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; overflow (INT 4)
-OVERFLOW_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; bounds check (INT 5)
-BOUNDS_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; invalid opcode (INT 6)
-INVALID_OPCODE_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; device not available (INT 7)
-DEV_NOT_AVAIL_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; double fault (INT 8)
-DOUBLE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Coprocessor segment overrun - reserved (INT 9)
-RSVD_INTR_SEL1 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; invalid TSS (INT 0ah)
-INVALID_TSS_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; segment not present (INT 0bh)
-SEG_NOT_PRESENT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; stack fault (INT 0ch)
-STACK_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; general protection (INT 0dh)
-GP_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; page fault (INT 0eh)
-PAGE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Intel reserved - do not use (INT 0fh)
-RSVD_INTR_SEL2 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; floating point error (INT 10h)
-FLT_POINT_ERR_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; alignment check (INT 11h)
-ALIGNMENT_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; machine check (INT 12h)
-MACHINE_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; SIMD floating-point exception (INT 13h)
-SIMD_EXCEPTION_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- db (85 * 16) dup(0)
-
-; IRQ 0 (System timer) - (INT 68h)
-IRQ0_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 1 (8042 Keyboard controller) - (INT 69h)
-IRQ1_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-IRQ2_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 3 (COM 2) - (INT 6bh)
-IRQ3_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 4 (COM 1) - (INT 6ch)
-IRQ4_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 5 (LPT 2) - (INT 6dh)
-IRQ5_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 6 (Floppy controller) - (INT 6eh)
-IRQ6_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 7 (LPT 1) - (INT 6fh)
-IRQ7_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 8 (RTC Alarm) - (INT 70h)
-IRQ8_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 9 - (INT 71h)
-IRQ9_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 10 - (INT 72h)
-IRQ10_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 11 - (INT 73h)
-IRQ11_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 12 (PS/2 mouse) - (INT 74h)
-IRQ12_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 13 (Floating point error) - (INT 75h)
-IRQ13_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 14 (Secondary IDE) - (INT 76h)
-IRQ14_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 15 (Primary IDE) - (INT 77h)
-IRQ15_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-IDT_END:
-
- align 02h
-
-MemoryMapSize dd 0
-MemoryMap dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
-
- 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
- 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
-
- org 0fe0h
-MyStack:
- ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- ; known low address (20f00) so it can be set up by PlMapIrqToVect in
- ; 8259.c
-
- int 8
- iret
-
- int 9
- iret
-
- int 10
- iret
-
- int 11
- iret
-
- int 12
- iret
-
- int 13
- iret
-
- int 14
- iret
-
- int 15
- iret
-
-
- org 0ffeh
-BlockSignature:
- dw 0aa55h
-
- end
diff --git a/DuetPkg/BootSector/st32_64.S b/DuetPkg/BootSector/st32_64.S deleted file mode 100644 index 18c53f81fa..0000000000 --- a/DuetPkg/BootSector/st32_64.S +++ /dev/null @@ -1,1157 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* st32_64.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
-
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
- .org 0x0
-
-.global _start
-_start:
-
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-SectorSize: .word 0 # Sector Size - 2 bytes
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 1 byte
-ReservedSectors: .word 0 # Reserved Sectors - 2 bytes
-NoFats: .byte 0 # Number of FATs - 1 byte
-RootEntries: .word 0 # Root Entries - 2 bytes
-Sectors: .word 0 # Number of Sectors - 2 bytes
-Media: .byte 0 # Media - 1 byte
-SectorsPerFat16: .word 0 # Sectors Per FAT for FAT12/FAT16 - 2 byte
-SectorsPerTrack: .word 0 # Sectors Per Track - 2 bytes
-Heads: .word 0 # Heads - 2 bytes
-HiddenSectors: .long 0 # Hidden Sectors - 4 bytes
-LargeSectors: .long 0 # Large Sectors - 4 bytes
-
-#******************************************************************************
-#
-#The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
-#the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
-#
-#******************************************************************************
-
-SectorsPerFat32: .long 0 # Sectors Per FAT for FAT32 - 4 bytes
-ExtFlags: .word 0 # Mirror Flag - 2 bytes
-FSVersion: .word 0 # File System Version - 2 bytes
-RootCluster: .long 0 # 1st Cluster Number of Root Dir - 4 bytes
-FSInfo: .word 0 # Sector Number of FSINFO - 2 bytes
-BkBootSector: .word 0 # Sector Number of Bk BootSector - 2 bytes
-Reserved: .fill 12,1,0 # Reserved Field - 12 bytes
-PhysicalDrive: .byte 0 # Physical Drive Number - 1 byte
-Reserved1: .byte 0 # Reserved Field - 1 byte
-Signature: .byte 0 # Extended Boot Signature - 1 byte
-VolId: .ascii " " # Volume Serial Number - 4 bytes
-FatLabel: .ascii " " # Volume Label - 11 bytes
-FileSystemType: .ascii "FAT32 " # File System Type - 8 bytes
-
-
-BootSectorEntryPoint:
- # ASSUME ds:@code
- # ASSUME ss:@code
- # ds = 1000, es = 2000 + x (size of first cluster >> 4)
- # cx = Start Cluster of EfiLdr
- # dx = Start Cluster of Efivar.bin
-
-# Re use the BPB data stored in Boot Sector
- movw $0x7c00,%bp
-
- pushw %cx
-# Read Efivar.bin
-# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- movw $0x1900,%ax
- movw %ax,%es
- testw %dx,%dx
- jnz CheckVarStoreSize
-
- movb $1,%al
-NoVarStore:
- pushw %es
-# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- movb %al, %es:(4)
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- movw %dx,%di
- cmpl $0x4000, %ds:2(%di)
- movb $2,%al
- jne NoVarStore
-
-LoadVarStore:
- movb $0,%al
- movb %al, %es:(4)
- movw (%di), %cx
-# ES:DI = 1500:0
- xorw %di,%di
- pushw %es
- movw $0x1500,%ax
- movw %ax,%es
- call ReadFile
-SaveVolumeId:
- popw %es
- movw VolId(%bp), %ax
- movw %ax, %es:(0) # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- movw VolId+2(%bp), %ax
- movw %ax, %es:(2)
-
-# Read Efildr
- popw %cx
-# cx = Start Cluster of Efildr -> BS.com has filled already
-# ES:DI = 2000:0, first cluster will be read again
- xorw %di,%di # di = 0
- movw $0x2000,%ax
- movw %ax,%es
- call ReadFile
- movw %cs,%ax
- movw %ax, %cs:JumpSegment
-
-CheckEm64T:
- movl $0x80000001,%eax
-# cpuid
- .word 0xA20F
- btl $29,%edx
- jc CheckEm64TPass
- pushw %cs
- popw %ds
- leaw Em64String,%si
- movw $18,%cx
- jmp PrintStringAndHalt
-CheckEm64TPass:
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x200
-JumpSegment:
- .word 0x2000
-
-
-
-# ****************************************************************************
-# ReadFile
-#
-# Arguments:
-# CX = Start Cluster of File
-# ES:DI = Buffer to store file content read from disk
-#
-# Return:
-# (ES << 4 + DI) = end of file content Buffer
-#
-# ****************************************************************************
-ReadFile:
-# si = NumberOfClusters
-# cx = ClusterNumber
-# dx = CachedFatSectorNumber
-# ds:0000 = CacheFatSectorBuffer
-# es:di = Buffer to load file
-# bx = NextClusterNumber
- pusha
- movw $1,%si # NumberOfClusters = 1
- pushw %cx # Push Start Cluster onto stack
- movw $0xfff,%dx # CachedFatSectorNumber = 0xfff
-FatChainLoop:
- movw %cx,%ax # ax = ClusterNumber
- andw $0xfff8,%ax # ax = ax & 0xfff8
- cmpw $0xfff8,%ax # See if this is the last cluster
- je FoundLastCluster # Jump if last cluster found
- movw %cx,%ax # ax = ClusterNumber
- shlw $2, %ax # FatOffset = ClusterNumber * 2
- pushw %si # Save si
- movw %ax,%si # si = FatOffset
- shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
- addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK
- cmpw %dx,%ax # Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- movw $2,%bx
- pushw %es
- pushw %ds
- popw %es
- call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
- popw %es
- movw %ax,%dx # CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- movw (%si), %bx # bx = NextClusterNumber
- movw %cx,%ax # ax = ClusterNumber
- popw %si # Restore si
- decw %bx # bx = NextClusterNumber - 1
- cmpw %cx,%bx # See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- incw %bx # bx = NextClusterNumber
- incw %si # NumberOfClusters++
- movw %bx,%cx # ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- incw %bx
- popw %ax # ax = StartCluster
- pushw %bx # StartCluster = NextClusterNumber
- movw %bx,%cx # ClusterNumber = NextClusterNumber
- subw $2,%ax # ax = StartCluster - 2
- xorb %bh,%bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- pushw %ax # save start sector
- movw %si,%ax # ax = NumberOfClusters
- mulw %bx # ax = NumberOfClusters * SectorsPerCluster
- movw %ax,%bx # bx = Number of Sectors
- popw %ax # ax = Start Sector
- call ReadBlocks
- movw $1,%si # NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- popw %cx
- popa
- ret
-
-
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax,%esi # esi = Start LBA
- movw %bx,%cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc,%bp # bp = 0x7bfc
- movl %esi,%eax # eax = Start LBA
- xorl %edx,%edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
-
- movw (%bp), %bx # bx = MaxSector
- subw %dx,%bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx,%cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx,%bx # bx = Blocks
-LimitTransfer:
- pushw %ax # save ax
- movw %es,%ax # ax = es
- shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
- andw $0x7f,%ax # ax = Number of blocks into current seg
- addw %bx,%ax # ax = End Block number of transfer
- cmpw $0x80,%ax # See if it crosses a 64K boundry
- jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
- subw $0x80,%ax # ax = Number of blocks past 64K boundry
- subw %ax,%bx # Decrease transfer size by block overage
-NotCrossing64KBoundry:
- popw %ax # restore ax
-
- pushw %cx
- movb %dl,%cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx,%dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl,%dh # dh = Head
- movw $0x7c00,%bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al,%ch # ch = Cylinder
- movb %bl,%al # al = Blocks
- movb $2,%ah # ah = Function 2
- movw %di,%bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx,%ebx
- addl %ebx,%esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx,%cx # Blocks = Blocks - NumberOfBlocks
- movw %es,%ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx,%ax
- movw %ax,%es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0,%cx
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- pushw %cs
- popw %ds
- leaw ErrorString,%si
- movw $7,%cx
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- movw $0xb800,%ax
- movw %ax,%es
- movw $160,%di
- rep
- movsw
-Halt:
- jmp Halt
-
-ErrorString:
- .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c
-
- .org 0x01fa
-LBAOffsetForBootSector:
- .long 0x0
-
- .org 0x01fe
- .word 0xaa55
-
-#******************************************************************************
-#******************************************************************************
-#******************************************************************************
-
-.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
-.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
-.equ KBD_STATUS_PORT, 0x064 # 8042 status port
-.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
-.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
-
- .org 0x200
- jmp start
-Em64String:
-.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
-
-start:
- movw %cs,%ax
- movw %ax,%ds
- movw %ax,%es
- movw %ax,%ss
- movw $MyStack, %sp
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[160],'a'
-# mov ax,cs
-# mov es,ax
-
- movl $0,%ebx
- leal MemoryMap, %edi
-MemMapLoop:
- movl $0xe820,%eax
- movl $20,%ecx
- movl $0x534d4150, %edx # SMAP
- int $0x15
- jc MemMapDone
- addl $20,%edi
- cmpl $0,%ebx
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- leal MemoryMap, %eax
- subl %eax,%edi # Get the address of the memory map
- movl %edi, MemoryMapSize # Save the size of the memory map
-
- xorl %ebx,%ebx
- movw %cs,%bx # BX=segment
- shll $4,%ebx # BX="linear" address of segment base
- leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
- movl %eax, (gdtr + 2) # Put address of gdt into the gdtr
- leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
- movl %eax, (idtr + 2) # Put address of idt into the idtr
- leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[162],'b'
-# mov ax,cs
-# mov es,ax
-
-#
-# Enable A20 Gate
-#
-
- movw $0x2401,%ax # Enable A20 Gate
- int $0x15
- jnc A20GateEnabled # Jump if it suceeded
-
-#
-# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-#
-
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- outw %ax, $DELAY_PORT # Delay 1 uS
- movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
- outb %al, $KBD_STATUS_PORT # Send command to the 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- movb $ENABLE_A20_CMD, %al # gate address bit 20 on
- outb %al, $KBD_CONTROL_PORT # Send command to thre 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- movw $25,%cx # Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- outw %ax, $DELAY_PORT # Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
-
-#
-# DISABLE INTERRUPTS - Entering Protected Mode
-#
-
- cli
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[164],'c'
-# mov ax,cs
-# mov es,ax
-
- leal OffsetIn32BitProtectedMode, %eax
- addl $0x20000+0x6,%eax
- movl %eax, OffsetIn32BitProtectedMode
-
- leal OffsetInLongMode, %eax
- addl $0x20000+0x6,%eax
- movl %eax, OffsetInLongMode
-
- #
- # load GDT
- #
- .byte 0x66
- lgdt gdtr
-
- #
- # Enable Protect Mode (set CR0.PE=1)
- #
- movl %cr0, %eax # Read CR0.
- orl $0x1,%eax # Set PE=1
- movl %eax, %cr0 # Write CR0.
- .byte 0x66
- .byte 0xea # jmp far 16:32
-OffsetIn32BitProtectedMode:
- .long 0x0000000 # offset $+8 (In32BitProtectedMode)
- .word 0x10 # selector (flat CS)
-In32BitProtectedMode:
-
-#
-# Entering Long Mode
-#
- .byte 0x66
- movw $8,%ax
- movw %ax,%ds
- movw %ax,%es
- movw %ax,%ss
-
- #
- # Enable the 64-bit page-translation-table entries by
- # setting CR4.PAE=1 (this is _required_ before activating
- # long mode). Paging is not enabled until after long mode
- # is enabled.
- #
- .byte 0xf
- .byte 0x20
- .byte 0xe0
-# mov eax, cr4
- btsl $5,%eax
- .byte 0xf
- .byte 0x22
- .byte 0xe0
-# mov cr4, eax
-
- #
- # This is the Trapolean Page Tables that are guarenteed
- # under 4GB.
- #
- # Address Map:
- # 10000 ~ 12000 - efildr (loaded)
- # 20000 ~ 21000 - start64.com
- # 21000 ~ 22000 - efi64.com
- # 22000 ~ 90000 - efildr
- # 90000 ~ 96000 - 4G pagetable (will be reload later)
- #
- .byte 0xb8
- .long 0x90000
-# mov eax, 90000h
- movl %eax, %cr3
-
- #
- # Enable long mode (set EFER.LME=1).
- #
- .byte 0xb9
- .long 0xc0000080
-# mov ecx, 0c0000080h ; EFER MSR number.
- .byte 0xf
- .byte 0x32
-# rdmsr ; Read EFER.
- .byte 0xf
- .byte 0xba
- .byte 0xe8
- .byte 0x8
-# bts eax, 8 ; Set LME=1.
- .byte 0xf
- .byte 0x30
-# wrmsr ; Write EFER.
-
- #
- # Enable paging to activate long mode (set CR0.PG=1)
- #
- movl %cr0, %eax # Read CR0.
- .byte 0xf
- .byte 0xba
- .byte 0xe8
- .byte 0x1f
-# bts eax, 31 ; Set PG=1.
- movl %eax, %cr0 # Write CR0.
- jmp GoToLongMode
-GoToLongMode:
-
- .byte 0x67
- .byte 0xea # Far Jump $+9:Selector to reload CS
-OffsetInLongMode:
- .long 00000000 # $+9 Offset is ensuing instruction boundary
- .word 0x38 # Selector is our code selector, 38h
-
-InLongMode:
- .byte 0x66
- movw $0x30,%ax
- movw %ax,%ds
-
- .byte 0x66
- movw $0x18,%ax
- movw %ax,%es
- movw %ax,%ss
- movw %ax,%ds
-
- .byte 0xbd
- .long 0x400000
-# mov ebp,000400000h ; Destination of EFILDR32
- .byte 0xbb
- .long 0x70000
-# mov ebx,000070000h ; Length of copy
-
- #
- # load idt later
- #
- .byte 0x48
- .byte 0x33
- .byte 0xc0
-# xor rax, rax
- .byte 0x66
- movw $idtr, %ax
- .byte 0x48
- .byte 0x5
- .long 0x20000
-# add rax, 20000h
-
- .byte 0xf
- .byte 0x1
- .byte 0x18
-# lidt fword ptr [rax]
-
- .byte 0x48
- .byte 0xc7
- .byte 0xc0
- .long 0x21000
-# mov rax, 21000h
- .byte 0x50
-# push rax
-
-# ret
- .byte 0xc3
-
-Empty8042InputBuffer:
- movw $0,%cx
-Empty8042Loop:
- outw %ax, $DELAY_PORT # Delay 1us
- inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port
- andb $0x2,%al # Check the Input Buffer Full Flag
- loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-##############################################################################
-# data
-##############################################################################
-
- .p2align 1
-
- gdtr: .word GDT_END - GDT_BASE - 1 # GDT limit
- .long 0 # (GDT base gets set above)
-##############################################################################
-# global descriptor table (GDT)
-##############################################################################
-
- .p2align 1
-
-GDT_BASE:
-# null descriptor
-.equ NULL_SEL, .-GDT_BASE # Selector [0x0]
- .word 0 # limit 15:0
- .word 0 # base 15:0
- .byte 0 # base 23:16
- .byte 0 # type
- .byte 0 # limit 19:16, flags
- .byte 0 # base 31:24
-
-# linear data segment descriptor
-.equ LINEAR_SEL, .-GDT_BASE # Selector [0x8]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# linear code segment descriptor
-.equ LINEAR_CODE_SEL, .-GDT_BASE # Selector [0x10]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system data segment descriptor
-.equ SYS_DATA_SEL, .-GDT_BASE # Selector [0x18]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system code segment descriptor
-.equ SYS_CODE_SEL, .-GDT_BASE # Selector [0x20]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE3_SEL, .-GDT_BASE # Selector [0x28]
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-#
-# system data segment descriptor
-#
-.equ SYS_DATA64_SEL, .-GDT_BASE # Selector [0x30]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # P | DPL [1..2] | 1 | 1 | C | R | A
- .byte 0xCF # G | D | L | AVL | Segment [19..16]
- .byte 0
-
-#
-# system code segment descriptor
-#
-.equ SYS_CODE64_SEL, .-GDT_BASE # Selector [0x38]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # P | DPL [1..2] | 1 | 1 | C | R | A
- .byte 0xAF # G | D | L | AVL | Segment [19..16]
- .byte 0
-
-# spare segment descriptor
-.equ SPARE4_SEL, .-GDT_BASE # Selector [0x40]
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-GDT_END:
-
- .p2align 1
-
-
-
-idtr: .long IDT_END - IDT_BASE - 1 # IDT limit
- .quad 0 # (IDT base gets set above)
-
-##############################################################################
-# interrupt descriptor table (IDT)
-#
-# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-# mappings. This implementation only uses the system timer and all other
-# IRQs will remain masked. The descriptors for vectors 33+ are provided
-# for convenience.
-##############################################################################
-
-#idt_tag db "IDT",0
- .p2align 1
-
-
-IDT_BASE:
-# divide by zero (INT 0)
-.equ DIV_ZERO_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# debug exception (INT 1)
-.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# NMI (INT 2)
-.equ NMI_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# soft breakpoint (INT 3)
-.equ BREAKPOINT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# overflow (INT 4)
-.equ OVERFLOW_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# bounds check (INT 5)
-.equ BOUNDS_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# invalid opcode (INT 6)
-.equ INVALID_OPCODE_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# device not available (INT 7)
-.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# double fault (INT 8)
-.equ DOUBLE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Coprocessor segment overrun - reserved (INT 9)
-.equ RSVD_INTR_SEL1, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# invalid TSS (INT 0ah)
-.equ INVALID_TSS_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# segment not present (INT 0bh)
-.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# stack fault (INT 0ch)
-.equ STACK_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# general protection (INT 0dh)
-.equ GP_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# page fault (INT 0eh)
-.equ PAGE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Intel reserved - do not use (INT 0fh)
-.equ RSVD_INTR_SEL2, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# floating point error (INT 10h)
-.equ FLT_POINT_ERR_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# alignment check (INT 11h)
-.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# machine check (INT 12h)
-.equ MACHINE_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# SIMD floating-point exception (INT 13h)
-.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- .fill 85 * 16, 1, 0 # db (85 * 16) dup(0)
-
-# IRQ 0 (System timer) - (INT 68h)
-.equ IRQ0_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 1 (8042 Keyboard controller) - (INT 69h)
-.equ IRQ1_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-.equ IRQ2_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 3 (COM 2) - (INT 6bh)
-.equ IRQ3_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 4 (COM 1) - (INT 6ch)
-.equ IRQ4_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 5 (LPT 2) - (INT 6dh)
-.equ IRQ5_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 6 (Floppy controller) - (INT 6eh)
-.equ IRQ6_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 7 (LPT 1) - (INT 6fh)
-.equ IRQ7_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 8 (RTC Alarm) - (INT 70h)
-.equ IRQ8_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 9 - (INT 71h)
-.equ IRQ9_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 10 - (INT 72h)
-.equ IRQ10_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 11 - (INT 73h)
-.equ IRQ11_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 12 (PS/2 mouse) - (INT 74h)
-.equ IRQ12_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 13 (Floating point error) - (INT 75h)
-.equ IRQ13_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 14 (Secondary IDE) - (INT 76h)
-.equ IRQ14_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 15 (Primary IDE) - (INT 77h)
-.equ IRQ15_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-IDT_END:
-
- .p2align 1
-
-MemoryMapSize: .long 0
-MemoryMap: .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
-
- .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
-
- .org 0x0fe0
-MyStack:
- # below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- # back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- # known low address (20f00) so it can be set up by PlMapIrqToVect in
- # 8259.c
-
- int $8
- iret
-
- int $9
- iret
-
- int $10
- iret
-
- int $11
- iret
-
- int $12
- iret
-
- int $13
- iret
-
- int $14
- iret
-
- int $15
- iret
-
-
- .org 0x0ffe
-BlockSignature:
- .word 0xaa55
-
diff --git a/DuetPkg/BootSector/st32_64.asm b/DuetPkg/BootSector/st32_64.asm deleted file mode 100644 index 9761dc883b..0000000000 --- a/DuetPkg/BootSector/st32_64.asm +++ /dev/null @@ -1,1156 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* st32_64.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-SectorSize dw 0 ; Sector Size - 2 bytes
-SectorsPerCluster db 0 ; Sector Per Cluster - 1 byte
-ReservedSectors dw 0 ; Reserved Sectors - 2 bytes
-NoFats db 0 ; Number of FATs - 1 byte
-RootEntries dw 0 ; Root Entries - 2 bytes
-Sectors dw 0 ; Number of Sectors - 2 bytes
-Media db 0 ; Media - 1 byte
-SectorsPerFat16 dw 0 ; Sectors Per FAT for FAT12/FAT16 - 2 byte
-SectorsPerTrack dw 0 ; Sectors Per Track - 2 bytes
-Heads dw 0 ; Heads - 2 bytes
-HiddenSectors dd 0 ; Hidden Sectors - 4 bytes
-LargeSectors dd 0 ; Large Sectors - 4 bytes
-
-;******************************************************************************
-;
-;The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
-;the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
-;
-;******************************************************************************
-
-SectorsPerFat32 dd 0 ; Sectors Per FAT for FAT32 - 4 bytes
-ExtFlags dw 0 ; Mirror Flag - 2 bytes
-FSVersion dw 0 ; File System Version - 2 bytes
-RootCluster dd 0 ; 1st Cluster Number of Root Dir - 4 bytes
-FSInfo dw 0 ; Sector Number of FSINFO - 2 bytes
-BkBootSector dw 0 ; Sector Number of Bk BootSector - 2 bytes
-Reserved db 12 dup(0) ; Reserved Field - 12 bytes
-PhysicalDrive db 0 ; Physical Drive Number - 1 byte
-Reserved1 db 0 ; Reserved Field - 1 byte
-Signature db 0 ; Extended Boot Signature - 1 byte
-VolId db " " ; Volume Serial Number - 4 bytes
-FatLabel db " " ; Volume Label - 11 bytes
-FileSystemType db "FAT32 " ; File System Type - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
- ; ds = 1000, es = 2000 + x (size of first cluster >> 4)
- ; cx = Start Cluster of EfiLdr
- ; dx = Start Cluster of Efivar.bin
-
-; Re use the BPB data stored in Boot Sector
- mov bp,07c00h
-
-
- push cx
-; Read Efivar.bin
-; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- mov ax,01900h
- mov es,ax
- test dx,dx
- jnz CheckVarStoreSize
-
- mov al,1
-NoVarStore:
- push es
-; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- mov byte ptr es:[4],al
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- mov di,dx
- cmp dword ptr ds:[di+2], 04000h
- mov al,2
- jne NoVarStore
-
-LoadVarStore:
- mov al,0
- mov byte ptr es:[4],al
- mov cx,word ptr[di]
-; ES:DI = 1500:0
- xor di,di
- push es
- mov ax,01500h
- mov es,ax
- call ReadFile
-SaveVolumeId:
- pop es
- mov ax,word ptr [bp+VolId]
- mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- mov ax,word ptr [bp+VolId+2]
- mov word ptr es:[2],ax
-
-; Read Efildr
- pop cx
-; cx = Start Cluster of Efildr -> BS.com has filled already
-; ES:DI = 2000:0, first cluster will be read again
- xor di,di ; di = 0
- mov ax,02000h
- mov es,ax
- call ReadFile
- mov ax,cs
- mov word ptr cs:[JumpSegment],ax
-
-CheckEm64T:
- mov eax, 080000001h
-; cpuid
- dw 0A20Fh
- bt edx, 29
- jc CheckEm64TPass
- push cs
- pop ds
- lea si, [Em64String]
- mov cx, 18
- jmp PrintStringAndHalt
-CheckEm64TPass:
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0200h
-JumpSegment:
- dw 2000h
-
-
-
-
-; ****************************************************************************
-; ReadFile
-;
-; Arguments:
-; CX = Start Cluster of File
-; ES:DI = Buffer to store file content read from disk
-;
-; Return:
-; (ES << 4 + DI) = end of file content Buffer
-;
-; ****************************************************************************
-ReadFile:
-; si = NumberOfClusters
-; cx = ClusterNumber
-; dx = CachedFatSectorNumber
-; ds:0000 = CacheFatSectorBuffer
-; es:di = Buffer to load file
-; bx = NextClusterNumber
- pusha
- mov si,1 ; NumberOfClusters = 1
- push cx ; Push Start Cluster onto stack
- mov dx,0fffh ; CachedFatSectorNumber = 0xfff
-FatChainLoop:
- mov ax,cx ; ax = ClusterNumber
- and ax,0fff8h ; ax = ax & 0xfff8
- cmp ax,0fff8h ; See if this is the last cluster
- je FoundLastCluster ; Jump if last cluster found
- mov ax,cx ; ax = ClusterNumber
- shl ax,2 ; FatOffset = ClusterNumber * 4
- push si ; Save si
- mov si,ax ; si = FatOffset
- shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
- add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
- cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- mov bx,2
- push es
- push ds
- pop es
- call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
- pop es
- mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- mov bx,word ptr [si] ; bx = NextClusterNumber
- mov ax,cx ; ax = ClusterNumber
- pop si ; Restore si
- dec bx ; bx = NextClusterNumber - 1
- cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- inc bx ; bx = NextClusterNumber
- inc si ; NumberOfClusters++
- mov cx,bx ; ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- inc bx
- pop ax ; ax = StartCluster
- push bx ; StartCluster = NextClusterNumber
- mov cx,bx ; ClusterNumber = NextClusterNumber
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- push ax ; save start sector
- mov ax,si ; ax = NumberOfClusters
- mul bx ; ax = NumberOfClusters * SectorsPerCluster
- mov bx,ax ; bx = Number of Sectors
- pop ax ; ax = Start Sector
- call ReadBlocks
- mov si,1 ; NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- pop cx
- popa
- ret
-
-
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
-
- mov bx,word ptr [bp] ; bx = MaxSector
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push ax ; save ax
- mov ax,es ; ax = es
- shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
- and ax,07fh ; ax = Number of blocks into current seg
- add ax,bx ; ax = End Block number of transfer
- cmp ax,080h ; See if it crosses a 64K boundry
- jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
- sub ax,080h ; ax = Number of blocks past 64K boundry
- sub bx,ax ; Decrease transfer size by block overage
-NotCrossing64KBoundry:
- pop ax ; restore ax
-
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- push cs
- pop ds
- lea si, [ErrorString]
- mov cx, 7
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- mov ax,0b800h
- mov es,ax
- mov di,160
- rep movsw
-Halt:
- jmp Halt
-
-ErrorString:
- db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
- org 01feh
- dw 0aa55h
-
-;******************************************************************************
-;******************************************************************************
-;******************************************************************************
-
-DELAY_PORT equ 0edh ; Port to use for 1uS delay
-KBD_CONTROL_PORT equ 060h ; 8042 control port
-KBD_STATUS_PORT equ 064h ; 8042 status port
-WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
-ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
-
- org 200h
- jmp start
-Em64String:
- 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
-
-start:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,MyStack
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[160],'a'
-; mov ax,cs
-; mov es,ax
-
- mov ebx,0
- lea edi,MemoryMap
-MemMapLoop:
- mov eax,0e820h
- mov ecx,20
- mov edx,'SMAP'
- int 15h
- jc MemMapDone
- add edi,20
- cmp ebx,0
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- lea eax,MemoryMap
- sub edi,eax ; Get the address of the memory map
- mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
-
- xor ebx,ebx
- mov bx,cs ; BX=segment
- shl ebx,4 ; BX="linear" address of segment base
- lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
- mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
- lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
- mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
- lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[162],'b'
-; mov ax,cs
-; mov es,ax
-
-;
-; Enable A20 Gate
-;
-
- mov ax,2401h ; Enable A20 Gate
- int 15h
- jnc A20GateEnabled ; Jump if it suceeded
-
-;
-; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-;
-
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- out DELAY_PORT,ax ; Delay 1 uS
- mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
- out KBD_STATUS_PORT,al ; Send command to the 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- mov al,ENABLE_A20_CMD ; gate address bit 20 on
- out KBD_CONTROL_PORT,al ; Send command to thre 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- mov cx,25 ; Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- out DELAY_PORT,ax ; Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
-
-;
-; DISABLE INTERRUPTS - Entering Protected Mode
-;
-
- cli
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[164],'c'
-; mov ax,cs
-; mov es,ax
-
- lea eax, OffsetIn32BitProtectedMode
- add eax, 20000h + 6h
- mov dword ptr[OffsetIn32BitProtectedMode], eax
-
- lea eax, OffsetInLongMode
- add eax, 20000h + 6h
- mov dword ptr[OffsetInLongMode], eax
-
- ;
- ; load GDT
- ;
- db 66h
- lgdt fword ptr [gdtr]
-
- ;
- ; Enable Protect Mode (set CR0.PE=1)
- ;
- mov eax, cr0 ; Read CR0.
- or eax, 1h ; Set PE=1
- mov cr0, eax ; Write CR0.
- db 066h
- db 0eah ; jmp far 16:32
-OffsetIn32BitProtectedMode:
- dd 00000000h ; offset $+8 (In32BitProtectedMode)
- dw 10h ; selector (flat CS)
-In32BitProtectedMode:
-
-;
-; Entering Long Mode
-;
- db 66h
- mov ax, 8
- mov ds, ax
- mov es, ax
- mov ss, ax
-
- ;
- ; Enable the 64-bit page-translation-table entries by
- ; setting CR4.PAE=1 (this is _required_ before activating
- ; long mode). Paging is not enabled until after long mode
- ; is enabled.
- ;
- db 0fh
- db 20h
- db 0e0h
-; mov eax, cr4
- bts eax, 5
- db 0fh
- db 22h
- db 0e0h
-; mov cr4, eax
-
- ;
- ; This is the Trapolean Page Tables that are guarenteed
- ; under 4GB.
- ;
- ; Address Map:
- ; 10000 ~ 12000 - efildr (loaded)
- ; 20000 ~ 21000 - start64.com
- ; 21000 ~ 22000 - efi64.com
- ; 22000 ~ 90000 - efildr
- ; 90000 ~ 96000 - 4G pagetable (will be reload later)
- ;
- db 0b8h
- dd 90000h
-; mov eax, 90000h
- mov cr3, eax
-
- ;
- ; Enable long mode (set EFER.LME=1).
- ;
- db 0b9h
- dd 0c0000080h
-; mov ecx, 0c0000080h ; EFER MSR number.
- db 0fh
- db 32h
-; rdmsr ; Read EFER.
- db 0fh
- db 0bah
- db 0e8h
- db 08h
-; bts eax, 8 ; Set LME=1.
- db 0fh
- db 30h
-; wrmsr ; Write EFER.
-
- ;
- ; Enable paging to activate long mode (set CR0.PG=1)
- ;
- mov eax, cr0 ; Read CR0.
- db 0fh
- db 0bah
- db 0e8h
- db 01fh
-; bts eax, 31 ; Set PG=1.
- mov cr0, eax ; Write CR0.
- jmp GoToLongMode
-GoToLongMode:
-
- db 067h
- db 0eah ; Far Jump $+9:Selector to reload CS
-OffsetInLongMode:
- dd 00000000 ; $+9 Offset is ensuing instruction boundary
- dw 038h ; Selector is our code selector, 38h
-
-InLongMode:
- db 66h
- mov ax, 30h
- mov ds, ax
-
- db 66h
- mov ax, 18h
- mov es, ax
- mov ss, ax
- mov ds, ax
-
- db 0bdh
- dd 400000h
-; mov ebp,000400000h ; Destination of EFILDR32
- db 0bbh
- dd 70000h
-; mov ebx,000070000h ; Length of copy
-
- ;
- ; load idt later
- ;
- db 48h
- db 33h
- db 0c0h
-; xor rax, rax
- db 66h
- mov ax, offset idtr
- db 48h
- db 05h
- dd 20000h
-; add rax, 20000h
-
- db 0fh
- db 01h
- db 18h
-; lidt fword ptr [rax]
-
- db 48h
- db 0c7h
- db 0c0h
- dd 21000h
-; mov rax, 21000h
- db 50h
-; push rax
-
-; ret
- db 0c3h
-
-Empty8042InputBuffer:
- mov cx,0
-Empty8042Loop:
- out DELAY_PORT,ax ; Delay 1us
- in al,KBD_STATUS_PORT ; Read the 8042 Status Port
- and al,02h ; Check the Input Buffer Full Flag
- loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; data
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
- dd 0 ; (GDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; global descriptor table (GDT)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-public GDT_BASE
-GDT_BASE:
-; null descriptor
-NULL_SEL equ $-GDT_BASE ; Selector [0x0]
- dw 0 ; limit 15:0
- dw 0 ; base 15:0
- db 0 ; base 23:16
- db 0 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
-
-; linear data segment descriptor
-LINEAR_SEL equ $-GDT_BASE ; Selector [0x8]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; linear code segment descriptor
-LINEAR_CODE_SEL equ $-GDT_BASE ; Selector [0x10]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system data segment descriptor
-SYS_DATA_SEL equ $-GDT_BASE ; Selector [0x18]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system code segment descriptor
-SYS_CODE_SEL equ $-GDT_BASE ; Selector [0x20]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE3_SEL equ $-GDT_BASE ; Selector [0x28]
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-;
-; system data segment descriptor
-;
-SYS_DATA64_SEL equ $-GDT_BASE ; Selector [0x30]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; P | DPL [1..2] | 1 | 1 | C | R | A
- db 0CFh ; G | D | L | AVL | Segment [19..16]
- db 0
-
-;
-; system code segment descriptor
-;
-SYS_CODE64_SEL equ $-GDT_BASE ; Selector [0x38]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; P | DPL [1..2] | 1 | 1 | C | R | A
- db 0AFh ; G | D | L | AVL | Segment [19..16]
- db 0
-
-; spare segment descriptor
-SPARE4_SEL equ $-GDT_BASE ; Selector [0x40]
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-GDT_END:
-
- align 02h
-
-
-
-idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
- dq 0 ; (IDT base gets set above)
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; interrupt descriptor table (IDT)
-;
-; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-; mappings. This implementation only uses the system timer and all other
-; IRQs will remain masked. The descriptors for vectors 33+ are provided
-; for convenience.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;idt_tag db "IDT",0
- align 02h
-
-public IDT_BASE
-IDT_BASE:
-; divide by zero (INT 0)
-DIV_ZERO_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; debug exception (INT 1)
-DEBUG_EXCEPT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; NMI (INT 2)
-NMI_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; soft breakpoint (INT 3)
-BREAKPOINT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; overflow (INT 4)
-OVERFLOW_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; bounds check (INT 5)
-BOUNDS_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; invalid opcode (INT 6)
-INVALID_OPCODE_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; device not available (INT 7)
-DEV_NOT_AVAIL_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; double fault (INT 8)
-DOUBLE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Coprocessor segment overrun - reserved (INT 9)
-RSVD_INTR_SEL1 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; invalid TSS (INT 0ah)
-INVALID_TSS_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; segment not present (INT 0bh)
-SEG_NOT_PRESENT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; stack fault (INT 0ch)
-STACK_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; general protection (INT 0dh)
-GP_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; page fault (INT 0eh)
-PAGE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Intel reserved - do not use (INT 0fh)
-RSVD_INTR_SEL2 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; floating point error (INT 10h)
-FLT_POINT_ERR_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; alignment check (INT 11h)
-ALIGNMENT_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; machine check (INT 12h)
-MACHINE_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; SIMD floating-point exception (INT 13h)
-SIMD_EXCEPTION_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- db (85 * 16) dup(0)
-
-; IRQ 0 (System timer) - (INT 68h)
-IRQ0_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 1 (8042 Keyboard controller) - (INT 69h)
-IRQ1_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-IRQ2_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 3 (COM 2) - (INT 6bh)
-IRQ3_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 4 (COM 1) - (INT 6ch)
-IRQ4_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 5 (LPT 2) - (INT 6dh)
-IRQ5_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 6 (Floppy controller) - (INT 6eh)
-IRQ6_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 7 (LPT 1) - (INT 6fh)
-IRQ7_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 8 (RTC Alarm) - (INT 70h)
-IRQ8_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 9 - (INT 71h)
-IRQ9_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 10 - (INT 72h)
-IRQ10_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 11 - (INT 73h)
-IRQ11_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 12 (PS/2 mouse) - (INT 74h)
-IRQ12_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 13 (Floating point error) - (INT 75h)
-IRQ13_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 14 (Secondary IDE) - (INT 76h)
-IRQ14_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 15 (Primary IDE) - (INT 77h)
-IRQ15_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-IDT_END:
-
- align 02h
-
-MemoryMapSize dd 0
-MemoryMap dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
-
- 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
- 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
-
- org 0fe0h
-MyStack:
- ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- ; known low address (20f00) so it can be set up by PlMapIrqToVect in
- ; 8259.c
-
- int 8
- iret
-
- int 9
- iret
-
- int 10
- iret
-
- int 11
- iret
-
- int 12
- iret
-
- int 13
- iret
-
- int 14
- iret
-
- int 15
- iret
-
-
- org 0ffeh
-BlockSignature:
- dw 0aa55h
-
- end
diff --git a/DuetPkg/BootSector/start.S b/DuetPkg/BootSector/start.S deleted file mode 100644 index f96d06e144..0000000000 --- a/DuetPkg/BootSector/start.S +++ /dev/null @@ -1,919 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* start.S
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
- .org 0x0
-
-.global _start
-_start:
-
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-
-SectorSize: .word 0 # Sector Size - 16 bits
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
-ReservedSectors: .word 0 # Reserved Sectors - 16 bits
-NoFats: .byte 0 # Number of FATs - 8 bits
-RootEntries: .word 0 # Root Entries - 16 bits
-Sectors: .word 0 # Number of Sectors - 16 bits
-Media: .byte 0 # Media - 8 bits - ignored
-SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
-SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
-Heads: .word 0 # Heads - 16 bits - ignored
-HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
-LargeSectors: .long 0 # Large Sectors - 32 bits
-PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
-CurrentHead: .byte 0 # Current Head - 8 bits
-Signature: .byte 0 # Signature - 8 bits - ignored
-VolId: .ascii " " # Volume Serial Number- 4 bytes
-FatLabel: .ascii " " # Label - 11 bytes
-SystemId: .ascii "FAT12 " # SystemId - 8 bytes
-
-BootSectorEntryPoint:
- #ASSUME ds:@code
- #ASSUME ss:@code
- # ds = 1000, es = 2000 + x (size of first cluster >> 4)
- # cx = Start Cluster of EfiLdr
- # dx = Start Cluster of Efivar.bin
-
-# Re use the BPB data stored in Boot Sector
- movw $0x7c00, %bp
-
- pushw %cx
-# Read Efivar.bin
-# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- movw $0x1900, %ax
- movw %ax, %es
- testw %dx, %dx
- jnz CheckVarStoreSize
-
- movb $1, %al
-NoVarStore:
- pushw %es
-# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- movb %al, %es:(4)
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- movw %dx, %di
- cmpl $0x4000, %ds:2(%di)
- movb $2, %al
- jne NoVarStore
-
-LoadVarStore:
- movb $0, %al
- movb %al, %es:(4)
- movw (%di), %cx
-# ES:DI = 1500:0
- xorw %di, %di
- pushw %es
- movw $0x1500, %ax
- movw %ax, %es
- call ReadFile
-SaveVolumeId:
- popw %es
- movw VolId(%bp), %ax
- movw %ax, %es:(0) # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- movw VolId+2(%bp), %ax
- movw %ax, %es:(2)
-
-# Read Efildr
- popw %cx
-# cx = Start Cluster of Efildr -> BS.com has filled already
-# ES:DI = 2000:0, first cluster will be read again
- xorw %di, %di # di = 0
- movw $0x2000, %ax
- movw %ax, %es
- call ReadFile
- movw %cs, %ax
- movw %ax, %cs:JumpSegment
-
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x200
-JumpSegment:
- .word 0x2000
-
-
-
-# ****************************************************************************
-# ReadFile
-#
-# Arguments:
-# CX = Start Cluster of File
-# ES:DI = Buffer to store file content read from disk
-#
-# Return:
-# (ES << 4 + DI) = end of file content Buffer
-#
-# ****************************************************************************
-ReadFile:
-# si = NumberOfClusters
-# cx = ClusterNumber
-# dx = CachedFatSectorNumber
-# ds:0000 = CacheFatSectorBuffer
-# es:di = Buffer to load file
-# bx = NextClusterNumber
- pusha
- movw $1, %si # NumberOfClusters = 1
- pushw %cx # Push Start Cluster onto stack
- movw $0xfff, %dx # CachedFatSectorNumber = 0xfff
-FatChainLoop:
- movw %cx, %ax # ax = ClusterNumber
- andw $0xff8, %ax # ax = ax & 0xff8
- cmpw $0xff8, %ax # See if this is the last cluster
- je FoundLastCluster # Jump if last cluster found
- movw %cx, %ax # ax = ClusterNumber
- shlw %ax # ax = ClusterNumber * 2
- addw %cx, %ax # ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3
- shrw %ax # FatOffset = ClusterNumber*3 / 2
- pushw %si # Save si
- movw %ax, %si # si = FatOffset
- shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
- addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- andw $BLOCK_MASK,%si # si = FatOffset & BLOCK_MASK
- cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- movw $2, %bx
- pushw %es
- pushw %ds
- popw %es
- call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
- popw %es
- movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- movw (%si), %bx # bx = NextClusterNumber
- movw %cx, %ax # ax = ClusterNumber
- andw $1, %ax # See if this is an odd cluster number
- je EvenFatEntry
- shrw $4, %bx # NextClusterNumber = NextClusterNumber >> 4
-EvenFatEntry:
- andw $0xfff, %bx # Strip upper 4 bits of NextClusterNumber
- popw %si # Restore si
- decw %bx # bx = NextClusterNumber - 1
- cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- incw %bx # bx = NextClusterNumber
- incw %si # NumberOfClusters++
- movw %bx, %cx # ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- incw %bx
- popw %ax # ax = StartCluster
- pushw %bx # StartCluster = NextClusterNumber
- movw %bx, %cx # ClusterNumber = NextClusterNumber
- subw $2, %ax # ax = StartCluster - 2
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- pushw %ax # save start sector
- movw %si, %ax # ax = NumberOfClusters
- mulw %bx # ax = NumberOfClusters * SectorsPerCluster
- movw %ax, %bx # bx = Number of Sectors
- popw %ax # ax = Start Sector
- call ReadBlocks
- movw $1, %si # NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- popw %cx
- popa
- ret
-
-
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax, %esi # esi = Start LBA
- movw %bx, %cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc, %bp # bp = 0x7bfc
- movl %esi, %eax # eax = Start LBA
- xorl %edx, %edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
-
- movw (%bp), %bx # bx = MaxSector
- subw %dx, %bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx, %bx # bx = Blocks
-LimitTransfer:
- pushw %ax # save ax
- movw %es, %ax # ax = es
- shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
- andw $0x7f, %ax # ax = Number of blocks into current seg
- addw %bx, %ax # ax = End Block number of transfer
- cmpw $0x80, %ax # See if it crosses a 64K boundry
- jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
- subw $0x80, %ax # ax = Number of blocks past 64K boundry
- subw %ax, %bx # Decrease transfer size by block overage
-NotCrossing64KBoundry:
- popw %ax # restore ax
-
- pushw %cx
- movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx, %dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl, %dh # dh = Head
- movw $0x7c00, %bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al, %ch # ch = Cylinder
- movb %bl, %al # al = Blocks
- movb $2, %ah # ah = Function 2
- movw %di, %bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx, %ebx
- addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
- movw %es, %ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx, %ax
- movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0, %cx
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- pushw %cs
- popw %ds
- leaw ErrorString, %si
- movw $7, %cx
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- movw $0xb800, %ax
- movw %ax, %es
- movw $160, %di
- rep
- movsw
-Halt:
- jmp Halt
-
-ErrorString:
- .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c
-
- .org 0x01fa
-LBAOffsetForBootSector:
- .long 0x0
-
- .org 0x01fe
- .word 0xaa55
-
-#******************************************************************************
-#******************************************************************************
-#******************************************************************************
-
-.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
-.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
-.equ KBD_STATUS_PORT, 0x064 # 8042 status port
-.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
-.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
-
- .org 0x200
- jmp start
-Em64String:
- .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
-
-start:
- movw %cs, %ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %ss
- movw $MyStack, %sp
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[160],'a'
-# mov ax,cs
-# mov es,ax
-
- movl $0, %ebx
- leal MemoryMap, %edi
-MemMapLoop:
- movl $0xe820, %eax
- movl $20, %ecx
- movl $0x534d4150, %edx # SMAP
- int $0x15
- jc MemMapDone
- addl $20, %edi
- cmpl $0, %ebx
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- leal MemoryMap, %eax
- subl %eax, %edi # Get the address of the memory map
- movl %edi, MemoryMapSize # Save the size of the memory map
-
- xorl %ebx, %ebx
- movw %cs, %bx # BX=segment
- shll $4, %ebx # BX="linear" address of segment base
- leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
- movl %eax, (gdtr + 2) # Put address of gdt into the gdtr
- leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
- movl %eax, (idtr + 2) # Put address of idt into the idtr
- leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
-
- addl $0x1000, %ebx # Source of EFI32
- movl %ebx, JUMP+2
- addl $0x1000, %ebx
- movl %ebx, %esi # Source of EFILDR32
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[162],'b'
-# mov ax,cs
-# mov es,ax
-
-#
-# Enable A20 Gate
-#
-
- movw $0x2401, %ax # Enable A20 Gate
- int $0x15
- jnc A20GateEnabled # Jump if it suceeded
-
-#
-# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-#
-
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- outw %ax, $DELAY_PORT # Delay 1 uS
- mov $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
- out %al, $KBD_STATUS_PORT # Send command to the 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- mov $ENABLE_A20_CMD, %al # gate address bit 20 on
- out %al, $KBD_CONTROL_PORT # Send command to thre 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- movw $25, %cx # Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- outw %ax, $DELAY_PORT # Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
- movw $0x0008, %bx # Flat data descriptor
-
-#
-# DISABLE INTERRUPTS - Entering Protected Mode
-#
-
- cli
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[164],'c'
-# mov ax,cs
-# mov es,ax
-
- .byte 0x66
- lgdt gdtr
- .byte 0x66
- lidt idtr
-
- movl %cr0, %eax
- orb $1, %al
- movl %eax, %cr0
-JUMP:
-# jmp far 0010:00020000
- .byte 0x66
- .byte 0xea
- .long 0x00020000
- .word 0x0010
-
-Empty8042InputBuffer:
- movw $0, %cx
-Empty8042Loop:
- outw %ax, $DELAY_PORT # Delay 1us
- in $KBD_STATUS_PORT, %al # Read the 8042 Status Port
- andb $0x2, %al # Check the Input Buffer Full Flag
- loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-##############################################################################
-# data
-##############################################################################
-
- .p2align 1
-
- gdtr: .long GDT_END - GDT_BASE - 1 # GDT limit
- .long 0 # (GDT base gets set above)
-##############################################################################
-# global descriptor table (GDT)
-##############################################################################
-
- .p2align 1
-
-GDT_BASE:
-# null descriptor
-.equ NULL_SEL, .-GDT_BASE
- .word 0 # limit 15:0
- .word 0 # base 15:0
- .byte 0 # base 23:16
- .byte 0 # type
- .byte 0 # limit 19:16, flags
- .byte 0 # base 31:24
-
-# linear data segment descriptor
-.equ LINEAR_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# linear code segment descriptor
-.equ LINEAR_CODE_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system data segment descriptor
-.equ SYS_DATA_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system code segment descriptor
-.equ SYS_CODE_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE3_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE4_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE5_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-GDT_END:
-
- .p2align 1
-
-
-
-idtr: .long IDT_END - IDT_BASE - 1 # IDT limit
- .long 0 # (IDT base gets set above)
-##############################################################################
-# interrupt descriptor table (IDT)
-#
-# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-# mappings. This implementation only uses the system timer and all other
-# IRQs will remain masked. The descriptors for vectors 33+ are provided
-# for convenience.
-##############################################################################
-
-#idt_tag db "IDT",0
- .p2align 1
-
-IDT_BASE:
-# divide by zero (INT 0)
-.equ DIV_ZERO_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# debug exception (INT 1)
-.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# NMI (INT 2)
-.equ NMI_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# soft breakpoint (INT 3)
-.equ BREAKPOINT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# overflow (INT 4)
-.equ OVERFLOW_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# bounds check (INT 5)
-.equ BOUNDS_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# invalid opcode (INT 6)
-.equ INVALID_OPCODE_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# device not available (INT 7)
-.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# double fault (INT 8)
-.equ DOUBLE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Coprocessor segment overrun - reserved (INT 9)
-.equ RSVD_INTR_SEL1, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# invalid TSS (INT 0x0a)
-.equ INVALID_TSS_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# segment not present (INT 0x0b)
-.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# stack fault (INT 0x0c)
-.equ STACK_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# general protection (INT 0x0d)
-.equ GP_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# page fault (INT 0x0e)
-.equ PAGE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Intel reserved - do not use (INT 0x0f)
-.equ RSVD_INTR_SEL2, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# floating point error (INT 0x10)
-.equ FLT_POINT_ERR_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# alignment check (INT 0x11)
-.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# machine check (INT 0x12)
-.equ MACHINE_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# SIMD floating-point exception (INT 0x13)
-.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- .fill 85 * 8, 1, 0 # db (85 * 8) dup(0)
-
-# IRQ 0 (System timer) - (INT 0x68)
-.equ IRQ0_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 1 (8042 Keyboard controller) - (INT 0x69)
-.equ IRQ1_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 0x6a)
-.equ IRQ2_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 3 (COM 2) - (INT 0x6b)
-.equ IRQ3_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 4 (COM 1) - (INT 0x6c)
-.equ IRQ4_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 5 (LPT 2) - (INT 0x6d)
-.equ IRQ5_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 6 (Floppy controller) - (INT 0x6e)
-.equ IRQ6_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 7 (LPT 1) - (INT 0x6f)
-.equ IRQ7_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 8 (RTC Alarm) - (INT 0x70)
-.equ IRQ8_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 9 - (INT 0x71)
-.equ IRQ9_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 10 - (INT 0x72)
-.equ IRQ10_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 11 - (INT 0x73)
-.equ IRQ11_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 12 (PS/2 mouse) - (INT 0x74)
-.equ IRQ12_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 13 (Floating point error) - (INT 0x75)
-.equ IRQ13_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 14 (Secondary IDE) - (INT 0x76)
-.equ IRQ14_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 15 (Primary IDE) - (INT 0x77)
-.equ IRQ15_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-IDT_END:
-
- .p2align 1
-
-MemoryMapSize: .long 0
-MemoryMap: .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
-
- .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
- .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
-
- .org 0x0fe0
-MyStack:
- # below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- # back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- # known low address (20f00) so it can be set up by PlMapIrqToVect in
- # 8259.c
-
- int $8
- iret
-
- int $9
- iret
-
- int $10
- iret
-
- int $11
- iret
-
- int $12
- iret
-
- int $13
- iret
-
- int $14
- iret
-
- int $15
- iret
-
-
- .org 0x0ffe
-BlockSignature:
- .word 0xaa55
-
-
diff --git a/DuetPkg/BootSector/start.asm b/DuetPkg/BootSector/start.asm deleted file mode 100644 index 9cc05ff5ca..0000000000 --- a/DuetPkg/BootSector/start.asm +++ /dev/null @@ -1,916 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* start.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-
-SectorSize dw 0 ; Sector Size - 16 bits
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits
-NoFats db 0 ; Number of FATs - 8 bits
-RootEntries dw 0 ; Root Entries - 16 bits
-Sectors dw 0 ; Number of Sectors - 16 bits
-Media db 0 ; Media - 8 bits - ignored
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
-Heads dw 0 ; Heads - 16 bits - ignored
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
-LargeSectors dd 0 ; Large Sectors - 32 bits
-PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
-CurrentHead db 0 ; Current Head - 8 bits
-Signature db 0 ; Signature - 8 bits - ignored
-VolId db " " ; Volume Serial Number- 4 bytes
-FatLabel db " " ; Label - 11 bytes
-SystemId db "FAT12 " ; SystemId - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
- ; ds = 1000, es = 2000 + x (size of first cluster >> 4)
- ; cx = Start Cluster of EfiLdr
- ; dx = Start Cluster of Efivar.bin
-
-; Re use the BPB data stored in Boot Sector
- mov bp,07c00h
-
- push cx
-; Read Efivar.bin
-; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- mov ax,01900h
- mov es,ax
- test dx,dx
- jnz CheckVarStoreSize
-
- mov al,1
-NoVarStore:
- push es
-; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- mov byte ptr es:[4],al
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- mov di,dx
- cmp dword ptr ds:[di+2], 04000h
- mov al,2
- jne NoVarStore
-
-LoadVarStore:
- mov al,0
- mov byte ptr es:[4],al
- mov cx,word ptr[di]
-; ES:DI = 1500:0
- xor di,di
- push es
- mov ax,01500h
- mov es,ax
- call ReadFile
-SaveVolumeId:
- pop es
- mov ax,word ptr [bp+VolId]
- mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- mov ax,word ptr [bp+VolId+2]
- mov word ptr es:[2],ax
-
-; Read Efildr
- pop cx
-; cx = Start Cluster of Efildr -> BS.com has filled already
-; ES:DI = 2000:0, first cluster will be read again
- xor di,di ; di = 0
- mov ax,02000h
- mov es,ax
- call ReadFile
- mov ax,cs
- mov word ptr cs:[JumpSegment],ax
-
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0200h
-JumpSegment:
- dw 2000h
-
-
-
-; ****************************************************************************
-; ReadFile
-;
-; Arguments:
-; CX = Start Cluster of File
-; ES:DI = Buffer to store file content read from disk
-;
-; Return:
-; (ES << 4 + DI) = end of file content Buffer
-;
-; ****************************************************************************
-ReadFile:
-; si = NumberOfClusters
-; cx = ClusterNumber
-; dx = CachedFatSectorNumber
-; ds:0000 = CacheFatSectorBuffer
-; es:di = Buffer to load file
-; bx = NextClusterNumber
- pusha
- mov si,1 ; NumberOfClusters = 1
- push cx ; Push Start Cluster onto stack
- mov dx,0fffh ; CachedFatSectorNumber = 0xfff
-FatChainLoop:
- mov ax,cx ; ax = ClusterNumber
- and ax,0ff8h ; ax = ax & 0xff8
- cmp ax,0ff8h ; See if this is the last cluster
- je FoundLastCluster ; Jump if last cluster found
- mov ax,cx ; ax = ClusterNumber
- shl ax,1 ; ax = ClusterNumber * 2
- add ax,cx ; ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3
- shr ax,1 ; FatOffset = ClusterNumber*3 / 2
- push si ; Save si
- mov si,ax ; si = FatOffset
- shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
- add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
- cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- mov bx,2
- push es
- push ds
- pop es
- call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
- pop es
- mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- mov bx,word ptr [si] ; bx = NextClusterNumber
- mov ax,cx ; ax = ClusterNumber
- and ax,1 ; See if this is an odd cluster number
- je EvenFatEntry
- shr bx,4 ; NextClusterNumber = NextClusterNumber >> 4
-EvenFatEntry:
- and bx,0fffh ; Strip upper 4 bits of NextClusterNumber
- pop si ; Restore si
- dec bx ; bx = NextClusterNumber - 1
- cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- inc bx ; bx = NextClusterNumber
- inc si ; NumberOfClusters++
- mov cx,bx ; ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- inc bx
- pop ax ; ax = StartCluster
- push bx ; StartCluster = NextClusterNumber
- mov cx,bx ; ClusterNumber = NextClusterNumber
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- push ax ; save start sector
- mov ax,si ; ax = NumberOfClusters
- mul bx ; ax = NumberOfClusters * SectorsPerCluster
- mov bx,ax ; bx = Number of Sectors
- pop ax ; ax = Start Sector
- call ReadBlocks
- mov si,1 ; NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- pop cx
- popa
- ret
-
-
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
-
- mov bx,word ptr [bp] ; bx = MaxSector
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push ax ; save ax
- mov ax,es ; ax = es
- shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
- and ax,07fh ; ax = Number of blocks into current seg
- add ax,bx ; ax = End Block number of transfer
- cmp ax,080h ; See if it crosses a 64K boundry
- jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
- sub ax,080h ; ax = Number of blocks past 64K boundry
- sub bx,ax ; Decrease transfer size by block overage
-NotCrossing64KBoundry:
- pop ax ; restore ax
-
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- push cs
- pop ds
- lea si, [ErrorString]
- mov cx, 7
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- mov ax,0b800h
- mov es,ax
- mov di,160
- rep movsw
-Halt:
- jmp Halt
-
-ErrorString:
- db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
- org 01feh
- dw 0aa55h
-
-;******************************************************************************
-;******************************************************************************
-;******************************************************************************
-
-DELAY_PORT equ 0edh ; Port to use for 1uS delay
-KBD_CONTROL_PORT equ 060h ; 8042 control port
-KBD_STATUS_PORT equ 064h ; 8042 status port
-WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
-ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
-
- org 200h
- jmp start
-Em64String:
- 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
-
-start:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,MyStack
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[160],'a'
-; mov ax,cs
-; mov es,ax
-
- mov ebx,0
- lea edi,MemoryMap
-MemMapLoop:
- mov eax,0e820h
- mov ecx,20
- mov edx,'SMAP'
- int 15h
- jc MemMapDone
- add edi,20
- cmp ebx,0
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- lea eax,MemoryMap
- sub edi,eax ; Get the address of the memory map
- mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
-
- xor ebx,ebx
- mov bx,cs ; BX=segment
- shl ebx,4 ; BX="linear" address of segment base
- lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
- mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
- lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
- mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
- lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
-
- add ebx,01000h ; Source of EFI32
- mov dword ptr [JUMP+2],ebx
- add ebx,01000h
- mov esi,ebx ; Source of EFILDR32
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[162],'b'
-; mov ax,cs
-; mov es,ax
-
-;
-; Enable A20 Gate
-;
-
- mov ax,2401h ; Enable A20 Gate
- int 15h
- jnc A20GateEnabled ; Jump if it suceeded
-
-;
-; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-;
-
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- out DELAY_PORT,ax ; Delay 1 uS
- mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
- out KBD_STATUS_PORT,al ; Send command to the 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- mov al,ENABLE_A20_CMD ; gate address bit 20 on
- out KBD_CONTROL_PORT,al ; Send command to thre 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- mov cx,25 ; Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- out DELAY_PORT,ax ; Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
- mov bx,0008h ; Flat data descriptor
-;
-; DISABLE INTERRUPTS - Entering Protected Mode
-;
-
- cli
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[164],'c'
-; mov ax,cs
-; mov es,ax
-
- db 66h
- lgdt fword ptr [gdtr]
- db 66h
- lidt fword ptr [idtr]
-
- mov eax,cr0
- or al,1
- mov cr0,eax
-JUMP:
-; jmp far 0010:00020000
- db 066h
- db 0eah
- dd 000020000h
- dw 00010h
-
-Empty8042InputBuffer:
- mov cx,0
-Empty8042Loop:
- out DELAY_PORT,ax ; Delay 1us
- in al,KBD_STATUS_PORT ; Read the 8042 Status Port
- and al,02h ; Check the Input Buffer Full Flag
- loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; data
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
- dd 0 ; (GDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; global descriptor table (GDT)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-public GDT_BASE
-GDT_BASE:
-; null descriptor
-NULL_SEL equ $-GDT_BASE
- dw 0 ; limit 15:0
- dw 0 ; base 15:0
- db 0 ; base 23:16
- db 0 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
-
-; linear data segment descriptor
-LINEAR_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; linear code segment descriptor
-LINEAR_CODE_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system data segment descriptor
-SYS_DATA_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system code segment descriptor
-SYS_CODE_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE3_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE4_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE5_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-GDT_END:
-
- align 02h
-
-
-
-idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
- dd 0 ; (IDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; interrupt descriptor table (IDT)
-;
-; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-; mappings. This implementation only uses the system timer and all other
-; IRQs will remain masked. The descriptors for vectors 33+ are provided
-; for convenience.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;idt_tag db "IDT",0
- align 02h
-
-public IDT_BASE
-IDT_BASE:
-; divide by zero (INT 0)
-DIV_ZERO_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; debug exception (INT 1)
-DEBUG_EXCEPT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; NMI (INT 2)
-NMI_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; soft breakpoint (INT 3)
-BREAKPOINT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; overflow (INT 4)
-OVERFLOW_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; bounds check (INT 5)
-BOUNDS_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; invalid opcode (INT 6)
-INVALID_OPCODE_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; device not available (INT 7)
-DEV_NOT_AVAIL_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; double fault (INT 8)
-DOUBLE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Coprocessor segment overrun - reserved (INT 9)
-RSVD_INTR_SEL1 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; invalid TSS (INT 0ah)
-INVALID_TSS_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; segment not present (INT 0bh)
-SEG_NOT_PRESENT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; stack fault (INT 0ch)
-STACK_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; general protection (INT 0dh)
-GP_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; page fault (INT 0eh)
-PAGE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Intel reserved - do not use (INT 0fh)
-RSVD_INTR_SEL2 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; floating point error (INT 10h)
-FLT_POINT_ERR_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; alignment check (INT 11h)
-ALIGNMENT_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; machine check (INT 12h)
-MACHINE_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; SIMD floating-point exception (INT 13h)
-SIMD_EXCEPTION_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- db (85 * 8) dup(0)
-
-; IRQ 0 (System timer) - (INT 68h)
-IRQ0_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 1 (8042 Keyboard controller) - (INT 69h)
-IRQ1_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-IRQ2_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 3 (COM 2) - (INT 6bh)
-IRQ3_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 4 (COM 1) - (INT 6ch)
-IRQ4_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 5 (LPT 2) - (INT 6dh)
-IRQ5_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 6 (Floppy controller) - (INT 6eh)
-IRQ6_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 7 (LPT 1) - (INT 6fh)
-IRQ7_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 8 (RTC Alarm) - (INT 70h)
-IRQ8_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 9 - (INT 71h)
-IRQ9_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 10 - (INT 72h)
-IRQ10_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 11 - (INT 73h)
-IRQ11_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 12 (PS/2 mouse) - (INT 74h)
-IRQ12_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 13 (Floating point error) - (INT 75h)
-IRQ13_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 14 (Secondary IDE) - (INT 76h)
-IRQ14_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 15 (Primary IDE) - (INT 77h)
-IRQ15_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-IDT_END:
-
- align 02h
-
-MemoryMapSize dd 0
-MemoryMap dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
-
- 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
- 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
-
- org 0fe0h
-MyStack:
- ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- ; known low address (20f00) so it can be set up by PlMapIrqToVect in
- ; 8259.c
-
- int 8
- iret
-
- int 9
- iret
-
- int 10
- iret
-
- int 11
- iret
-
- int 12
- iret
-
- int 13
- iret
-
- int 14
- iret
-
- int 15
- iret
-
-
- org 0ffeh
-BlockSignature:
- dw 0aa55h
-
- end
diff --git a/DuetPkg/BootSector/start16.S b/DuetPkg/BootSector/start16.S deleted file mode 100644 index a4cb151c77..0000000000 --- a/DuetPkg/BootSector/start16.S +++ /dev/null @@ -1,910 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* start16.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
- #.MODEL small
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x0020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
- .org 0x00
-
-.global _start
-_start:
-
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-
-SectorSize: .word 0 # Sector Size - 16 bits
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
-ReservedSectors: .word 0 # Reserved Sectors - 16 bits
-NoFats: .byte 0 # Number of FATs - 8 bits
-RootEntries: .word 0 # Root Entries - 16 bits
-Sectors: .word 0 # Number of Sectors - 16 bits
-Media: .byte 0 # Media - 8 bits - ignored
-SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
-SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
-Heads: .word 0 # Heads - 16 bits - ignored
-HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
-LargeSectors: .long 0 # Large Sectors - 32 bits
-PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
-CurrentHead: .byte 0 # Current Head - 8 bits
-Signature: .byte 0 # Signature - 8 bits - ignored
-VolId: .ascii " " # Volume Serial Number- 4 bytes
-FatLabel: .ascii " " # Label - 11 bytes
-SystemId: .ascii "FAT16 " # SystemId - 8 bytes
-
-BootSectorEntryPoint:
- #ASSUME ds:@code
- #ASSUME ss:@code
- # ds = 1000, es = 2000 + x (size of first cluster >> 4)
- # cx = Start Cluster of EfiLdr
- # dx = Start Cluster of Efivar.bin
-
-# Re use the BPB data stored in Boot Sector
- movw $0x7c00, %bp
-
- pushw %cx
-# Read Efivar.bin
-# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- movw $0x1900, %ax
- movw %ax, %es
- testw %dx, %dx
- jnz CheckVarStoreSize
-
- movb $1, %al
-NoVarStore:
- pushw %es
-# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- movb %al, %es:4
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- movw %dx, %di
- cmpl $0x4000, %ds:2(%di)
- movb $2, %al
- jne NoVarStore
-
-LoadVarStore:
- movb $0, %al
- movb %al, %es:4
- movw (%di), %cx
-# ES:DI = 1500:0
- xorw %di, %di
- pushw %es
- movw $0x1500, %ax
- movw %ax, %es
- call ReadFile
-SaveVolumeId:
- popw %es
- movw VolId(%bp), %ax
- movw %ax, %es:0 # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- movw VolId+2(%bp), %ax
- movw %ax, %es:2
-
-# Read Efildr
- popw %cx
-# cx = Start Cluster of Efildr -> BS.com has filled already
-# ES:DI = 2000:0, first cluster will be read again
- xorw %di, %di # di = 0
- movw $0x2000, %ax
- movw %ax, %es
- call ReadFile
- movw %cs, %ax
- movw %ax, %cs:JumpSegment
-
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x200
-JumpSegment:
- .word 0x2000
-
-
-
-# ****************************************************************************
-# ReadFile
-#
-# Arguments:
-# CX = Start Cluster of File
-# ES:DI = Buffer to store file content read from disk
-#
-# Return:
-# (ES << 4 + DI) = end of file content Buffer
-#
-# ****************************************************************************
-ReadFile:
-# si = NumberOfClusters
-# cx = ClusterNumber
-# dx = CachedFatSectorNumber
-# ds:0000 = CacheFatSectorBuffer
-# es:di = Buffer to load file
-# bx = NextClusterNumber
- pusha
- movw $1, %si # NumberOfClusters = 1
- pushw %cx # Push Start Cluster onto stack
- movw $0xfff, %dx # CachedFatSectorNumber = 0xfff
-FatChainLoop:
- movw %cx, %ax # ax = ClusterNumber
- andw $0xfff8, %ax # ax = ax & 0xfff8
- cmpw $0xfff8, %ax # See if this is the last cluster
- je FoundLastCluster # Jump if last cluster found
- movw %cx, %ax # ax = ClusterNumber
- shlw %ax # FatOffset = ClusterNumber * 2
- pushw %si # Save si
- movw %ax, %si # si = FatOffset
- shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
- addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK
- cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- movw $2, %bx
- pushw %es
- pushw %ds
- popw %es
- call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
- popw %es
- movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- movw (%si), %bx # bx = NextClusterNumber
- movw %cx, %ax # ax = ClusterNumber
- popw %si # Restore si
- decw %bx # bx = NextClusterNumber - 1
- cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- incw %bx # bx = NextClusterNumber
- incw %si # NumberOfClusters++
- movw %bx, %cx # ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- incw %bx
- popw %ax # ax = StartCluster
- pushw %bx # StartCluster = NextClusterNumber
- movw %bx, %cx # ClusterNumber = NextClusterNumber
- subw $2, %ax # ax = StartCluster - 2
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- pushw %ax # save start sector
- movw %si, %ax # ax = NumberOfClusters
- mulw %bx # ax = NumberOfClusters * SectorsPerCluster
- movw %ax, %bx # bx = Number of Sectors
- popw %ax # ax = Start Sector
- call ReadBlocks
- movw $1, %si # NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- popw %cx
- popa
- ret
-
-
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax, %esi # esi = Start LBA
- movw %bx, %cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc, %bp # bp = 0x7bfc
- movl %esi, %eax # eax = Start LBA
- xorl %edx, %edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
-
- movw (%bp), %bx # bx = MaxSector
- subw %dx, %bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx, %bx # bx = Blocks
-LimitTransfer:
- pushw %ax # save ax
- movw %es, %ax # ax = es
- shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
- andw $0x7f, %ax # ax = Number of blocks into current seg
- addw %bx, %ax # ax = End Block number of transfer
- cmpw $0x80, %ax # See if it crosses a 64K boundry
- jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
- subw $0x80, %ax # ax = Number of blocks past 64K boundry
- subw %ax, %bx # Decrease transfer size by block overage
-NotCrossing64KBoundry:
- popw %ax # restore ax
-
- pushw %cx
- movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx, %dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl, %dh # dh = Head
- movw $0x7c00, %bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al, %ch # ch = Cylinder
- movb %bl, %al # al = Blocks
- movb $2, %ah # ah = Function 2
- movw %di, %bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx, %ebx
- addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
- movw %es, %ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx, %ax
- movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0, %cx
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- pushw %cs
- popw %ds
- leaw ErrorString, %si
- movw $7, %cx
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- movw $0xb800, %ax
- movw %ax, %es
- movw $160, %di
- rep
- movsw
-Halt:
- jmp Halt
-
-ErrorString:
- .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
-
- # .org 0x01fa # Just for passing build.
-LBAOffsetForBootSector:
- .long 0x0
-
- # .org 0x01fe # Just for passing build.
- .word 0xaa55
-
-#******************************************************************************
-#******************************************************************************
-#******************************************************************************
-
-.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
-.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
-.equ KBD_STATUS_PORT, 0x064 # 8042 status port
-.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
-.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
-
- # .org 0x0200 # Just for passing build.
- jmp start
-Em64String:
- .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
-
-start:
- movw %cs, %ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %ss
- movw $MyStack, %sp
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[160],'a'
-# mov ax,cs
-# mov es,ax
-
- movl $0, %ebx
- leal MemoryMap, %edi
-MemMapLoop:
- movl $0xe820, %eax
- movl $20, %ecx
- movl $0x534d4150, %edx # 0x534d4150 stands for 'SMAP'
- int $0x15
- jc MemMapDone
- addl $20, %edi
- cmpl $0, %ebx
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- leal MemoryMap, %eax
- subl %eax, %edi # Get the address of the memory map
- movl %edi, MemoryMapSize # Save the size of the memory map
-
- xorl %ebx, %ebx
- movw %cs, %bx # BX=segment
- shll $4, %ebx # BX="linear" address of segment base
- leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
- movl %eax, gdtr + 2 # Put address of gdt into the gdtr
- leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
- movl %eax, idtr + 2 # Put address of idt into the idtr
- leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
-
- addl $0x1000, %ebx # Source of EFI32
- movl %ebx, JUMP+2
- addl $0x1000, %ebx
- movl %ebx, %esi # Source of EFILDR32
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[162],'b'
-# mov ax,cs
-# mov es,ax
-
-#
-# Enable A20 Gate
-#
-
- movw $0x2401, %ax # Enable A20 Gate
- int $0x15
- jnc A20GateEnabled # Jump if it suceeded
-
-#
-# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-#
-
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- outw %ax, $DELAY_PORT # Delay 1 uS
- movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
- outb %al, $KBD_STATUS_PORT # Send command to the 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- movb $ENABLE_A20_CMD, %al # gate address bit 20 on
- outb %al, $KBD_CONTROL_PORT # Send command to thre 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- movw $25, %cx # Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- outw %ax, $DELAY_PORT # Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
- movw $0x0008, %bx # Flat data descriptor
-#
-# DISABLE INTERRUPTS - Entering Protected Mode
-#
-
- cli
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[164],'c'
-# mov ax,cs
-# mov es,ax
-
- .byte 0x66
- lgdt gdtr
- .byte 0x66
- lidt idtr
-
- movl %cr0, %eax
- orb $1, %al
- movl %eax, %cr0
-JUMP:
-# jmp far 0010:00020000
- .byte 0x66
- .byte 0xea
- .long 0x00020000
- .word 0x0010
-
-Empty8042InputBuffer:
- movw $0, %cx
-Empty8042Loop:
- outw %ax, $DELAY_PORT # Delay 1us
- inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port
- andb $0x2, %al # Check the Input Buffer Full Flag
- loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-##############################################################################
-# data
-##############################################################################
-
- .p2align 1
-
-gdtr: .word GDT_END - GDT_BASE - 1 # GDT limit
- .long 0 # (GDT base gets set above)
-##############################################################################
-# global descriptor table (GDT)
-##############################################################################
-
- .p2align 1
-
-GDT_BASE:
-# null descriptor
-.equ NULL_SEL, .-GDT_BASE
- .word 0 # limit 15:0
- .word 0 # base 15:0
- .byte 0 # base 23:16
- .byte 0 # type
- .byte 0 # limit 19:16, flags
- .byte 0 # base 31:24
-
-# linear data segment descriptor
-.equ LINEAR_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# linear code segment descriptor
-.equ LINEAR_CODE_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system data segment descriptor
-.equ SYS_DATA_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system code segment descriptor
-.equ SYS_CODE_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE3_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE4_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE5_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-GDT_END:
-
- .p2align 1
-
-
-
-idtr: .word IDT_END - IDT_BASE - 1 # IDT limit
- .long 0 # (IDT base gets set above)
-##############################################################################
-# interrupt descriptor table (IDT)
-#
-# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-# mappings. This implementation only uses the system timer and all other
-# IRQs will remain masked. The descriptors for vectors 33+ are provided
-# for convenience.
-##############################################################################
-
-#idt_tag db "IDT",0
- .p2align 1
-
-IDT_BASE:
-# divide by zero (INT 0)
-.equ DIV_ZERO_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# debug exception (INT 1)
-.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# NMI (INT 2)
-.equ NMI_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# soft breakpoint (INT 3)
-.equ BREAKPOINT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# overflow (INT 4)
-.equ OVERFLOW_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# bounds check (INT 5)
-.equ BOUNDS_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# invalid opcode (INT 6)
-.equ INVALID_OPCODE_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# device not available (INT 7)
-.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# double fault (INT 8)
-.equ DOUBLE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Coprocessor segment overrun - reserved (INT 9)
-.equ RSVD_INTR_SEL1, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# invalid TSS (INT 0ah)
-.equ INVALID_TSS_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# segment not present (INT 0bh)
-.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# stack fault (INT 0ch)
-.equ STACK_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# general protection (INT 0dh)
-.equ GP_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# page fault (INT 0eh)
-.equ PAGE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Intel reserved - do not use (INT 0fh)
-.equ RSVD_INTR_SEL2, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# floating point error (INT 10h)
-.equ FLT_POINT_ERR_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# alignment check (INT 11h)
-.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# machine check (INT 12h)
-.equ MACHINE_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# SIMD floating-point exception (INT 13h)
-.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- .fill 85 * 8, 1, 0
-
-# IRQ 0 (System timer) - (INT 68h)
-.equ IRQ0_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 1 (8042 Keyboard controller) - (INT 69h)
-.equ IRQ1_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-.equ IRQ2_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 3 (COM 2) - (INT 6bh)
-.equ IRQ3_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 4 (COM 1) - (INT 6ch)
-.equ IRQ4_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 5 (LPT 2) - (INT 6dh)
-.equ IRQ5_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 6 (Floppy controller) - (INT 6eh)
-.equ IRQ6_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 7 (LPT 1) - (INT 6fh)
-.equ IRQ7_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 8 (RTC Alarm) - (INT 70h)
-.equ IRQ8_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 9 - (INT 71h)
-.equ IRQ9_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 10 - (INT 72h)
-.equ IRQ10_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 11 - (INT 73h)
-.equ IRQ11_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 12 (PS/2 mouse) - (INT 74h)
-.equ IRQ12_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 13 (Floating point error) - (INT 75h)
-.equ IRQ13_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 14 (Secondary IDE) - (INT 76h)
-.equ IRQ14_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 15 (Primary IDE) - (INT 77h)
-.equ IRQ15_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-IDT_END:
-
- .p2align 1
-
-MemoryMapSize: .long 0
-MemoryMap: .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
-
- .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
- .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
-
- .org 0x0fe0
-MyStack:
- # below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- # back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- # known low address (20f00) so it can be set up by PlMapIrqToVect in
- # 8259.c
-
- int $8
- iret
-
- int $9
- iret
-
- int $10
- iret
-
- int $11
- iret
-
- int $12
- iret
-
- int $13
- iret
-
- int $14
- iret
-
- int $15
- iret
-
-
- .org 0x0ffe
-BlockSignature:
- .word 0xaa55
diff --git a/DuetPkg/BootSector/start16.asm b/DuetPkg/BootSector/start16.asm deleted file mode 100644 index 05d0b2d1e5..0000000000 --- a/DuetPkg/BootSector/start16.asm +++ /dev/null @@ -1,909 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* start16.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-
-SectorSize dw 0 ; Sector Size - 16 bits
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits
-NoFats db 0 ; Number of FATs - 8 bits
-RootEntries dw 0 ; Root Entries - 16 bits
-Sectors dw 0 ; Number of Sectors - 16 bits
-Media db 0 ; Media - 8 bits - ignored
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
-Heads dw 0 ; Heads - 16 bits - ignored
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
-LargeSectors dd 0 ; Large Sectors - 32 bits
-PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
-CurrentHead db 0 ; Current Head - 8 bits
-Signature db 0 ; Signature - 8 bits - ignored
-VolId db " " ; Volume Serial Number- 4 bytes
-FatLabel db " " ; Label - 11 bytes
-SystemId db "FAT16 " ; SystemId - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
- ; ds = 1000, es = 2000 + x (size of first cluster >> 4)
- ; cx = Start Cluster of EfiLdr
- ; dx = Start Cluster of Efivar.bin
-
-; Re use the BPB data stored in Boot Sector
- mov bp,07c00h
-
- push cx
-; Read Efivar.bin
-; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- mov ax,01900h
- mov es,ax
- test dx,dx
- jnz CheckVarStoreSize
-
- mov al,1
-NoVarStore:
- push es
-; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- mov byte ptr es:[4],al
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- mov di,dx
- cmp dword ptr ds:[di+2], 04000h
- mov al,2
- jne NoVarStore
-
-LoadVarStore:
- mov al,0
- mov byte ptr es:[4],al
- mov cx,word ptr[di]
-; ES:DI = 1500:0
- xor di,di
- push es
- mov ax,01500h
- mov es,ax
- call ReadFile
-SaveVolumeId:
- pop es
- mov ax,word ptr [bp+VolId]
- mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- mov ax,word ptr [bp+VolId+2]
- mov word ptr es:[2],ax
-
-; Read Efildr
- pop cx
-; cx = Start Cluster of Efildr -> BS.com has filled already
-; ES:DI = 2000:0, first cluster will be read again
- xor di,di ; di = 0
- mov ax,02000h
- mov es,ax
- call ReadFile
- mov ax,cs
- mov word ptr cs:[JumpSegment],ax
-
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0200h
-JumpSegment:
- dw 2000h
-
-
-
-; ****************************************************************************
-; ReadFile
-;
-; Arguments:
-; CX = Start Cluster of File
-; ES:DI = Buffer to store file content read from disk
-;
-; Return:
-; (ES << 4 + DI) = end of file content Buffer
-;
-; ****************************************************************************
-ReadFile:
-; si = NumberOfClusters
-; cx = ClusterNumber
-; dx = CachedFatSectorNumber
-; ds:0000 = CacheFatSectorBuffer
-; es:di = Buffer to load file
-; bx = NextClusterNumber
- pusha
- mov si,1 ; NumberOfClusters = 1
- push cx ; Push Start Cluster onto stack
- mov dx,0fffh ; CachedFatSectorNumber = 0xfff
-FatChainLoop:
- mov ax,cx ; ax = ClusterNumber
- and ax,0fff8h ; ax = ax & 0xfff8
- cmp ax,0fff8h ; See if this is the last cluster
- je FoundLastCluster ; Jump if last cluster found
- mov ax,cx ; ax = ClusterNumber
- shl ax,1 ; FatOffset = ClusterNumber * 2
- push si ; Save si
- mov si,ax ; si = FatOffset
- shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
- add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
- cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- mov bx,2
- push es
- push ds
- pop es
- call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
- pop es
- mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- mov bx,word ptr [si] ; bx = NextClusterNumber
- mov ax,cx ; ax = ClusterNumber
- pop si ; Restore si
- dec bx ; bx = NextClusterNumber - 1
- cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- inc bx ; bx = NextClusterNumber
- inc si ; NumberOfClusters++
- mov cx,bx ; ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- inc bx
- pop ax ; ax = StartCluster
- push bx ; StartCluster = NextClusterNumber
- mov cx,bx ; ClusterNumber = NextClusterNumber
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- push ax ; save start sector
- mov ax,si ; ax = NumberOfClusters
- mul bx ; ax = NumberOfClusters * SectorsPerCluster
- mov bx,ax ; bx = Number of Sectors
- pop ax ; ax = Start Sector
- call ReadBlocks
- mov si,1 ; NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- pop cx
- popa
- ret
-
-
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
-
- mov bx,word ptr [bp] ; bx = MaxSector
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push ax ; save ax
- mov ax,es ; ax = es
- shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
- and ax,07fh ; ax = Number of blocks into current seg
- add ax,bx ; ax = End Block number of transfer
- cmp ax,080h ; See if it crosses a 64K boundry
- jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
- sub ax,080h ; ax = Number of blocks past 64K boundry
- sub bx,ax ; Decrease transfer size by block overage
-NotCrossing64KBoundry:
- pop ax ; restore ax
-
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- push cs
- pop ds
- lea si, [ErrorString]
- mov cx, 7
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- mov ax,0b800h
- mov es,ax
- mov di,160
- rep movsw
-Halt:
- jmp Halt
-
-ErrorString:
- db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
- org 01feh
- dw 0aa55h
-
-;******************************************************************************
-;******************************************************************************
-;******************************************************************************
-
-DELAY_PORT equ 0edh ; Port to use for 1uS delay
-KBD_CONTROL_PORT equ 060h ; 8042 control port
-KBD_STATUS_PORT equ 064h ; 8042 status port
-WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
-ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
-
- org 200h
- jmp start
-Em64String:
- 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
-
-start:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,MyStack
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[160],'a'
-; mov ax,cs
-; mov es,ax
-
- mov ebx,0
- lea edi,MemoryMap
-MemMapLoop:
- mov eax,0e820h
- mov ecx,20
- mov edx,'SMAP'
- int 15h
- jc MemMapDone
- add edi,20
- cmp ebx,0
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- lea eax,MemoryMap
- sub edi,eax ; Get the address of the memory map
- mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
-
- xor ebx,ebx
- mov bx,cs ; BX=segment
- shl ebx,4 ; BX="linear" address of segment base
- lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
- mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
- lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
- mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
- lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
-
- add ebx,01000h ; Source of EFI32
- mov dword ptr [JUMP+2],ebx
- add ebx,01000h
- mov esi,ebx ; Source of EFILDR32
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[162],'b'
-; mov ax,cs
-; mov es,ax
-
-;
-; Enable A20 Gate
-;
-
- mov ax,2401h ; Enable A20 Gate
- int 15h
- jnc A20GateEnabled ; Jump if it suceeded
-
-;
-; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-;
-
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- out DELAY_PORT,ax ; Delay 1 uS
- mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
- out KBD_STATUS_PORT,al ; Send command to the 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- mov al,ENABLE_A20_CMD ; gate address bit 20 on
- out KBD_CONTROL_PORT,al ; Send command to thre 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- mov cx,25 ; Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- out DELAY_PORT,ax ; Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
- mov bx,0008h ; Flat data descriptor
-;
-; DISABLE INTERRUPTS - Entering Protected Mode
-;
-
- cli
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[164],'c'
-; mov ax,cs
-; mov es,ax
-
- db 66h
- lgdt fword ptr [gdtr]
- db 66h
- lidt fword ptr [idtr]
-
- mov eax,cr0
- or al,1
- mov cr0,eax
-JUMP:
-; jmp far 0010:00020000
- db 066h
- db 0eah
- dd 000020000h
- dw 00010h
-
-Empty8042InputBuffer:
- mov cx,0
-Empty8042Loop:
- out DELAY_PORT,ax ; Delay 1us
- in al,KBD_STATUS_PORT ; Read the 8042 Status Port
- and al,02h ; Check the Input Buffer Full Flag
- loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; data
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
- dd 0 ; (GDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; global descriptor table (GDT)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-public GDT_BASE
-GDT_BASE:
-; null descriptor
-NULL_SEL equ $-GDT_BASE
- dw 0 ; limit 15:0
- dw 0 ; base 15:0
- db 0 ; base 23:16
- db 0 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
-
-; linear data segment descriptor
-LINEAR_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; linear code segment descriptor
-LINEAR_CODE_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system data segment descriptor
-SYS_DATA_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system code segment descriptor
-SYS_CODE_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE3_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE4_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE5_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-GDT_END:
-
- align 02h
-
-
-
-idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
- dd 0 ; (IDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; interrupt descriptor table (IDT)
-;
-; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-; mappings. This implementation only uses the system timer and all other
-; IRQs will remain masked. The descriptors for vectors 33+ are provided
-; for convenience.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;idt_tag db "IDT",0
- align 02h
-
-public IDT_BASE
-IDT_BASE:
-; divide by zero (INT 0)
-DIV_ZERO_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; debug exception (INT 1)
-DEBUG_EXCEPT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; NMI (INT 2)
-NMI_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; soft breakpoint (INT 3)
-BREAKPOINT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; overflow (INT 4)
-OVERFLOW_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; bounds check (INT 5)
-BOUNDS_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; invalid opcode (INT 6)
-INVALID_OPCODE_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; device not available (INT 7)
-DEV_NOT_AVAIL_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; double fault (INT 8)
-DOUBLE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Coprocessor segment overrun - reserved (INT 9)
-RSVD_INTR_SEL1 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; invalid TSS (INT 0ah)
-INVALID_TSS_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; segment not present (INT 0bh)
-SEG_NOT_PRESENT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; stack fault (INT 0ch)
-STACK_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; general protection (INT 0dh)
-GP_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; page fault (INT 0eh)
-PAGE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Intel reserved - do not use (INT 0fh)
-RSVD_INTR_SEL2 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; floating point error (INT 10h)
-FLT_POINT_ERR_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; alignment check (INT 11h)
-ALIGNMENT_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; machine check (INT 12h)
-MACHINE_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; SIMD floating-point exception (INT 13h)
-SIMD_EXCEPTION_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- db (85 * 8) dup(0)
-
-; IRQ 0 (System timer) - (INT 68h)
-IRQ0_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 1 (8042 Keyboard controller) - (INT 69h)
-IRQ1_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-IRQ2_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 3 (COM 2) - (INT 6bh)
-IRQ3_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 4 (COM 1) - (INT 6ch)
-IRQ4_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 5 (LPT 2) - (INT 6dh)
-IRQ5_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 6 (Floppy controller) - (INT 6eh)
-IRQ6_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 7 (LPT 1) - (INT 6fh)
-IRQ7_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 8 (RTC Alarm) - (INT 70h)
-IRQ8_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 9 - (INT 71h)
-IRQ9_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 10 - (INT 72h)
-IRQ10_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 11 - (INT 73h)
-IRQ11_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 12 (PS/2 mouse) - (INT 74h)
-IRQ12_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 13 (Floating point error) - (INT 75h)
-IRQ13_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 14 (Secondary IDE) - (INT 76h)
-IRQ14_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 15 (Primary IDE) - (INT 77h)
-IRQ15_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-IDT_END:
-
- align 02h
-
-MemoryMapSize dd 0
-MemoryMap dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
-
- 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
- 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
-
- org 0fe0h
-MyStack:
- ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- ; known low address (20f00) so it can be set up by PlMapIrqToVect in
- ; 8259.c
-
- int 8
- iret
-
- int 9
- iret
-
- int 10
- iret
-
- int 11
- iret
-
- int 12
- iret
-
- int 13
- iret
-
- int 14
- iret
-
- int 15
- iret
-
-
- org 0ffeh
-BlockSignature:
- dw 0aa55h
-
- end
diff --git a/DuetPkg/BootSector/start32.S b/DuetPkg/BootSector/start32.S deleted file mode 100644 index dc683f585b..0000000000 --- a/DuetPkg/BootSector/start32.S +++ /dev/null @@ -1,927 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* start32.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
- #.MODEL small
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
- .org 0x0
-
-.global _start
-_start:
-
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-SectorSize: .word 0 # Sector Size - 2 bytes
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 1 byte
-ReservedSectors: .word 0 # Reserved Sectors - 2 bytes
-NoFats: .byte 0 # Number of FATs - 1 byte
-RootEntries: .word 0 # Root Entries - 2 bytes
-Sectors: .word 0 # Number of Sectors - 2 bytes
-Media: .byte 0 # Media - 1 byte
-SectorsPerFat16: .word 0 # Sectors Per FAT for FAT12/FAT16 - 2 byte
-SectorsPerTrack: .word 0 # Sectors Per Track - 2 bytes
-Heads: .word 0 # Heads - 2 bytes
-HiddenSectors: .long 0 # Hidden Sectors - 4 bytes
-LargeSectors: .long 0 # Large Sectors - 4 bytes
-
-#******************************************************************************
-#
-#The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
-#the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
-#
-#******************************************************************************
-
-SectorsPerFat32: .long 0 # Sectors Per FAT for FAT32 - 4 bytes
-ExtFlags: .word 0 # Mirror Flag - 2 bytes
-FSVersion: .word 0 # File System Version - 2 bytes
-RootCluster: .long 0 # 1st Cluster Number of Root Dir - 4 bytes
-FSInfo: .word 0 # Sector Number of FSINFO - 2 bytes
-BkBootSector: .word 0 # Sector Number of Bk BootSector - 2 bytes
-Reserved: .fill 12,1,0 # Reserved Field - 12 bytes
-PhysicalDrive: .byte 0 # Physical Drive Number - 1 byte
-Reserved1: .byte 0 # Reserved Field - 1 byte
-Signature: .byte 0 # Extended Boot Signature - 1 byte
-VolId: .ascii " " # Volume Serial Number - 4 bytes
-FatLabel: .ascii " " # Volume Label - 11 bytes
-FileSystemType: .ascii "FAT32 " # File System Type - 8 bytes
-
-BootSectorEntryPoint:
- #ASSUME ds:@code
- #ASSUME ss:@code
- # ds = 1000, es = 2000 + x (size of first cluster >> 4)
- # cx = Start Cluster of EfiLdr
- # dx = Start Cluster of Efivar.bin
-
-# Re use the BPB data stored in Boot Sector
- movw $0x7c00, %bp
-
-
- pushw %cx
-# Read Efivar.bin
-# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- movw $0x1900, %ax
- movw %ax, %es
- testw %dx, %dx
- jnz CheckVarStoreSize
-
- movb $1, %al
-NoVarStore:
- pushw %es
-# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- movb %al, %es:4
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- movw %dx, %di
- cmpl $0x4000, %ds:2(%di)
- movb $2, %al
- jne NoVarStore
-
-LoadVarStore:
- movb $0, %al
- movb %al, %es:4
- movw (%di), %cx
-# ES:DI = 1500:0
- xorw %di, %di
- pushw %es
- movw $0x1500, %ax
- movw %ax, %es
- call ReadFile
-SaveVolumeId:
- popw %es
- movw VolId(%bp), %ax
- movw %ax, %es:0 # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- movw VolId+2(%bp), %ax
- movw %ax, %es:2
-
-# Read Efildr
- popw %cx
-# cx = Start Cluster of Efildr -> BS.com has filled already
-# ES:DI = 2000:0, first cluster will be read again
- xorw %di, %di # di = 0
- movw $0x2000, %ax
- movw %ax, %es
- call ReadFile
- movw %cs, %ax
- movw %ax, %cs:JumpSegment
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x200
-JumpSegment:
- .word 0x2000
-
-
-
-
-# ****************************************************************************
-# ReadFile
-#
-# Arguments:
-# CX = Start Cluster of File
-# ES:DI = Buffer to store file content read from disk
-#
-# Return:
-# (ES << 4 + DI) = end of file content Buffer
-#
-# ****************************************************************************
-ReadFile:
-# si = NumberOfClusters
-# cx = ClusterNumber
-# dx = CachedFatSectorNumber
-# ds:0000 = CacheFatSectorBuffer
-# es:di = Buffer to load file
-# bx = NextClusterNumber
- pusha
- movw $1, %si # NumberOfClusters = 1
- pushw %cx # Push Start Cluster onto stack
- movw $0xfff, %dx # CachedFatSectorNumber = 0xfff
-FatChainLoop:
- movw %cx, %ax # ax = ClusterNumber
- andw $0xfff8, %ax # ax = ax & 0xfff8
- cmpw $0xfff8, %ax # See if this is the last cluster
- je FoundLastCluster # Jump if last cluster found
- movw %cx, %ax # ax = ClusterNumber
- shlw $2, %ax # FatOffset = ClusterNumber * 4
- pushw %si # Save si
- movw %ax, %si # si = FatOffset
- shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
- addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK
- cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- movw $2, %bx
- pushw %es
- pushw %ds
- popw %es
- call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
- popw %es
- movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- movw (%si), %bx # bx = NextClusterNumber
- movw %cx, %ax # ax = ClusterNumber
- popw %si # Restore si
- decw %bx # bx = NextClusterNumber - 1
- cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- incw %bx # bx = NextClusterNumber
- incw %si # NumberOfClusters++
- movw %bx, %cx # ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- incw %bx
- popw %ax # ax = StartCluster
- pushw %bx # StartCluster = NextClusterNumber
- movw %bx, %cx # ClusterNumber = NextClusterNumber
- subw $2, %ax # ax = StartCluster - 2
- xorb %bh, %bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- pushw %ax # save start sector
- movw %si, %ax # ax = NumberOfClusters
- mulw %bx # ax = NumberOfClusters * SectorsPerCluster
- movw %ax, %bx # bx = Number of Sectors
- popw %ax # ax = Start Sector
- call ReadBlocks
- movw $1, %si # NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- popw %cx
- popa
- ret
-
-
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax, %esi # esi = Start LBA
- movw %bx, %cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc, %bp # bp = 0x7bfc
- movl %esi, %eax # eax = Start LBA
- xorl %edx, %edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
-
- movw (%bp), %bx # bx = MaxSector
- subw %dx, %bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx, %bx # bx = Blocks
-LimitTransfer:
- pushw %ax # save ax
- movw %es, %ax # ax = es
- shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
- andw $0x7f, %ax # ax = Number of blocks into current seg
- addw %bx, %ax # ax = End Block number of transfer
- cmpw $0x80, %ax # See if it crosses a 64K boundry
- jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
- subw $0x80, %ax # ax = Number of blocks past 64K boundry
- subw %ax, %bx # Decrease transfer size by block overage
-NotCrossing64KBoundry:
- popw %ax # restore ax
-
- pushw %cx
- movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx, %dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl, %dh # dh = Head
- movw $0x7c00, %bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al, %ch # ch = Cylinder
- movb %bl, %al # al = Blocks
- movb $2, %ah # ah = Function 2
- movw %di, %bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx, %ebx
- addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
- movw %es, %ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx, %ax
- movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0, %cx
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- pushw %cs
- popw %ds
- leaw ErrorString, %si
- movw $7, %cx
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- movw $0xb800, %ax
- movw %ax, %es
- movw $160, %di
- rep
- movsw
-Halt:
- jmp Halt
-
-ErrorString:
- .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
-
- .org 0x01fa
-LBAOffsetForBootSector:
- .long 0x0
-
- .org 0x01fe
- .word 0xaa55
-
-#******************************************************************************
-#******************************************************************************
-#******************************************************************************
-
-.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
-.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
-.equ KBD_STATUS_PORT, 0x064 # 8042 status port
-.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
-.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
-
- .org 0x200
- jmp start
-Em64String:
- .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
-
-start:
- movw %cs, %ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %ss
- movw $MyStack, %sp
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[160],'a'
-# mov ax,cs
-# mov es,ax
-
- movl $0, %ebx
- leal MemoryMap, %edi
-MemMapLoop:
- movl $0xe820, %eax
- movl $20, %ecx
- movl $0x534d4150, %edx # 0x534d4150 = 'SMAP'
- int $0x15
- jc MemMapDone
- addl $20, %edi
- cmpl $0, %ebx
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- leal MemoryMap, %eax
- subl %eax, %edi # Get the address of the memory map
- movl %edi, MemoryMapSize # Save the size of the memory map
-
- xorl %ebx, %ebx
- movw %cs, %bx # BX=segment
- shll $4, %ebx # BX="linear" address of segment base
- leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
- movl %eax, gdtr + 2 # Put address of gdt into the gdtr
- leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
- movl %eax, idtr + 2 # Put address of idt into the idtr
- leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
-
- addl $0x1000, %ebx # Source of EFI32
- movl %ebx, JUMP+2
- addl $0x1000, %ebx
- movl %ebx, %esi # Source of EFILDR32
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[162],'b'
-# mov ax,cs
-# mov es,ax
-
-#
-# Enable A20 Gate
-#
-
- movw $0x2401, %ax # Enable A20 Gate
- int $0x15
- jnc A20GateEnabled # Jump if it suceeded
-
-#
-# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-#
-
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- outw %ax, $DELAY_PORT # Delay 1 uS
- movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
- outb %al, $KBD_STATUS_PORT # Send command to the 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- movb $ENABLE_A20_CMD, %al # gate address bit 20 on
- outb %al, $KBD_CONTROL_PORT # Send command to thre 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- movw $25, %cx # Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- outw %ax, $DELAY_PORT # Delay 1 uS
- loopl Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
- movw $0x0008, %bx # Flat data descriptor
-#
-# DISABLE INTERRUPTS - Entering Protected Mode
-#
-
- cli
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[164],'c'
-# mov ax,cs
-# mov es,ax
-
- .byte 0x66
- lgdt gdtr
- .byte 0x66
- lidt idtr
-
- movl %cr0, %eax
- orb $1, %al
- movl %eax, %cr0
-JUMP:
-# jmp far 0010:00020000
- .byte 0x66
- .byte 0xea
- .long 0x00020000
- .word 0x0010
-
-Empty8042InputBuffer:
- movw $0, %cx
-Empty8042Loop:
- outw %ax, $DELAY_PORT # Delay 1us
- inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port
- andb $0x2, %al # Check the Input Buffer Full Flag
- loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-##############################################################################
-# data
-##############################################################################
-
- .p2align 1
-
-gdtr: .word GDT_END - GDT_BASE - 1
- .long 0 # (GDT base gets set above)
-##############################################################################
-# global descriptor table (GDT)
-##############################################################################
-
- .p2align 1
-
-GDT_BASE:
-# null descriptor
-.equ NULL_SEL, .-GDT_BASE
- .word 0 # limit 15:0
- .word 0 # base 15:0
- .byte 0 # base 23:16
- .byte 0 # type
- .byte 0 # limit 19:16, flags
- .byte 0 # base 31:24
-
-# linear data segment descriptor
-.equ LINEAR_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# linear code segment descriptor
-.equ LINEAR_CODE_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system data segment descriptor
-.equ SYS_DATA_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system code segment descriptor
-.equ SYS_CODE_SEL, .-GDT_BASE
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE3_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE4_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE5_SEL, .-GDT_BASE
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-GDT_END:
-
- .p2align 1
-
-
-
-idtr: .word IDT_END - IDT_BASE - 1
- .long 0 # (IDT base gets set above)
-##############################################################################
-# interrupt descriptor table (IDT)
-#
-# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-# mappings. This implementation only uses the system timer and all other
-# IRQs will remain masked. The descriptors for vectors 33+ are provided
-# for convenience.
-##############################################################################
-
-#idt_tag db "IDT",0
- .p2align 1
-
-IDT_BASE:
-# divide by zero (INT 0)
-.equ DIV_ZERO_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# debug exception (INT 1)
-.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# NMI (INT 2)
-.equ NMI_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# soft breakpoint (INT 3)
-.equ BREAKPOINT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# overflow (INT 4)
-.equ OVERFLOW_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# bounds check (INT 5)
-.equ BOUNDS_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# invalid opcode (INT 6)
-.equ INVALID_OPCODE_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# device not available (INT 7)
-.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# double fault (INT 8)
-.equ DOUBLE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Coprocessor segment overrun - reserved (INT 9)
-.equ RSVD_INTR_SEL1, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# invalid TSS (INT 0ah)
-.equ INVALID_TSS_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# segment not present (INT 0bh)
-.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# stack fault (INT 0ch)
-.equ STACK_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# general protection (INT 0dh)
-.equ GP_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# page fault (INT 0eh)
-.equ PAGE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Intel reserved - do not use (INT 0fh)
-.equ RSVD_INTR_SEL2, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# floating point error (INT 10h)
-.equ FLT_POINT_ERR_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# alignment check (INT 11h)
-.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# machine check (INT 12h)
-.equ MACHINE_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# SIMD floating-point exception (INT 13h)
-.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- .fill 85 * 8, 1, 0
-
-# IRQ 0 (System timer) - (INT 68h)
-.equ IRQ0_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 1 (8042 Keyboard controller) - (INT 69h)
-.equ IRQ1_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-.equ IRQ2_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 3 (COM 2) - (INT 6bh)
-.equ IRQ3_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 4 (COM 1) - (INT 6ch)
-.equ IRQ4_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 5 (LPT 2) - (INT 6dh)
-.equ IRQ5_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 6 (Floppy controller) - (INT 6eh)
-.equ IRQ6_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 7 (LPT 1) - (INT 6fh)
-.equ IRQ7_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 8 (RTC Alarm) - (INT 70h)
-.equ IRQ8_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 9 - (INT 71h)
-.equ IRQ9_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 10 - (INT 72h)
-.equ IRQ10_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 11 - (INT 73h)
-.equ IRQ11_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 12 (PS/2 mouse) - (INT 74h)
-.equ IRQ12_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 13 (Floating point error) - (INT 75h)
-.equ IRQ13_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 14 (Secondary IDE) - (INT 76h)
-.equ IRQ14_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-# IRQ 15 (Primary IDE) - (INT 77h)
-.equ IRQ15_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .word SYS_CODE_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
-
-IDT_END:
-
- .p2align 1
-
-MemoryMapSize: .long 0
-MemoryMap: .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
-
- .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
- .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
-
- .org 0x0fe0
-MyStack:
- # below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- # back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- # known low address (20f00) so it can be set up by PlMapIrqToVect in
- # 8259.c
-
- int $8
- iret
-
- int $9
- iret
-
- int $10
- iret
-
- int $11
- iret
-
- int $12
- iret
-
- int $13
- iret
-
- int $14
- iret
-
- int $15
- iret
-
-
- .org 0x0ffe
-BlockSignature:
- .word 0xaa55
-
-
diff --git a/DuetPkg/BootSector/start32.asm b/DuetPkg/BootSector/start32.asm deleted file mode 100644 index aaf04b86bc..0000000000 --- a/DuetPkg/BootSector/start32.asm +++ /dev/null @@ -1,924 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* start32.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-SectorSize dw 0 ; Sector Size - 2 bytes
-SectorsPerCluster db 0 ; Sector Per Cluster - 1 byte
-ReservedSectors dw 0 ; Reserved Sectors - 2 bytes
-NoFats db 0 ; Number of FATs - 1 byte
-RootEntries dw 0 ; Root Entries - 2 bytes
-Sectors dw 0 ; Number of Sectors - 2 bytes
-Media db 0 ; Media - 1 byte
-SectorsPerFat16 dw 0 ; Sectors Per FAT for FAT12/FAT16 - 2 byte
-SectorsPerTrack dw 0 ; Sectors Per Track - 2 bytes
-Heads dw 0 ; Heads - 2 bytes
-HiddenSectors dd 0 ; Hidden Sectors - 4 bytes
-LargeSectors dd 0 ; Large Sectors - 4 bytes
-
-;******************************************************************************
-;
-;The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
-;the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
-;
-;******************************************************************************
-
-SectorsPerFat32 dd 0 ; Sectors Per FAT for FAT32 - 4 bytes
-ExtFlags dw 0 ; Mirror Flag - 2 bytes
-FSVersion dw 0 ; File System Version - 2 bytes
-RootCluster dd 0 ; 1st Cluster Number of Root Dir - 4 bytes
-FSInfo dw 0 ; Sector Number of FSINFO - 2 bytes
-BkBootSector dw 0 ; Sector Number of Bk BootSector - 2 bytes
-Reserved db 12 dup(0) ; Reserved Field - 12 bytes
-PhysicalDrive db 0 ; Physical Drive Number - 1 byte
-Reserved1 db 0 ; Reserved Field - 1 byte
-Signature db 0 ; Extended Boot Signature - 1 byte
-VolId db " " ; Volume Serial Number - 4 bytes
-FatLabel db " " ; Volume Label - 11 bytes
-FileSystemType db "FAT32 " ; File System Type - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
- ; ds = 1000, es = 2000 + x (size of first cluster >> 4)
- ; cx = Start Cluster of EfiLdr
- ; dx = Start Cluster of Efivar.bin
-
-; Re use the BPB data stored in Boot Sector
- mov bp,07c00h
-
-
- push cx
-; Read Efivar.bin
-; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- mov ax,01900h
- mov es,ax
- test dx,dx
- jnz CheckVarStoreSize
-
- mov al,1
-NoVarStore:
- push es
-; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- mov byte ptr es:[4],al
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- mov di,dx
- cmp dword ptr ds:[di+2], 04000h
- mov al,2
- jne NoVarStore
-
-LoadVarStore:
- mov al,0
- mov byte ptr es:[4],al
- mov cx,word ptr[di]
-; ES:DI = 1500:0
- xor di,di
- push es
- mov ax,01500h
- mov es,ax
- call ReadFile
-SaveVolumeId:
- pop es
- mov ax,word ptr [bp+VolId]
- mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- mov ax,word ptr [bp+VolId+2]
- mov word ptr es:[2],ax
-
-; Read Efildr
- pop cx
-; cx = Start Cluster of Efildr -> BS.com has filled already
-; ES:DI = 2000:0, first cluster will be read again
- xor di,di ; di = 0
- mov ax,02000h
- mov es,ax
- call ReadFile
- mov ax,cs
- mov word ptr cs:[JumpSegment],ax
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0200h
-JumpSegment:
- dw 2000h
-
-
-
-
-; ****************************************************************************
-; ReadFile
-;
-; Arguments:
-; CX = Start Cluster of File
-; ES:DI = Buffer to store file content read from disk
-;
-; Return:
-; (ES << 4 + DI) = end of file content Buffer
-;
-; ****************************************************************************
-ReadFile:
-; si = NumberOfClusters
-; cx = ClusterNumber
-; dx = CachedFatSectorNumber
-; ds:0000 = CacheFatSectorBuffer
-; es:di = Buffer to load file
-; bx = NextClusterNumber
- pusha
- mov si,1 ; NumberOfClusters = 1
- push cx ; Push Start Cluster onto stack
- mov dx,0fffh ; CachedFatSectorNumber = 0xfff
-FatChainLoop:
- mov ax,cx ; ax = ClusterNumber
- and ax,0fff8h ; ax = ax & 0xfff8
- cmp ax,0fff8h ; See if this is the last cluster
- je FoundLastCluster ; Jump if last cluster found
- mov ax,cx ; ax = ClusterNumber
- shl ax,2 ; FatOffset = ClusterNumber * 4
- push si ; Save si
- mov si,ax ; si = FatOffset
- shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
- add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
- cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- mov bx,2
- push es
- push ds
- pop es
- call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
- pop es
- mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- mov bx,word ptr [si] ; bx = NextClusterNumber
- mov ax,cx ; ax = ClusterNumber
- pop si ; Restore si
- dec bx ; bx = NextClusterNumber - 1
- cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- inc bx ; bx = NextClusterNumber
- inc si ; NumberOfClusters++
- mov cx,bx ; ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- inc bx
- pop ax ; ax = StartCluster
- push bx ; StartCluster = NextClusterNumber
- mov cx,bx ; ClusterNumber = NextClusterNumber
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- push ax ; save start sector
- mov ax,si ; ax = NumberOfClusters
- mul bx ; ax = NumberOfClusters * SectorsPerCluster
- mov bx,ax ; bx = Number of Sectors
- pop ax ; ax = Start Sector
- call ReadBlocks
- mov si,1 ; NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- pop cx
- popa
- ret
-
-
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
-
- mov bx,word ptr [bp] ; bx = MaxSector
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push ax ; save ax
- mov ax,es ; ax = es
- shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
- and ax,07fh ; ax = Number of blocks into current seg
- add ax,bx ; ax = End Block number of transfer
- cmp ax,080h ; See if it crosses a 64K boundry
- jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
- sub ax,080h ; ax = Number of blocks past 64K boundry
- sub bx,ax ; Decrease transfer size by block overage
-NotCrossing64KBoundry:
- pop ax ; restore ax
-
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- push cs
- pop ds
- lea si, [ErrorString]
- mov cx, 7
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- mov ax,0b800h
- mov es,ax
- mov di,160
- rep movsw
-Halt:
- jmp Halt
-
-ErrorString:
- db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
- org 01feh
- dw 0aa55h
-
-;******************************************************************************
-;******************************************************************************
-;******************************************************************************
-
-DELAY_PORT equ 0edh ; Port to use for 1uS delay
-KBD_CONTROL_PORT equ 060h ; 8042 control port
-KBD_STATUS_PORT equ 064h ; 8042 status port
-WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
-ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
-
- org 200h
- jmp start
-Em64String:
- 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
-
-start:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,MyStack
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[160],'a'
-; mov ax,cs
-; mov es,ax
-
- mov ebx,0
- lea edi,MemoryMap
-MemMapLoop:
- mov eax,0e820h
- mov ecx,20
- mov edx,'SMAP'
- int 15h
- jc MemMapDone
- add edi,20
- cmp ebx,0
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- lea eax,MemoryMap
- sub edi,eax ; Get the address of the memory map
- mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
-
- xor ebx,ebx
- mov bx,cs ; BX=segment
- shl ebx,4 ; BX="linear" address of segment base
- lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
- mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
- lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
- mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
- lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
-
- add ebx,01000h ; Source of EFI32
- mov dword ptr [JUMP+2],ebx
- add ebx,01000h
- mov esi,ebx ; Source of EFILDR32
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[162],'b'
-; mov ax,cs
-; mov es,ax
-
-;
-; Enable A20 Gate
-;
-
- mov ax,2401h ; Enable A20 Gate
- int 15h
- jnc A20GateEnabled ; Jump if it suceeded
-
-;
-; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-;
-
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- out DELAY_PORT,ax ; Delay 1 uS
- mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
- out KBD_STATUS_PORT,al ; Send command to the 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- mov al,ENABLE_A20_CMD ; gate address bit 20 on
- out KBD_CONTROL_PORT,al ; Send command to thre 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- mov cx,25 ; Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- out DELAY_PORT,ax ; Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
- mov bx,0008h ; Flat data descriptor
-;
-; DISABLE INTERRUPTS - Entering Protected Mode
-;
-
- cli
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[164],'c'
-; mov ax,cs
-; mov es,ax
-
- db 66h
- lgdt fword ptr [gdtr]
- db 66h
- lidt fword ptr [idtr]
-
- mov eax,cr0
- or al,1
- mov cr0,eax
-JUMP:
-; jmp far 0010:00020000
- db 066h
- db 0eah
- dd 000020000h
- dw 00010h
-
-Empty8042InputBuffer:
- mov cx,0
-Empty8042Loop:
- out DELAY_PORT,ax ; Delay 1us
- in al,KBD_STATUS_PORT ; Read the 8042 Status Port
- and al,02h ; Check the Input Buffer Full Flag
- loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; data
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
- dd 0 ; (GDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; global descriptor table (GDT)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-public GDT_BASE
-GDT_BASE:
-; null descriptor
-NULL_SEL equ $-GDT_BASE
- dw 0 ; limit 15:0
- dw 0 ; base 15:0
- db 0 ; base 23:16
- db 0 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
-
-; linear data segment descriptor
-LINEAR_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; linear code segment descriptor
-LINEAR_CODE_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system data segment descriptor
-SYS_DATA_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system code segment descriptor
-SYS_CODE_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE3_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE4_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE5_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-GDT_END:
-
- align 02h
-
-
-
-idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
- dd 0 ; (IDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; interrupt descriptor table (IDT)
-;
-; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-; mappings. This implementation only uses the system timer and all other
-; IRQs will remain masked. The descriptors for vectors 33+ are provided
-; for convenience.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;idt_tag db "IDT",0
- align 02h
-
-public IDT_BASE
-IDT_BASE:
-; divide by zero (INT 0)
-DIV_ZERO_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; debug exception (INT 1)
-DEBUG_EXCEPT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; NMI (INT 2)
-NMI_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; soft breakpoint (INT 3)
-BREAKPOINT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; overflow (INT 4)
-OVERFLOW_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; bounds check (INT 5)
-BOUNDS_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; invalid opcode (INT 6)
-INVALID_OPCODE_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; device not available (INT 7)
-DEV_NOT_AVAIL_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; double fault (INT 8)
-DOUBLE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Coprocessor segment overrun - reserved (INT 9)
-RSVD_INTR_SEL1 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; invalid TSS (INT 0ah)
-INVALID_TSS_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; segment not present (INT 0bh)
-SEG_NOT_PRESENT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; stack fault (INT 0ch)
-STACK_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; general protection (INT 0dh)
-GP_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; page fault (INT 0eh)
-PAGE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Intel reserved - do not use (INT 0fh)
-RSVD_INTR_SEL2 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; floating point error (INT 10h)
-FLT_POINT_ERR_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; alignment check (INT 11h)
-ALIGNMENT_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; machine check (INT 12h)
-MACHINE_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; SIMD floating-point exception (INT 13h)
-SIMD_EXCEPTION_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- db (85 * 8) dup(0)
-
-; IRQ 0 (System timer) - (INT 68h)
-IRQ0_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 1 (8042 Keyboard controller) - (INT 69h)
-IRQ1_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-IRQ2_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 3 (COM 2) - (INT 6bh)
-IRQ3_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 4 (COM 1) - (INT 6ch)
-IRQ4_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 5 (LPT 2) - (INT 6dh)
-IRQ5_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 6 (Floppy controller) - (INT 6eh)
-IRQ6_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 7 (LPT 1) - (INT 6fh)
-IRQ7_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 8 (RTC Alarm) - (INT 70h)
-IRQ8_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 9 - (INT 71h)
-IRQ9_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 10 - (INT 72h)
-IRQ10_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 11 - (INT 73h)
-IRQ11_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 12 (PS/2 mouse) - (INT 74h)
-IRQ12_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 13 (Floating point error) - (INT 75h)
-IRQ13_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 14 (Secondary IDE) - (INT 76h)
-IRQ14_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-; IRQ 15 (Primary IDE) - (INT 77h)
-IRQ15_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
-
-IDT_END:
-
- align 02h
-
-MemoryMapSize dd 0
-MemoryMap dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
-
- 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
- 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
-
- org 0fe0h
-MyStack:
- ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- ; known low address (20f00) so it can be set up by PlMapIrqToVect in
- ; 8259.c
-
- int 8
- iret
-
- int 9
- iret
-
- int 10
- iret
-
- int 11
- iret
-
- int 12
- iret
-
- int 13
- iret
-
- int 14
- iret
-
- int 15
- iret
-
-
- org 0ffeh
-BlockSignature:
- dw 0aa55h
-
- end
diff --git a/DuetPkg/BootSector/start64.S b/DuetPkg/BootSector/start64.S deleted file mode 100644 index 75626b86a4..0000000000 --- a/DuetPkg/BootSector/start64.S +++ /dev/null @@ -1,1149 +0,0 @@ -#------------------------------------------------------------------------------
-#*
-#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-#* This program and the accompanying materials
-#* are licensed and made available under the terms and conditions of the BSD License
-#* which accompanies this distribution. The full text of the license may be found at
-#* http://opensource.org/licenses/bsd-license.php
-#*
-#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#*
-#* start64.asm
-#*
-#* Abstract:
-#*
-#------------------------------------------------------------------------------
-
-
- .stack:
- .486p:
- .code16
-
-.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
-.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
-.equ BLOCK_SIZE, 0x0200
-.equ BLOCK_MASK, 0x01ff
-.equ BLOCK_SHIFT, 9
-
- .org 0x0
-
-.global _start
-_start:
-
-Ia32Jump:
- jmp BootSectorEntryPoint # JMP inst - 3 bytes
- nop
-
-OemId: .ascii "INTEL " # OemId - 8 bytes
-
-SectorSize: .word 0 # Sector Size - 16 bits
-SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
-ReservedSectors: .word 0 # Reserved Sectors - 16 bits
-NoFats: .byte 0 # Number of FATs - 8 bits
-RootEntries: .word 0 # Root Entries - 16 bits
-Sectors: .word 0 # Number of Sectors - 16 bits
-Media: .byte 0 # Media - 8 bits - ignored
-SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
-SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
-Heads: .word 0 # Heads - 16 bits - ignored
-HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
-LargeSectors: .long 0 # Large Sectors - 32 bits
-PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
-CurrentHead: .byte 0 # Current Head - 8 bits
-Signature: .byte 0 # Signature - 8 bits - ignored
-VolId: .ascii " " # Volume Serial Number- 4 bytes
-FatLabel: .ascii " " # Label - 11 bytes
-SystemId: .ascii "FAT12 " # SystemId - 8 bytes
-
-BootSectorEntryPoint:
- # ASSUME ds:@code"
- # ASSUME ss:@code"
- # ds = 1000, es = 2000 + x (size of first cluster >> 4)
- # cx = Start Cluster of EfiLdr
- # dx = Start Cluster of Efivar.bin
-
-# Re use the BPB data stored in Boot Sector
- movw $0x7c00,%bp
-
- pushw %cx
-# Read Efivar.bin
-# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- movw $0x1900,%ax
- movw %ax,%es
- testw %dx,%dx
- jnz CheckVarStoreSize
-
- movb $1,%al
-NoVarStore:
- pushw %es
-# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- movb %al, %es:(4)
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- movw %dx,%di
- cmpl $0x4000, %ds:2(%di)
- movb $2,%al
- jne NoVarStore
-
-LoadVarStore:
- movb $0,%al
- movb %al, %es:(4)
- movw (%di), %cx
-# ES:DI = 1500:0
- xorw %di,%di
- pushw %es
- movw $0x1500,%ax
- movw %ax,%es
- call ReadFile
-SaveVolumeId:
- popw %es
- movw VolId(%bp), %ax
- movw %ax, %es:(0)
- movw VolId+2(%bp), %ax
- movw %ax, %es:(2)
-
-# Read Efildr
- popw %cx
-# cx = Start Cluster of Efildr -> BS.com has filled already
-# ES:DI = 2000:0, first cluster will be read again
- xorw %di,%di # di = 0
- movw $0x2000,%ax
- movw %ax,%es
- call ReadFile
- movw %cs,%ax
- movw %ax, %cs:JumpSegment
-
-CheckEm64T:
- movl $0x80000001,%eax
-# cpuid
- .word 0xA20F
- btl $29,%edx
- jc CheckEm64TPass
- pushw %cs
- popw %ds
- leaw Em64String,%si
- movw $18,%cx
- jmp PrintStringAndHalt
-CheckEm64TPass:
-JumpFarInstruction:
- .byte 0xea
-JumpOffset:
- .word 0x200
-JumpSegment:
- .word 0x2000
-
-
-
-# ****************************************************************************
-# ReadFile
-#
-# Arguments:
-# CX = Start Cluster of File
-# ES:DI = Buffer to store file content read from disk
-#
-# Return:
-# (ES << 4 + DI) = end of file content Buffer
-#
-# ****************************************************************************
-ReadFile:
-# si = NumberOfClusters
-# cx = ClusterNumber
-# dx = CachedFatSectorNumber
-# ds:0000 = CacheFatSectorBuffer
-# es:di = Buffer to load file
-# bx = NextClusterNumber
- pusha
- movw $1,%si # NumberOfClusters = 1
- pushw %cx # Push Start Cluster onto stack
- movw $0xfff,%dx # CachedFatSectorNumber = 0xfff
-FatChainLoop:
- movw %cx,%ax # ax = ClusterNumber
- andw $0xff8,%ax # ax = ax & 0xff8
- cmpw $0xff8,%ax # See if this is the last cluster
- je FoundLastCluster # Jump if last cluster found
- movw %cx,%ax # ax = ClusterNumber
- shlw %ax # ax = ClusterNumber * 2
- addw %cx,%ax # ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3
- shrw %ax # FatOffset = ClusterNumber*3 / 2
- pushw %si # Save si
- movw %ax,%si # si = FatOffset
- shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
- addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK
- cmpw %dx,%ax # Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- movw $2,%bx
- pushw %es
- pushw %ds
- popw %es
- call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
- popw %es
- movw %ax,%dx # CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- movw (%si), %bx # bx = NextClusterNumber
- movw %cx,%ax # ax = ClusterNumber
- andw $1,%ax # See if this is an odd cluster number
- je EvenFatEntry
- shrw $4,%bx # NextClusterNumber = NextClusterNumber >> 4
-EvenFatEntry:
- andw $0xfff,%bx # Strip upper 4 bits of NextClusterNumber
- popw %si # Restore si
- decw %bx # bx = NextClusterNumber - 1
- cmpw %cx,%bx # See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- incw %bx # bx = NextClusterNumber
- incw %si # NumberOfClusters++
- movw %bx,%cx # ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- incw %bx
- popw %ax # ax = StartCluster
- pushw %bx # StartCluster = NextClusterNumber
- movw %bx,%cx # ClusterNumber = NextClusterNumber
- subw $2,%ax # ax = StartCluster - 2
- xorb %bh,%bh
- movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
- mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
- addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- pushw %ax # save start sector
- movw %si,%ax # ax = NumberOfClusters
- mulw %bx # ax = NumberOfClusters * SectorsPerCluster
- movw %ax,%bx # bx = Number of Sectors
- popw %ax # ax = Start Sector
- call ReadBlocks
- movw $1,%si # NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- popw %cx
- popa
- ret
-
-
-# ****************************************************************************
-# ReadBlocks - Reads a set of blocks from a block device
-#
-# AX = Start LBA
-# BX = Number of Blocks to Read
-# ES:DI = Buffer to store sectors read from disk
-# ****************************************************************************
-
-# cx = Blocks
-# bx = NumberOfBlocks
-# si = StartLBA
-
-ReadBlocks:
- pusha
- addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
- addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
- movl %eax,%esi # esi = Start LBA
- movw %bx,%cx # cx = Number of blocks to read
-ReadCylinderLoop:
- movw $0x7bfc,%bp # bp = 0x7bfc
- movl %esi,%eax # eax = Start LBA
- xorl %edx,%edx # edx = 0
- movzwl (%bp), %ebx # bx = MaxSector
- divl %ebx # ax = StartLBA / MaxSector
- incw %dx # dx = (StartLBA % MaxSector) + 1
-
- movw (%bp), %bx # bx = MaxSector
- subw %dx,%bx # bx = MaxSector - Sector
- incw %bx # bx = MaxSector - Sector + 1
- cmpw %bx,%cx # Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- movw %cx,%bx # bx = Blocks
-LimitTransfer:
- pushw %ax # save ax
- movw %es,%ax # ax = es
- shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
- andw $0x7f,%ax # ax = Number of blocks into current seg
- addw %bx,%ax # ax = End Block number of transfer
- cmpw $0x80,%ax # See if it crosses a 64K boundry
- jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
- subw $0x80,%ax # ax = Number of blocks past 64K boundry
- subw %ax,%bx # Decrease transfer size by block overage
-NotCrossing64KBoundry:
- popw %ax # restore ax
-
- pushw %cx
- movb %dl,%cl # cl = (StartLBA % MaxSector) + 1 = Sector
- xorw %dx,%dx # dx = 0
- divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
- # dx = ax % (MaxHead + 1) = Head
-
- pushw %bx # Save number of blocks to transfer
- movb %dl,%dh # dh = Head
- movw $0x7c00,%bp # bp = 0x7c00
- movb PhysicalDrive(%bp), %dl # dl = Drive Number
- movb %al,%ch # ch = Cylinder
- movb %bl,%al # al = Blocks
- movb $2,%ah # ah = Function 2
- movw %di,%bx # es:bx = Buffer address
- int $0x13
- jc DiskError
- popw %bx
- popw %cx
- movzwl %bx,%ebx
- addl %ebx,%esi # StartLBA = StartLBA + NumberOfBlocks
- subw %bx,%cx # Blocks = Blocks - NumberOfBlocks
- movw %es,%ax
- shlw $(BLOCK_SHIFT-4), %bx
- addw %bx,%ax
- movw %ax,%es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmpw $0,%cx
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- pushw %cs
- popw %ds
- leaw ErrorString,%si
- movw $7,%cx
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- movw $0xb800,%ax
- movw %ax,%es
- movw $160,%di
- rep
- movsw
-Halt:
- jmp Halt
-
-ErrorString:
- .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c
-
- .org 0x01fa
-LBAOffsetForBootSector:
- .long 0x0
-
- .org 0x01fe
- .word 0xaa55
-
-#******************************************************************************
-#******************************************************************************
-#******************************************************************************
-
-.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
-.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
-.equ KBD_STATUS_PORT, 0x064 # 8042 status port
-.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
-.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
-
- .org 0x200
- jmp start
-Em64String:
-.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
-
-start:
- movw %cs,%ax
- movw %ax,%ds
- movw %ax,%es
- movw %ax,%ss
- movw $MyStack, %sp
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[160],'a'
-# mov ax,cs
-# mov es,ax
-
- movl $0,%ebx
- leal MemoryMap, %edi
-MemMapLoop:
- movl $0xe820,%eax
- movl $20,%ecx
- movl $0x534d4150, %edx # SMAP
- int $0x15
- jc MemMapDone
- addl $20,%edi
- cmpl $0,%ebx
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- leal MemoryMap, %eax
- subl %eax,%edi # Get the address of the memory map
- movl %edi, MemoryMapSize # Save the size of the memory map
-
- xorl %ebx,%ebx
- movw %cs,%bx # BX=segment
- shll $4,%ebx # BX="linear" address of segment base
- leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
- movl %eax, (gdtr + 2) # Put address of gdt into the gdtr
- leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
- movl %eax, (idtr + 2) # Put address of idt into the idtr
- leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[162],'b'
-# mov ax,cs
-# mov es,ax
-
-#
-# Enable A20 Gate
-#
-
- movw $0x2401,%ax # Enable A20 Gate
- int $0x15
- jnc A20GateEnabled # Jump if it suceeded
-
-#
-# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-#
-
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- outw %ax, $DELAY_PORT # Delay 1 uS
- movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
- outb %al, $KBD_STATUS_PORT # Send command to the 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 # Jump if the 8042 timed out
- movb $ENABLE_A20_CMD, %al # gate address bit 20 on
- outb %al, $KBD_CONTROL_PORT # Send command to thre 8042
- call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
- movw $25,%cx # Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- outw %ax, $DELAY_PORT # Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
-
-#
-# DISABLE INTERRUPTS - Entering Protected Mode
-#
-
- cli
-
-# mov ax,0b800h
-# mov es,ax
-# mov byte ptr es:[164],'c'
-# mov ax,cs
-# mov es,ax
-
- leal OffsetIn32BitProtectedMode, %eax
- addl $0x20000+0x6,%eax
- movl %eax, OffsetIn32BitProtectedMode
-
- leal OffsetInLongMode, %eax
- addl $0x20000+0x6,%eax
- movl %eax, OffsetInLongMode
-
- #
- # load GDT
- #
- .byte 0x66
- lgdt gdtr
-
- #
- # Enable Protect Mode (set CR0.PE=1)
- #
- movl %cr0, %eax # Read CR0.
- orl $0x1,%eax # Set PE=1
- movl %eax, %cr0 # Write CR0.
- .byte 0x66
- .byte 0xea # jmp far 16:32
-OffsetIn32BitProtectedMode:
- .long 0x0000000 # offset $+8 (In32BitProtectedMode)
- .word 0x10 # selector (flat CS)
-In32BitProtectedMode:
-
-#
-# Entering Long Mode
-#
- .byte 0x66
- movw $8,%ax
- movw %ax,%ds
- movw %ax,%es
- movw %ax,%ss
-
- #
- # Enable the 64-bit page-translation-table entries by
- # setting CR4.PAE=1 (this is _required_ before activating
- # long mode). Paging is not enabled until after long mode
- # is enabled.
- #
- .byte 0xf
- .byte 0x20
- .byte 0xe0
-# mov eax, cr4
- btsl $5,%eax
- .byte 0xf
- .byte 0x22
- .byte 0xe0
-# mov cr4, eax
-
- #
- # This is the Trapolean Page Tables that are guarenteed
- # under 4GB.
- #
- # Address Map:
- # 10000 ~ 12000 - efildr (loaded)
- # 20000 ~ 21000 - start64.com
- # 21000 ~ 22000 - efi64.com
- # 22000 ~ 90000 - efildr
- # 90000 ~ 96000 - 4G pagetable (will be reload later)
- #
- .byte 0xb8
- .long 0x90000
-# mov eax, 90000h
- movl %eax, %cr3
-
- #
- # Enable long mode (set EFER.LME=1).
- #
- .byte 0xb9
- .long 0xc0000080
-# mov ecx, 0c0000080h ; EFER MSR number.
- .byte 0xf
- .byte 0x32
-# rdmsr ; Read EFER.
- .byte 0xf
- .byte 0xba
- .byte 0xe8
- .byte 0x8
-# bts eax, 8 ; Set LME=1.
- .byte 0xf
- .byte 0x30
-# wrmsr ; Write EFER.
-
- #
- # Enable paging to activate long mode (set CR0.PG=1)
- #
- movl %cr0, %eax # Read CR0.
- .byte 0xf
- .byte 0xba
- .byte 0xe8
- .byte 0x1f
-# bts eax, 31 ; Set PG=1.
- movl %eax, %cr0 # Write CR0.
- jmp GoToLongMode
-GoToLongMode:
-
- .byte 0x67
- .byte 0xea # Far Jump $+9:Selector to reload CS
-OffsetInLongMode:
- .long 00000000 # $+9 Offset is ensuing instruction boundary
- .word 0x38 # Selector is our code selector, 38h
-
-InLongMode:
- .byte 0x66
- movw $0x30,%ax
- movw %ax,%ds
-
- .byte 0x66
- movw $0x18,%ax
- movw %ax,%es
- movw %ax,%ss
- movw %ax,%ds
-
- .byte 0xbd
- .long 0x400000
-# mov ebp,000400000h ; Destination of EFILDR32
- .byte 0xbb
- .long 0x70000
-# mov ebx,000070000h ; Length of copy
-
- #
- # load idt later
- #
- .byte 0x48
- .byte 0x33
- .byte 0xc0
-# xor rax, rax
- .byte 0x66
- movw $idtr, %ax
- .byte 0x48
- .byte 0x5
- .long 0x20000
-# add rax, 20000h
-
- .byte 0xf
- .byte 0x1
- .byte 0x18
-# lidt fword ptr [rax]
-
- .byte 0x48
- .byte 0xc7
- .byte 0xc0
- .long 0x21000
-# mov rax, 21000h
- .byte 0x50
-# push rax
-
-# ret
- .byte 0xc3
-
-Empty8042InputBuffer:
- movw $0,%cx
-Empty8042Loop:
- outw %ax, $DELAY_PORT # Delay 1us
- inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port
- andb $0x2,%al # Check the Input Buffer Full Flag
- loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-##############################################################################
-# data
-##############################################################################
-
- .p2align 1
-
- gdtr: .long GDT_END - GDT_BASE - 1 # GDT limit
- .long 0 # (GDT base gets set above)
-##############################################################################
-# global descriptor table (GDT)
-##############################################################################
-
- .p2align 1
-
-GDT_BASE:
-# null descriptor
-.equ NULL_SEL, .-GDT_BASE # Selector [0x0]
- .word 0 # limit 15:0
- .word 0 # base 15:0
- .byte 0 # base 23:16
- .byte 0 # type
- .byte 0 # limit 19:16, flags
- .byte 0 # base 31:24
-
-# linear data segment descriptor
-.equ LINEAR_SEL, .-GDT_BASE # Selector [0x8]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# linear code segment descriptor
-.equ LINEAR_CODE_SEL, .-GDT_BASE # Selector [0x10]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system data segment descriptor
-.equ SYS_DATA_SEL, .-GDT_BASE # Selector [0x18]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# system code segment descriptor
-.equ SYS_CODE_SEL, .-GDT_BASE # Selector [0x20]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # present, ring 0, data, expand-up, writable
- .byte 0xCF # page-granular, 32-bit
- .byte 0
-
-# spare segment descriptor
-.equ SPARE3_SEL, .-GDT_BASE # Selector [0x28]
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-#
-# system data segment descriptor
-#
-.equ SYS_DATA64_SEL, .-GDT_BASE # Selector [0x30]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x92 # P | DPL [1..2] | 1 | 1 | C | R | A
- .byte 0xCF # G | D | L | AVL | Segment [19..16]
- .byte 0
-
-#
-# system code segment descriptor
-#
-.equ SYS_CODE64_SEL, .-GDT_BASE # Selector [0x38]
- .word 0xFFFF # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0x9A # P | DPL [1..2] | 1 | 1 | C | R | A
- .byte 0xAF # G | D | L | AVL | Segment [19..16]
- .byte 0
-
-# spare segment descriptor
-.equ SPARE4_SEL, .-GDT_BASE # Selector [0x40]
- .word 0 # limit 0xFFFFF
- .word 0 # base 0
- .byte 0
- .byte 0 # present, ring 0, data, expand-up, writable
- .byte 0 # page-granular, 32-bit
- .byte 0
-
-GDT_END:
-
- .p2align 1
-
-
-
-idtr: .long IDT_END - IDT_BASE - 1 # IDT limit
- .quad 0 # (IDT base gets set above)
-
-##############################################################################
-# interrupt descriptor table (IDT)
-#
-# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-# mappings. This implementation only uses the system timer and all other
-# IRQs will remain masked. The descriptors for vectors 33+ are provided
-# for convenience.
-##############################################################################
-
-#idt_tag db "IDT",0
- .p2align 1
-
-
-IDT_BASE:
-# divide by zero (INT 0)
-.equ DIV_ZERO_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# debug exception (INT 1)
-.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# NMI (INT 2)
-.equ NMI_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# soft breakpoint (INT 3)
-.equ BREAKPOINT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# overflow (INT 4)
-.equ OVERFLOW_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# bounds check (INT 5)
-.equ BOUNDS_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# invalid opcode (INT 6)
-.equ INVALID_OPCODE_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# device not available (INT 7)
-.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# double fault (INT 8)
-.equ DOUBLE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Coprocessor segment overrun - reserved (INT 9)
-.equ RSVD_INTR_SEL1, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# invalid TSS (INT 0ah)
-.equ INVALID_TSS_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# segment not present (INT 0bh)
-.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# stack fault (INT 0ch)
-.equ STACK_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# general protection (INT 0dh)
-.equ GP_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# page fault (INT 0eh)
-.equ PAGE_FAULT_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Intel reserved - do not use (INT 0fh)
-.equ RSVD_INTR_SEL2, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# floating point error (INT 10h)
-.equ FLT_POINT_ERR_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# alignment check (INT 11h)
-.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# machine check (INT 12h)
-.equ MACHINE_CHECK_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# SIMD floating-point exception (INT 13h)
-.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- .fill 85 * 16, 1, 0 # db (85 * 16) dup(0)
-
-# IRQ 0 (System timer) - (INT 68h)
-.equ IRQ0_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 1 (8042 Keyboard controller) - (INT 69h)
-.equ IRQ1_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-.equ IRQ2_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 3 (COM 2) - (INT 6bh)
-.equ IRQ3_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 4 (COM 1) - (INT 6ch)
-.equ IRQ4_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 5 (LPT 2) - (INT 6dh)
-.equ IRQ5_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 6 (Floppy controller) - (INT 6eh)
-.equ IRQ6_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 7 (LPT 1) - (INT 6fh)
-.equ IRQ7_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 8 (RTC Alarm) - (INT 70h)
-.equ IRQ8_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 9 - (INT 71h)
-.equ IRQ9_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 10 - (INT 72h)
-.equ IRQ10_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 11 - (INT 73h)
-.equ IRQ11_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 12 (PS/2 mouse) - (INT 74h)
-.equ IRQ12_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 13 (Floating point error) - (INT 75h)
-.equ IRQ13_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 14 (Secondary IDE) - (INT 76h)
-.equ IRQ14_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-# IRQ 15 (Primary IDE) - (INT 77h)
-.equ IRQ15_SEL, .-IDT_BASE
- .word 0 # offset 15:0
- .long SYS_CODE64_SEL # selector 15:0
- .byte 0 # 0 for interrupt gate
- .byte 0x0e | 0x80 # type = 386 interrupt gate, present
- .word 0 # offset 31:16
- .long 0 # offset 63:32
- .long 0 # 0 for reserved
-
-IDT_END:
-
- .p2align 1
-
-MemoryMapSize: .long 0
-MemoryMap: .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
- .long 0,0,0,0,0,0,0,0
-
- .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
-
- .org 0x0fe0
-MyStack:
- # below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- # back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- # known low address (20f00) so it can be set up by PlMapIrqToVect in
- # 8259.c
-
- int $8
- iret
-
- int $9
- iret
-
- int $10
- iret
-
- int $11
- iret
-
- int $12
- iret
-
- int $13
- iret
-
- int $14
- iret
-
- int $15
- iret
-
-
- .org 0x0ffe
-BlockSignature:
- .word 0xaa55
-
diff --git a/DuetPkg/BootSector/start64.asm b/DuetPkg/BootSector/start64.asm deleted file mode 100644 index e368bf3727..0000000000 --- a/DuetPkg/BootSector/start64.asm +++ /dev/null @@ -1,1147 +0,0 @@ -;------------------------------------------------------------------------------
-;*
-;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
-;* This program and the accompanying materials
-;* are licensed and made available under the terms and conditions of the BSD License
-;* which accompanies this distribution. The full text of the license may be found at
-;* http://opensource.org/licenses/bsd-license.php
-;*
-;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;*
-;* start64.asm
-;*
-;* Abstract:
-;*
-;------------------------------------------------------------------------------
-
- .model small
- .stack
- .486p
- .code
-
-FAT_DIRECTORY_ENTRY_SIZE EQU 020h
-FAT_DIRECTORY_ENTRY_SHIFT EQU 5
-BLOCK_SIZE EQU 0200h
-BLOCK_MASK EQU 01ffh
-BLOCK_SHIFT EQU 9
-
- org 0h
-Ia32Jump:
- jmp BootSectorEntryPoint ; JMP inst - 3 bytes
- nop
-
-OemId db "INTEL " ; OemId - 8 bytes
-
-SectorSize dw 0 ; Sector Size - 16 bits
-SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
-ReservedSectors dw 0 ; Reserved Sectors - 16 bits
-NoFats db 0 ; Number of FATs - 8 bits
-RootEntries dw 0 ; Root Entries - 16 bits
-Sectors dw 0 ; Number of Sectors - 16 bits
-Media db 0 ; Media - 8 bits - ignored
-SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
-SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
-Heads dw 0 ; Heads - 16 bits - ignored
-HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
-LargeSectors dd 0 ; Large Sectors - 32 bits
-PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
-CurrentHead db 0 ; Current Head - 8 bits
-Signature db 0 ; Signature - 8 bits - ignored
-VolId db " " ; Volume Serial Number- 4 bytes
-FatLabel db " " ; Label - 11 bytes
-SystemId db "FAT12 " ; SystemId - 8 bytes
-
-BootSectorEntryPoint:
- ASSUME ds:@code
- ASSUME ss:@code
- ; ds = 1000, es = 2000 + x (size of first cluster >> 4)
- ; cx = Start Cluster of EfiLdr
- ; dx = Start Cluster of Efivar.bin
-
-; Re use the BPB data stored in Boot Sector
- mov bp,07c00h
-
- push cx
-; Read Efivar.bin
-; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
- mov ax,01900h
- mov es,ax
- test dx,dx
- jnz CheckVarStoreSize
-
- mov al,1
-NoVarStore:
- push es
-; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
- mov byte ptr es:[4],al
- jmp SaveVolumeId
-
-CheckVarStoreSize:
- mov di,dx
- cmp dword ptr ds:[di+2], 04000h
- mov al,2
- jne NoVarStore
-
-LoadVarStore:
- mov al,0
- mov byte ptr es:[4],al
- mov cx,word ptr[di]
-; ES:DI = 1500:0
- xor di,di
- push es
- mov ax,01500h
- mov es,ax
- call ReadFile
-SaveVolumeId:
- pop es
- mov ax,word ptr [bp+VolId]
- mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
- mov ax,word ptr [bp+VolId+2]
- mov word ptr es:[2],ax
-
-; Read Efildr
- pop cx
-; cx = Start Cluster of Efildr -> BS.com has filled already
-; ES:DI = 2000:0, first cluster will be read again
- xor di,di ; di = 0
- mov ax,02000h
- mov es,ax
- call ReadFile
- mov ax,cs
- mov word ptr cs:[JumpSegment],ax
-
-CheckEm64T:
- mov eax, 080000001h
-; cpuid
- dw 0A20Fh
- bt edx, 29
- jc CheckEm64TPass
- push cs
- pop ds
- lea si, [Em64String]
- mov cx, 18
- jmp PrintStringAndHalt
-CheckEm64TPass:
-JumpFarInstruction:
- db 0eah
-JumpOffset:
- dw 0200h
-JumpSegment:
- dw 2000h
-
-
-
-; ****************************************************************************
-; ReadFile
-;
-; Arguments:
-; CX = Start Cluster of File
-; ES:DI = Buffer to store file content read from disk
-;
-; Return:
-; (ES << 4 + DI) = end of file content Buffer
-;
-; ****************************************************************************
-ReadFile:
-; si = NumberOfClusters
-; cx = ClusterNumber
-; dx = CachedFatSectorNumber
-; ds:0000 = CacheFatSectorBuffer
-; es:di = Buffer to load file
-; bx = NextClusterNumber
- pusha
- mov si,1 ; NumberOfClusters = 1
- push cx ; Push Start Cluster onto stack
- mov dx,0fffh ; CachedFatSectorNumber = 0xfff
-FatChainLoop:
- mov ax,cx ; ax = ClusterNumber
- and ax,0ff8h ; ax = ax & 0xff8
- cmp ax,0ff8h ; See if this is the last cluster
- je FoundLastCluster ; Jump if last cluster found
- mov ax,cx ; ax = ClusterNumber
- shl ax,1 ; ax = ClusterNumber * 2
- add ax,cx ; ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3
- shr ax,1 ; FatOffset = ClusterNumber*3 / 2
- push si ; Save si
- mov si,ax ; si = FatOffset
- shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
- add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
- and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
- cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
- je SkipFatRead
- mov bx,2
- push es
- push ds
- pop es
- call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
- pop es
- mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
-SkipFatRead:
- mov bx,word ptr [si] ; bx = NextClusterNumber
- mov ax,cx ; ax = ClusterNumber
- and ax,1 ; See if this is an odd cluster number
- je EvenFatEntry
- shr bx,4 ; NextClusterNumber = NextClusterNumber >> 4
-EvenFatEntry:
- and bx,0fffh ; Strip upper 4 bits of NextClusterNumber
- pop si ; Restore si
- dec bx ; bx = NextClusterNumber - 1
- cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
- jne ReadClusters
- inc bx ; bx = NextClusterNumber
- inc si ; NumberOfClusters++
- mov cx,bx ; ClusterNumber = NextClusterNumber
- jmp FatChainLoop
-ReadClusters:
- inc bx
- pop ax ; ax = StartCluster
- push bx ; StartCluster = NextClusterNumber
- mov cx,bx ; ClusterNumber = NextClusterNumber
- sub ax,2 ; ax = StartCluster - 2
- xor bh,bh
- mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
- mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
- add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
- push ax ; save start sector
- mov ax,si ; ax = NumberOfClusters
- mul bx ; ax = NumberOfClusters * SectorsPerCluster
- mov bx,ax ; bx = Number of Sectors
- pop ax ; ax = Start Sector
- call ReadBlocks
- mov si,1 ; NumberOfClusters = 1
- jmp FatChainLoop
-FoundLastCluster:
- pop cx
- popa
- ret
-
-
-; ****************************************************************************
-; ReadBlocks - Reads a set of blocks from a block device
-;
-; AX = Start LBA
-; BX = Number of Blocks to Read
-; ES:DI = Buffer to store sectors read from disk
-; ****************************************************************************
-
-; cx = Blocks
-; bx = NumberOfBlocks
-; si = StartLBA
-
-ReadBlocks:
- pusha
- add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
- add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
- mov esi,eax ; esi = Start LBA
- mov cx,bx ; cx = Number of blocks to read
-ReadCylinderLoop:
- mov bp,07bfch ; bp = 0x7bfc
- mov eax,esi ; eax = Start LBA
- xor edx,edx ; edx = 0
- movzx ebx,word ptr [bp] ; bx = MaxSector
- div ebx ; ax = StartLBA / MaxSector
- inc dx ; dx = (StartLBA % MaxSector) + 1
-
- mov bx,word ptr [bp] ; bx = MaxSector
- sub bx,dx ; bx = MaxSector - Sector
- inc bx ; bx = MaxSector - Sector + 1
- cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
- jg LimitTransfer
- mov bx,cx ; bx = Blocks
-LimitTransfer:
- push ax ; save ax
- mov ax,es ; ax = es
- shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
- and ax,07fh ; ax = Number of blocks into current seg
- add ax,bx ; ax = End Block number of transfer
- cmp ax,080h ; See if it crosses a 64K boundry
- jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
- sub ax,080h ; ax = Number of blocks past 64K boundry
- sub bx,ax ; Decrease transfer size by block overage
-NotCrossing64KBoundry:
- pop ax ; restore ax
-
- push cx
- mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
- xor dx,dx ; dx = 0
- div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
- ; dx = ax % (MaxHead + 1) = Head
-
- push bx ; Save number of blocks to transfer
- mov dh,dl ; dh = Head
- mov bp,07c00h ; bp = 0x7c00
- mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
- mov ch,al ; ch = Cylinder
- mov al,bl ; al = Blocks
- mov ah,2 ; ah = Function 2
- mov bx,di ; es:bx = Buffer address
- int 013h
- jc DiskError
- pop bx
- pop cx
- movzx ebx,bx
- add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
- sub cx,bx ; Blocks = Blocks - NumberOfBlocks
- mov ax,es
- shl bx,(BLOCK_SHIFT-4)
- add ax,bx
- mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
- cmp cx,0
- jne ReadCylinderLoop
- popa
- ret
-
-DiskError:
- push cs
- pop ds
- lea si, [ErrorString]
- mov cx, 7
- jmp PrintStringAndHalt
-
-PrintStringAndHalt:
- mov ax,0b800h
- mov es,ax
- mov di,160
- rep movsw
-Halt:
- jmp Halt
-
-ErrorString:
- db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
-
- org 01fah
-LBAOffsetForBootSector:
- dd 0h
-
- org 01feh
- dw 0aa55h
-
-;******************************************************************************
-;******************************************************************************
-;******************************************************************************
-
-DELAY_PORT equ 0edh ; Port to use for 1uS delay
-KBD_CONTROL_PORT equ 060h ; 8042 control port
-KBD_STATUS_PORT equ 064h ; 8042 status port
-WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
-ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
-
- org 200h
- jmp start
-Em64String:
- 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
-
-start:
- mov ax,cs
- mov ds,ax
- mov es,ax
- mov ss,ax
- mov sp,MyStack
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[160],'a'
-; mov ax,cs
-; mov es,ax
-
- mov ebx,0
- lea edi,MemoryMap
-MemMapLoop:
- mov eax,0e820h
- mov ecx,20
- mov edx,'SMAP'
- int 15h
- jc MemMapDone
- add edi,20
- cmp ebx,0
- je MemMapDone
- jmp MemMapLoop
-MemMapDone:
- lea eax,MemoryMap
- sub edi,eax ; Get the address of the memory map
- mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
-
- xor ebx,ebx
- mov bx,cs ; BX=segment
- shl ebx,4 ; BX="linear" address of segment base
- lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
- mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
- lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
- mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
- lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[162],'b'
-; mov ax,cs
-; mov es,ax
-
-;
-; Enable A20 Gate
-;
-
- mov ax,2401h ; Enable A20 Gate
- int 15h
- jnc A20GateEnabled ; Jump if it suceeded
-
-;
-; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
-;
-
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- out DELAY_PORT,ax ; Delay 1 uS
- mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
- out KBD_STATUS_PORT,al ; Send command to the 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- jnz Timeout8042 ; Jump if the 8042 timed out
- mov al,ENABLE_A20_CMD ; gate address bit 20 on
- out KBD_CONTROL_PORT,al ; Send command to thre 8042
- call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
- mov cx,25 ; Delay 25 uS for the command to complete on the 8042
-Delay25uS:
- out DELAY_PORT,ax ; Delay 1 uS
- loop Delay25uS
-Timeout8042:
-
-
-A20GateEnabled:
-
-;
-; DISABLE INTERRUPTS - Entering Protected Mode
-;
-
- cli
-
-; mov ax,0b800h
-; mov es,ax
-; mov byte ptr es:[164],'c'
-; mov ax,cs
-; mov es,ax
-
- lea eax, OffsetIn32BitProtectedMode
- add eax, 20000h + 6h
- mov dword ptr[OffsetIn32BitProtectedMode], eax
-
- lea eax, OffsetInLongMode
- add eax, 20000h + 6h
- mov dword ptr[OffsetInLongMode], eax
-
- ;
- ; load GDT
- ;
- db 66h
- lgdt fword ptr [gdtr]
-
- ;
- ; Enable Protect Mode (set CR0.PE=1)
- ;
- mov eax, cr0 ; Read CR0.
- or eax, 1h ; Set PE=1
- mov cr0, eax ; Write CR0.
- db 066h
- db 0eah ; jmp far 16:32
-OffsetIn32BitProtectedMode:
- dd 00000000h ; offset $+8 (In32BitProtectedMode)
- dw 10h ; selector (flat CS)
-In32BitProtectedMode:
-
-;
-; Entering Long Mode
-;
- db 66h
- mov ax, 8
- mov ds, ax
- mov es, ax
- mov ss, ax
-
- ;
- ; Enable the 64-bit page-translation-table entries by
- ; setting CR4.PAE=1 (this is _required_ before activating
- ; long mode). Paging is not enabled until after long mode
- ; is enabled.
- ;
- db 0fh
- db 20h
- db 0e0h
-; mov eax, cr4
- bts eax, 5
- db 0fh
- db 22h
- db 0e0h
-; mov cr4, eax
-
- ;
- ; This is the Trapolean Page Tables that are guarenteed
- ; under 4GB.
- ;
- ; Address Map:
- ; 10000 ~ 12000 - efildr (loaded)
- ; 20000 ~ 21000 - start64.com
- ; 21000 ~ 22000 - efi64.com
- ; 22000 ~ 90000 - efildr
- ; 90000 ~ 96000 - 4G pagetable (will be reload later)
- ;
- db 0b8h
- dd 90000h
-; mov eax, 90000h
- mov cr3, eax
-
- ;
- ; Enable long mode (set EFER.LME=1).
- ;
- db 0b9h
- dd 0c0000080h
-; mov ecx, 0c0000080h ; EFER MSR number.
- db 0fh
- db 32h
-; rdmsr ; Read EFER.
- db 0fh
- db 0bah
- db 0e8h
- db 08h
-; bts eax, 8 ; Set LME=1.
- db 0fh
- db 30h
-; wrmsr ; Write EFER.
-
- ;
- ; Enable paging to activate long mode (set CR0.PG=1)
- ;
- mov eax, cr0 ; Read CR0.
- db 0fh
- db 0bah
- db 0e8h
- db 01fh
-; bts eax, 31 ; Set PG=1.
- mov cr0, eax ; Write CR0.
- jmp GoToLongMode
-GoToLongMode:
-
- db 067h
- db 0eah ; Far Jump $+9:Selector to reload CS
-OffsetInLongMode:
- dd 00000000 ; $+9 Offset is ensuing instruction boundary
- dw 038h ; Selector is our code selector, 38h
-
-InLongMode:
- db 66h
- mov ax, 30h
- mov ds, ax
-
- db 66h
- mov ax, 18h
- mov es, ax
- mov ss, ax
- mov ds, ax
-
- db 0bdh
- dd 400000h
-; mov ebp,000400000h ; Destination of EFILDR32
- db 0bbh
- dd 70000h
-; mov ebx,000070000h ; Length of copy
-
- ;
- ; load idt later
- ;
- db 48h
- db 33h
- db 0c0h
-; xor rax, rax
- db 66h
- mov ax, offset idtr
- db 48h
- db 05h
- dd 20000h
-; add rax, 20000h
-
- db 0fh
- db 01h
- db 18h
-; lidt fword ptr [rax]
-
- db 48h
- db 0c7h
- db 0c0h
- dd 21000h
-; mov rax, 21000h
- db 50h
-; push rax
-
-; ret
- db 0c3h
-
-Empty8042InputBuffer:
- mov cx,0
-Empty8042Loop:
- out DELAY_PORT,ax ; Delay 1us
- in al,KBD_STATUS_PORT ; Read the 8042 Status Port
- and al,02h ; Check the Input Buffer Full Flag
- loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
- ret
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; data
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
- dd 0 ; (GDT base gets set above)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; global descriptor table (GDT)
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- align 02h
-
-public GDT_BASE
-GDT_BASE:
-; null descriptor
-NULL_SEL equ $-GDT_BASE ; Selector [0x0]
- dw 0 ; limit 15:0
- dw 0 ; base 15:0
- db 0 ; base 23:16
- db 0 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
-
-; linear data segment descriptor
-LINEAR_SEL equ $-GDT_BASE ; Selector [0x8]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; linear code segment descriptor
-LINEAR_CODE_SEL equ $-GDT_BASE ; Selector [0x10]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system data segment descriptor
-SYS_DATA_SEL equ $-GDT_BASE ; Selector [0x18]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system code segment descriptor
-SYS_CODE_SEL equ $-GDT_BASE ; Selector [0x20]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; present, ring 0, data, expand-up, writable
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE3_SEL equ $-GDT_BASE ; Selector [0x28]
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-;
-; system data segment descriptor
-;
-SYS_DATA64_SEL equ $-GDT_BASE ; Selector [0x30]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 092h ; P | DPL [1..2] | 1 | 1 | C | R | A
- db 0CFh ; G | D | L | AVL | Segment [19..16]
- db 0
-
-;
-; system code segment descriptor
-;
-SYS_CODE64_SEL equ $-GDT_BASE ; Selector [0x38]
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Ah ; P | DPL [1..2] | 1 | 1 | C | R | A
- db 0AFh ; G | D | L | AVL | Segment [19..16]
- db 0
-
-; spare segment descriptor
-SPARE4_SEL equ $-GDT_BASE ; Selector [0x40]
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-GDT_END:
-
- align 02h
-
-
-
-idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
- dq 0 ; (IDT base gets set above)
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; interrupt descriptor table (IDT)
-;
-; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
-; mappings. This implementation only uses the system timer and all other
-; IRQs will remain masked. The descriptors for vectors 33+ are provided
-; for convenience.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;idt_tag db "IDT",0
- align 02h
-
-public IDT_BASE
-IDT_BASE:
-; divide by zero (INT 0)
-DIV_ZERO_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; debug exception (INT 1)
-DEBUG_EXCEPT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; NMI (INT 2)
-NMI_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; soft breakpoint (INT 3)
-BREAKPOINT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; overflow (INT 4)
-OVERFLOW_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; bounds check (INT 5)
-BOUNDS_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; invalid opcode (INT 6)
-INVALID_OPCODE_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; device not available (INT 7)
-DEV_NOT_AVAIL_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; double fault (INT 8)
-DOUBLE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Coprocessor segment overrun - reserved (INT 9)
-RSVD_INTR_SEL1 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; invalid TSS (INT 0ah)
-INVALID_TSS_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; segment not present (INT 0bh)
-SEG_NOT_PRESENT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; stack fault (INT 0ch)
-STACK_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; general protection (INT 0dh)
-GP_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; page fault (INT 0eh)
-PAGE_FAULT_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Intel reserved - do not use (INT 0fh)
-RSVD_INTR_SEL2 equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; floating point error (INT 10h)
-FLT_POINT_ERR_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; alignment check (INT 11h)
-ALIGNMENT_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; machine check (INT 12h)
-MACHINE_CHECK_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; SIMD floating-point exception (INT 13h)
-SIMD_EXCEPTION_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
- db (85 * 16) dup(0)
-
-; IRQ 0 (System timer) - (INT 68h)
-IRQ0_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 1 (8042 Keyboard controller) - (INT 69h)
-IRQ1_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
-IRQ2_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 3 (COM 2) - (INT 6bh)
-IRQ3_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 4 (COM 1) - (INT 6ch)
-IRQ4_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 5 (LPT 2) - (INT 6dh)
-IRQ5_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 6 (Floppy controller) - (INT 6eh)
-IRQ6_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 7 (LPT 1) - (INT 6fh)
-IRQ7_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 8 (RTC Alarm) - (INT 70h)
-IRQ8_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 9 - (INT 71h)
-IRQ9_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 10 - (INT 72h)
-IRQ10_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 11 - (INT 73h)
-IRQ11_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 12 (PS/2 mouse) - (INT 74h)
-IRQ12_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 13 (Floating point error) - (INT 75h)
-IRQ13_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 14 (Secondary IDE) - (INT 76h)
-IRQ14_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-; IRQ 15 (Primary IDE) - (INT 77h)
-IRQ15_SEL equ $-IDT_BASE
- dw 0 ; offset 15:0
- dw SYS_CODE64_SEL ; selector 15:0
- db 0 ; 0 for interrupt gate
- db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
- dw 0 ; offset 31:16
- dd 0 ; offset 63:32
- dd 0 ; 0 for reserved
-
-IDT_END:
-
- align 02h
-
-MemoryMapSize dd 0
-MemoryMap dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
- dd 0,0,0,0,0,0,0,0
-
- 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
- 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
-
- org 0fe0h
-MyStack:
- ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
- ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
- ; known low address (20f00) so it can be set up by PlMapIrqToVect in
- ; 8259.c
-
- int 8
- iret
-
- int 9
- iret
-
- int 10
- iret
-
- int 11
- iret
-
- int 12
- iret
-
- int 13
- iret
-
- int 14
- iret
-
- int 15
- iret
-
-
- org 0ffeh
-BlockSignature:
- dw 0aa55h
-
- end
|