Compare commits
2 Commits
7cd6baa74d
...
721ff2e62d
| Author | SHA1 | Date | |
|---|---|---|---|
| 721ff2e62d | |||
| a50af35abd |
@@ -207,24 +207,45 @@ Each GDT entry is 8 bytes:
|
|||||||
|
|
||||||
## **5. Memory Layout Example**
|
## **5. Memory Layout Example**
|
||||||
|
|
||||||
### **Low Memory (First MiB)**
|
### **Low Memory/Upper Memory map (<= 1MiB)**
|
||||||
|
|
||||||
| Start | End | Size | Type | Description |
|
| Start | End | Size | Type | Description |
|
||||||
|-------------|-------------|-----------------|-----------------------|----------------------------------|
|
|-------------|-------------|-----------------|----------------------|--------------------------------|
|
||||||
| 0x00000000 | 0x000003FF | 1 KiB | RAM (partially unusable) | Real Mode IVT (Interrupt Vector Table) |
|
| 0x00000000 | 0x000003FF | 1 KiB | RAM reclaimable~1~ | Real Mode IVT |
|
||||||
| 0x00000400 | 0x000004FF | 256 bytes | RAM (partially unusable) | BDA (BIOS data area) |
|
| 0x00000400 | 0x000004FF | 256 bytes | RAM reclaimable~1~ | BDA |
|
||||||
| 0x00000500 | 0x00007BFF | almost 30 KiB | RAM - free for use | Conventional memory |
|
| 0x00000500 | 0x00007BFF | 29 KiB + 767b | RAM - free | Conventional memory |
|
||||||
| 0x00007C00 | 0x00007DFF | 512 bytes | RAM (partially unusable) | OS BootSector |
|
| 0x00007C00 | 0x00007DFF | 512 bytes | RAM reclaimable~2~ | OS BootSector |
|
||||||
| 0x00007E00 | 0x0007FFFF | 480.5 KiB | RAM - free for use | Conventional memory |
|
| 0x00007E00 | 0x0007FFFF | 480.5 KiB | RAM - free | Conventional memory |
|
||||||
| 0x00080000 | 0x0009FFFF | 128 KiB | RAM (partially unusable) | EBDA (Extended BIOS Data Area) |
|
| 0x00080000 | 0x0009FFFF | 128 KiB | RAM (unusable)~1~ | EBDA (Extended BIOS Data Area) |
|
||||||
| 0x000A0000 | 0x000FFFFF | 384 KiB | various (unusable) | Video memory, ROM Area |
|
| 0x000A0000 | 0x000FFFFF | 384 KiB | Upper RAM (unusable) | Video memory, ROM Area |
|
||||||
|
|
||||||
### **Extended Memory (Above 1 MiB)**
|
1. Reclaimable in the event that you *never* need the BIOS again & once the CPU is in protected mode.
|
||||||
|
2. Reclaimable after you are done with with the MBR/VBR stages.
|
||||||
|
|
||||||
| Start | End | Size | Description |
|
### **Extended Memory (> 1 MiB)**
|
||||||
|-------------|-------------|-----------------|------------------------|
|
|
||||||
| 0x00100000 | 0x00EFFFFF | 14 MiB | RAM - free for use |
|
This is only an example, you should always check the memory map.
|
||||||
|
|
||||||
|
| Start | End | Size | Description |
|
||||||
|
|-------------|-------------|-----------------|---------------------------------------|
|
||||||
|
| 0x00100000 | 0x00EFFFFF | 14 MiB | RAM(?) - free for use |
|
||||||
| 0x00F00000 | 0x00FFFFFF | 1 MiB | Possible memory-mapped hardware (ISA) |
|
| 0x00F00000 | 0x00FFFFFF | 1 MiB | Possible memory-mapped hardware (ISA) |
|
||||||
| 0x01000000 | ? | ? | More extended memory |
|
| 0x01000000 | ? | ? | More extended memory |
|
||||||
| 0xC0000000 | 0xFFFFFFFF | 1 GiB | Memory mapped PCI devices, BIOS, etc. |
|
| 0xC0000000 | 0xFFFFFFFF | 1 GiB | Memory mapped PCI devices, BIOS, etc. |
|
||||||
| 0x0000000100000000 | ? | ? | RAM - usable in PAE/64-bit mode |
|
| 0x0000000100000000 | ? | ? | RAM(?) - usable in PAE/64-bit mode |
|
||||||
|
|
||||||
|
|
||||||
|
## **6. Stage2 Memory Layout **
|
||||||
|
|
||||||
|
Overall, Tiny (64 KiB page) Code/Data, Flat 4GiB mapping in gs/fs after unreal switch
|
||||||
|
|
||||||
|
| Start | End | Size (Bytes) | Type | Description |
|
||||||
|
|-------------|-------------|--------------|--------------------|----------------------------|
|
||||||
|
| 0x00000000 | 0x000003FF | 0x400 | RAM - (BIOS) | Real Mode IVT |
|
||||||
|
| 0x00000400 | 0x000004FF | 0x100 | RAM - (BIOS) | BDA |
|
||||||
|
| 0x00000500 | 0x000042FF | 0x3E00 | RAM - .text/.data | Code and constants/strings |
|
||||||
|
| 0x00004300 | 0x000044FF | 0x100 | RAM - .sign | EOF marker/signature |
|
||||||
|
| 0x00004500 | 0x000074FF | 0x3000 | RAM - bss | Runtime data/stack |
|
||||||
|
| 0x00007500 | 0x00007FFF | 0xB00 | RAM - reserved | Reserved |
|
||||||
|
| 0x00008000 | 0x0000DFFF | 0x6000 | RAM - heap | Conventional memory |
|
||||||
|
| 0x0000F000 | 0x0000FFFF | 0x1000 | RAM - reserved | Reserved |
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
%ifndef __INC_STEVIA_CONFIG
|
%ifndef __INC_STEVIA_CONFIG
|
||||||
|
|
||||||
%define SECTOR_SIZE 512
|
%define SECTOR_SIZE 0x200
|
||||||
%define STAGE2_SECTOR_COUNT 0x20
|
%define STAGE2_SECTOR_COUNT 0x20
|
||||||
; 16 KiB
|
; 16 KiB
|
||||||
%define MAX_STAGE2_BYTES (SECTOR_SIZE * STAGE2_SECTOR_COUNT)
|
%define MAX_STAGE2_BYTES (SECTOR_SIZE * STAGE2_SECTOR_COUNT)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
section .text
|
section .text
|
||||||
begin_text:
|
begin_text:
|
||||||
; dl = byte boot_drive
|
; dl = byte boot_drive
|
||||||
ALIGN 4, db 0x90
|
ALIGN 16, db 0x90
|
||||||
init:
|
init:
|
||||||
cli ; We do not want to be interrupted
|
cli ; We do not want to be interrupted
|
||||||
mov [boot_drive], dl ; copy boot_drive to globals
|
mov [boot_drive], dl ; copy boot_drive to globals
|
||||||
@@ -375,7 +375,8 @@ EnterUnrealMode:
|
|||||||
end_text:
|
end_text:
|
||||||
|
|
||||||
section .data follows=.text
|
section .data follows=.text
|
||||||
align 512
|
align 16, db 0
|
||||||
|
|
||||||
begin_data:
|
begin_data:
|
||||||
; #############
|
; #############
|
||||||
;
|
;
|
||||||
@@ -410,19 +411,15 @@ define_info MaybeFound_Boot, "Maybe found a file...checking..."
|
|||||||
|
|
||||||
define_cstr BootTarget, "BOOT BIN"
|
define_cstr BootTarget, "BOOT BIN"
|
||||||
|
|
||||||
align 16, db 0
|
|
||||||
BootTarget:
|
|
||||||
db 'BOOT BIN'
|
|
||||||
|
|
||||||
;
|
|
||||||
; pre-bss init globals
|
|
||||||
;
|
|
||||||
|
|
||||||
; set to boot_drive passed from BIOS almost first thing in init
|
; set to boot_drive passed from BIOS almost first thing in init
|
||||||
align 4, db 0
|
align 4, db 0
|
||||||
boot_drive:
|
boot_drive:
|
||||||
db 0x00
|
db 0x00
|
||||||
|
|
||||||
|
align 16, db 0
|
||||||
|
BootTarget:
|
||||||
|
db 'BOOT BIN'
|
||||||
|
|
||||||
align 16, db 0
|
align 16, db 0
|
||||||
IntToHex_table:
|
IntToHex_table:
|
||||||
db '0123456789ABCDEF'
|
db '0123456789ABCDEF'
|
||||||
@@ -504,15 +501,20 @@ BUILD_GIT_HASH:
|
|||||||
db __GIT_HASH__, 00h
|
db __GIT_HASH__, 00h
|
||||||
end_data:
|
end_data:
|
||||||
|
|
||||||
%assign bytes_remaining ((MAX_STAGE2_BYTES - 512) - (($ - $$) + (end_text - begin_text)))
|
%define SIG_BYTES 0x4
|
||||||
%warning STAGE2 has bytes_remaining bytes remaining for code/data (MAX: MAX_STAGE2_BYTES)
|
|
||||||
|
; Optional: fail fast if we overflowed
|
||||||
|
%if ((MAX_STAGE2_BYTES - 512) - (($ - $$) + (end_text - begin_text))) < 0
|
||||||
|
%error "Stage2 overflow: code+data exceed MAX_STAGE2_BYTES - SIG_BYTES"
|
||||||
|
%endif
|
||||||
|
|
||||||
; section start location needs to be a 'critical expression'
|
; section start location needs to be a 'critical expression'
|
||||||
; i.e resolvable at build time, we are setting 0x0500 as the offset since
|
; i.e resolvable at build time, we are setting 0x0500 as the offset since
|
||||||
section .sign start=((MAX_STAGE2_BYTES - 512) + 0x0500)
|
section .sign start=((MAX_STAGE2_BYTES - 512) + 0x0500)
|
||||||
times ((512 - 4) - ($ -$$) ) db 0x90 ; nop
|
times ((512 - 4) - ($ -$$) ) db 0x90 ; nop
|
||||||
STAGE2_SIG: dd 0xDEADBEEF ; Signature to mark the end of the stage2
|
STAGE2_SIG: dd 0xDEADBEEF ; Signature to mark the end of the stage2
|
||||||
|
; !!! END Stage2 .text/.data !!!
|
||||||
|
align 16, resb 1
|
||||||
section .bss follows=.sign
|
section .bss follows=.sign
|
||||||
begin_bss:
|
begin_bss:
|
||||||
|
|
||||||
@@ -596,3 +598,11 @@ stack_bottom:
|
|||||||
resb 1024
|
resb 1024
|
||||||
stack_top:
|
stack_top:
|
||||||
end_bss:
|
end_bss:
|
||||||
|
|
||||||
|
; Pad to the cap (emits nothing in the file; only increases .bss virtual size).
|
||||||
|
; If BSS_SIZE > BSS_MAX_BYTES, this becomes negative and NASM errors out.
|
||||||
|
%define BSS_MAX_BYTES 0x3000
|
||||||
|
resb (BSS_MAX_BYTES - (end_bss - begin_bss))
|
||||||
|
|
||||||
|
; Optional: keep a label for later math:
|
||||||
|
bss_cap_end:
|
||||||
Reference in New Issue
Block a user