96 lines
2.9 KiB
Markdown
96 lines
2.9 KiB
Markdown
# BIOS Boot Process and Disk Layout
|
|
|
|
## Disk Layout
|
|
|
|
```
|
|
Sector 0 (MBR):
|
|
+-----------------------------------+ 0x000
|
|
| |
|
|
| Bootstrap Code |
|
|
| (Stage 1 Bootloader) |
|
|
| |
|
|
| |
|
|
+-----------------------------------+ 0x1BE (446)
|
|
| Partition Entry 1 (16 bytes) |
|
|
+-----------------------------------+ 0x1CE (462)
|
|
| Partition Entry 2 (16 bytes) |
|
|
+-----------------------------------+ 0x1DE (478)
|
|
| Partition Entry 3 (16 bytes) |
|
|
+-----------------------------------+ 0x1EE (494)
|
|
| Partition Entry 4 (16 bytes) |
|
|
+-----------------------------------+ 0x1FE (510)
|
|
| Boot Signature (0x55AA) |
|
|
+-----------------------------------+ 0x200 (512)
|
|
|
|
Sectors 1-2047:
|
|
+-----------------------------------+ 0x200
|
|
| |
|
|
| Stage 2 Bootloader |
|
|
| (Up to 1023.5 KB) |
|
|
| |
|
|
+-----------------------------------+ 0x100000 (Sector 2048)
|
|
|
|
Sector 2048 onwards:
|
|
+-----------------------------------+ 0x100000
|
|
| |
|
|
| FAT32 Partition |
|
|
| (Rest of disk) |
|
|
| |
|
|
+-----------------------------------+
|
|
```
|
|
|
|
## Partition Entry Format (16 bytes)
|
|
```
|
|
Offset Size Description
|
|
0x00 1 Boot flag (0x80 = bootable, 0x00 = non-bootable)
|
|
0x01 3 Starting CHS address
|
|
0x04 1 Partition type
|
|
0x05 3 Ending CHS address
|
|
0x08 4 Starting sector (LBA)
|
|
0x0C 4 Number of sectors
|
|
```
|
|
|
|
## Boot Process
|
|
|
|
1. **BIOS Power-On**
|
|
- BIOS performs POST (Power-On Self Test)
|
|
- Looks for bootable devices
|
|
|
|
2. **MBR Load**
|
|
- BIOS loads Sector 0 (MBR) into memory at 0x7C00
|
|
- Verifies 0x55AA signature
|
|
- Executes Stage 1 Bootloader
|
|
|
|
3. **Stage 1 Bootloader**
|
|
- Runs in 16-bit real mode
|
|
- Limited to 446 bytes
|
|
- Main task: Load Stage 2 Bootloader
|
|
- Typically contains minimal disk I/O code
|
|
|
|
4. **Stage 2 Bootloader**
|
|
- Located in sectors 1-2047
|
|
- Has more space for complex operations
|
|
- Tasks:
|
|
- Switch to 32-bit protected mode
|
|
- Set up basic memory management
|
|
- Parse FAT32 filesystem
|
|
- Switch to long mode
|
|
- Load and execute kernel
|
|
|
|
5. **Kernel Load**
|
|
- Stage 2 loads kernel from FAT32 partition
|
|
- Sets up necessary environment
|
|
- Transfers control to kernel
|
|
|
|
## Memory Layout During Boot
|
|
```
|
|
0x00000000 - 0x000003FF: Interrupt Vector Table
|
|
0x00000400 - 0x000004FF: BIOS Data Area
|
|
0x00000500 - 0x00007BFF: Free Memory
|
|
0x00007C00 - 0x00007DFF: Stage 1 Bootloader (MBR)
|
|
0x00007E00 - 0x0007FFFF: Free Memory (Stage 2 can be loaded here)
|
|
0x00080000 - 0x0009FFFF: Extended BIOS Data Area
|
|
0x000A0000 - 0x000FFFFF: BIOS ROM, Video Memory, etc.
|
|
0x00100000 onwards: Free Memory (Kernel typically loaded here)
|
|
```
|