Boot.asm

This file contains the bootstrap (including Master Boot Record) for PwnOS.

Segments

  • MBR contains the space-optimized Master Boot Record code
  • BootData contains the global data for the 1st-level bootstrap code
  • Boot contains the 1st-level bootstrap code that loads the core

Includes

Boot.inc

See Also

Core.asm

Authors

  • Neil G.  Dickson
Summary
Boot.asmThis file contains the bootstrap (including Master Boot Record) for PwnOS.
MBRThis segment contains the master boot record of PwnOS
BootDataThis segment contains data for the 1st-level bootstrap code of PwnOS
Variables
GDTINITIAL GLOBAL DESCRIPTOR TABLE
IDTINTERRUPT DESCRIPTOR TABLE
BootThis segment contains the 1st-level bootstrap code of PwnOS
Functions
32-bit Entry PointThis code sets up some basic 32-bit Protected Mode stuff
ACPI BootSearches for Root System Description Pointer (RDSP)
Not Good EnoughThis is where the bootloader goes if the computer boot doesn’t go properly, like if the RSDP isn’t found, or if the ACPI info isn’t valid.
ACPI Boot ContinuedRSDP found, so scan RSDT for Multiple APIC Description Table (MADT)
Check Processor Requirements
I/ O APIC Setup
Memory Type Range Registers (MTRRs) and Page Attriubute Table Register (PAT MSR)
Local APIC Setup & Multi-Processor Startup
IDE Bus Master Setup (NEED PCI SPECIFICATIONS FOR THIS)
Read MBRs to Find NTFS Partition
Initialize Data in & for Core
Task Functions
Functions
SetTSSDescriptorSets the TSS descriptor corresponding with the current processor to select the specified TSS.
Timing Functions
Functions
WaitNanoseconds
ATA/ ATAPI Functions
Functions
ATAIdentifyDeviceFills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_DEVICE.
ATAIdentifyPacketDeviceFills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_PACKET_DEVICE.
CompactATAIdentifyFills in the ATADEVICEINFO of the specified device with the information returned by ATAIdentifyDevice.
ATAIsValidDeviceChecks the ATADEVICEINFO of the specified device to see if it is a valid, supported device.

MBR

This segment contains the master boot record of PwnOS

BootData

This segment contains data for the 1st-level bootstrap code of PwnOS

IT MUST BE LESS THAN OR EQUAL TO 2KB LARGE

Summary
Variables
GDTINITIAL GLOBAL DESCRIPTOR TABLE
IDTINTERRUPT DESCRIPTOR TABLE

Variables

GDT

GDT dq 0 ;NULL descriptor

INITIAL GLOBAL DESCRIPTOR TABLE

IDT

IDT: INT_DESC offset IntDivError ;00 Divide Error

INTERRUPT DESCRIPTOR TABLE

Boot

This segment contains the 1st-level bootstrap code of PwnOS

Summary
Functions
32-bit Entry PointThis code sets up some basic 32-bit Protected Mode stuff
ACPI BootSearches for Root System Description Pointer (RDSP)
Not Good EnoughThis is where the bootloader goes if the computer boot doesn’t go properly, like if the RSDP isn’t found, or if the ACPI info isn’t valid.
ACPI Boot ContinuedRSDP found, so scan RSDT for Multiple APIC Description Table (MADT)
Check Processor Requirements
I/ O APIC Setup
Memory Type Range Registers (MTRRs) and Page Attriubute Table Register (PAT MSR)
Local APIC Setup & Multi-Processor Startup
IDE Bus Master Setup (NEED PCI SPECIFICATIONS FOR THIS)
Read MBRs to Find NTFS Partition
Initialize Data in & for Core

Functions

32-bit Entry Point

This code sets up some basic 32-bit Protected Mode stuff

ACPI Boot

Searches for Root System Description Pointer (RDSP)

Not Good Enough

This is where the bootloader goes if the computer boot doesn’t go properly, like if the RSDP isn’t found, or if the ACPI info isn’t valid.

ACPI Boot Continued

RSDP found, so scan RSDT for Multiple APIC Description Table (MADT)

Check Processor Requirements

I/ O APIC Setup

Memory Type Range Registers (MTRRs) and Page Attriubute Table Register (PAT MSR)

Local APIC Setup & Multi-Processor Startup

IDE Bus Master Setup (NEED PCI SPECIFICATIONS FOR THIS)

Read MBRs to Find NTFS Partition

Initialize Data in & for Core

Task Functions

Summary
Functions
SetTSSDescriptorSets the TSS descriptor corresponding with the current processor to select the specified TSS.

Functions

SetTSSDescriptor

Sets the TSS descriptor corresponding with the current processor to select the specified TSS.

Parameters

pTSSvirtual address of the TSS

Returns

  • selector of the descriptor modified

Timing Functions

Functions

WaitNanoseconds

Parameters

Nanoseconds# of nanoseconds to wait

ATA/ ATAPI Functions

Summary
Functions
ATAIdentifyDeviceFills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_DEVICE.
ATAIdentifyPacketDeviceFills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_PACKET_DEVICE.
CompactATAIdentifyFills in the ATADEVICEINFO of the specified device with the information returned by ATAIdentifyDevice.
ATAIsValidDeviceChecks the ATADEVICEINFO of the specified device to see if it is a valid, supported device.

Functions

ATAIdentifyDevice

Fills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_DEVICE.  If the device is a packet device, it calls ATAIdentifyPacketDevice.

Parameters

pDestpointer to 512-byte buffer
DriveNumone of: ATA_DEVICE_DEV0, ATA_DEVICE_DEV1, ATA_DEVICE_DEV0 or 1, ATA_DEVICE_DEV1 or 1

Returns

  • carry flag set iff error

ATAIdentifyPacketDevice

Fills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_PACKET_DEVICE.  Called by ATAIdentifyDevice

Parameters

pDestpointer to 512-byte buffer
DriveNumone of: ATA_DEVICE_DEV0, ATA_DEVICE_DEV1, ATA_DEVICE_DEV0 or 1, ATA_DEVICE_DEV1 or 1

Returns

  • carry flag set iff error

CompactATAIdentify

Fills in the ATADEVICEINFO of the specified device with the information returned by ATAIdentifyDevice.  If the device is invalid (e.g. no device at all), the nSectors field is set to -1.

Parameters

Drive0To3ATA device index, from 0 to 3
pSourcepointer to info block returned from ATAIdentifyDevice

ATAIsValidDevice

Checks the ATADEVICEINFO of the specified device to see if it is a valid, supported device.

Parameters

Drive0To3ATA device index, from 0 to 3

Returns

  • eax = 0 in if invalid
  • eax = Address of ATADEVICEINFO if valid
  • ecx = nSectorsLow if valid
  • edx = nSectorsHigh if valid
GDT dq 0 ;NULL descriptor
INITIAL GLOBAL DESCRIPTOR TABLE
IDT: INT_DESC offset IntDivError ;00 Divide Error
INTERRUPT DESCRIPTOR TABLE
This structure defines a hardware device connected through the ATA controller (mostly harddrives and CD/DVD drives).
Fills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_DEVICE.
This segment contains the master boot record of PwnOS
This segment contains data for the 1st-level bootstrap code of PwnOS
This segment contains the 1st-level bootstrap code of PwnOS
This file contains the constants, macros, and function prototypes for the bootstrap of PwnOS.
This file defines the entry point into the Core of PwnOS, and includes the rest of the Core.
Fills in the 512-byte buffer with the information returned by ATA_CC_IDENTIFY_PACKET_DEVICE.