# Memory Map / Cartographie Mémoire ## 🇬🇧 English ### Physical Memory Layout (Real Mode) The processor starts in Real Mode, addressing 1 MB of memory. | Physical Start | Physical End | Size | Description | Segment | Source/Definied | | :--- | :--- | :--- | :--- | :--- | :--- | | **`0x00000`** | **`0x003FF`** | 1 KB | **IVT** (Interrupt Vector Table) | `0x0000` | `memory.asm` | | **`0x00400`** | **`0x004FF`** | 256 B | **BDA** (BIOS Data Area) Standard | `0x0040` | `memory.asm` | | **`0x00500`** | **`0x006FF`** | ~512 B | **Custom BDA** (Driver Data) | `0x0050` | | | **`0x00700`** | **`0x00A6F`** | ~1792 B | **GUI RAM** (Widget Allocation) | **`0x0070`** | `gui/lib-api.asm` | | **`0x00A70`** | **`0x07FFF`** | ~ 29 KB | **Free** (Low Memory) | | | | **`0x08000`** | **`0x17FFF`** | 64 KB | **Stack** (Grows downwards) | `0x0800` | `boot.asm` | | **`0x18000`** | **`0x1FFFF`** | 32 KB | **Free** | | | | **`0x20000`** | **`0x2FFFF`** | 64 KB | **Heap** (Dynamic Allocation) | `0x2000` | `memory.asm` | | **`0x30000`** | **`0x9FFFF`** | 448 KB | **Free** (Conventional RAM) | | | | **`0xA0000`** | **`0xAFFFF`** | 64 KB | **VGA RAM** (Graphics Modes) | `0xA000` | `Hardware` | | **`0xB0000`** | **`0xB7FFF`** | 32 KB | **MDA RAM** (Monochrome Text) | `0xB000` | `Hardware` | | **`0xB8000`** | **`0xBFFFF`** | 32 KB | **VRAM** (CGA / MCGA) | `0xB800` | `generic.asm` | | **`0xC0000`** | **`0xDFFFF`** | 128 KB | **Option ROMs** (e.g., VGA BIOS) | `0xC000` | `generic.asm` | | **`0xE0000`** | **`0xEFFFF`** | 64 KB | **System Reserved** (BIOS Extension) | `0xE000` | `Hardware` | | **`0xF0000`** | **`0xFFFFF`** | 64 KB | **System BIOS ROM** (Code) | `0xF000` | `Hardware` | ### Detailed Zones #### Interrupt Vector Table (IVT) * **Location**: `0000:0000` * **Usage**: Interrupt pointer table (256 entries of 4 bytes). * **Initialization**: * `ivt_setup` fills the table with a default handler (`default_isr`). * `ivt_setvector` installs specific IRQs (e.g., Timer on `INT 08h`). #### BIOS Data Area (BDA) The project separates the standard IBM BDA from its own variables to avoid conflicts with the VGA BIOS loaded at `0xC000`. * **Standard BDA (`0040:0000`)**: Used mainly by the VGA BIOS (loaded via QEMU) to store video modes (`0x0049`) and column count (`0x004A`). * **Custom BDA (`0050:0000`)**: Defined by `BDA_CUSTOM_SEG`. Stores driver states: * **Mouse**: Input buffer, status, coordinates, background buffer (for cursor). * **Gfx**: Text cursor position, attributes. * **GUI RAM**: Segment `0x0063` (Physical `0x00630`). * **Layout**: Located in low memory to avoid any collision with the Stack (`0x0800`). #### Stack * **Stack**: Grows downwards from physical address `0xFFFE` (16-bit aligned) of the "Stack Segment" defined by `STACK_SEG`. #### Video RAM (CGA High-Res) * **Segment**: `0xB800` * **Mode**: 640x200 Monochrome (1 bit per pixel). * **Organization**: Interleaved. * **Even Lines (0, 2, 4...)**: Offset `0x0000` - `0x1F3F` (Bank 0). * **Odd Lines (1, 3, 5...)**: Offset `0x2000` - `0x3F3F` (Bank 1). #### VGA RAM & System Reserved * **VGA RAM (`0xA0000`)**: Standard 64 KB memory window for VGA graphics modes. Although this project primarily uses the CGA memory at `0xB8000`, this area is physically present when the VGA hardware is emulated. * **System Reserved (`0xE0000`)**: Reserved memory area, typically used for motherboard BIOS extensions or specific hardware mapping. #### ROM * **Option ROMs (`0xC0000`)**: Scanned by `setup_load_rom` to initialize the VGA BIOS. * **System ROM (`0xF0000`)**: Contains the compiled binary code. The Reset Vector is at `0xFFFF0`. --- ## 🇫🇷 Français ### Cartographie Mémoire Physique (Mode Réel) Le processeur démarre en mode réel, adressant 1 Mo de mémoire. | Physical Start | Physical End | Size | Description | Segment | Source/Definied | | :--- | :--- | :--- | :--- | :--- | :--- | | **`0x00000`** | **`0x003FF`** | 1 KB | **IVT** (Interrupt Vector Table) | `0x0000` | `memory.asm` | | **`0x00400`** | **`0x004FF`** | 256 B | **BDA** (BIOS Data Area) Standard | `0x0040` | `memory.asm` | | **`0x00500`** | **`0x006FF`** | ~512 B | **Custom BDA** (Driver Data) | `0x0050` | | | **`0x00700`** | **`0x00A6F`** | ~1792 B | **GUI RAM** (Widget Allocation) | **`0x0070`** | `gui/lib-api.asm` | | **`0x00A70`** | **`0x07FFF`** | ~ 29 KB | **Free** (Low Memory) | | | | **`0x08000`** | **`0x17FFF`** | 64 KB | **Stack** (Grows downwards) | `0x0800` | `boot.asm` | | **`0x18000`** | **`0x1FFFF`** | 32 KB | **Libre** | | | | **`0x20000`** | **`0x2FFFF`** | 64 KB | **Heap** (Allocation Dynamique) | `0x2000` | `memory.asm` | | **`0x30000`** | **`0x9FFFF`** | 448 KB | **Libre** (RAM Conventionnelle) | | | | **`0xA0000`** | **`0xAFFFF`** | 64 KB | **VGA RAM** (Graphics Modes) | `0xA000` | `Hardware` | | **`0xB0000`** | **`0xB7FFF`** | 32 KB | **MDA RAM** (Monochrome Text) | `0xB000` | `Hardware` | | **`0xB8000`** | **`0xBFFFF`** | 32 KB | **VRAM** (CGA / MCGA) | `0xB800` | `generic.asm` | | **`0xC0000`** | **`0xDFFFF`** | 128 KB | **Option ROMs** (e.g., VGA BIOS) | `0xC000` | `generic.asm` | | **`0xE0000`** | **`0xEFFFF`** | 64 KB | **System Reserved** (BIOS Extension) | `0xE000` | `Hardware` | | **`0xF0000`** | **`0xFFFFF`** | 64 KB | **System BIOS ROM** (Code) | `0xF000` | `Hardware` | ### Détails des Zones #### Interrupt Vector Table (IVT) * **Emplacement** : `0000:0000` * **Usage** : Table des pointeurs d'interruption (256 entrées de 4 octets). * **Initialisation** : * `ivt_setup` remplit la table avec un handler par défaut (`default_isr`). * `ivt_setvector` installe les IRQ spécifiques (ex: Timer sur `INT 08h`). #### BIOS Data Area (BDA) Le projet sépare la BDA standard IBM de ses propres variables pour éviter les conflits avec le BIOS VGA chargé en `0xC000`. * **BDA Standard (`0040:0000`)** : Utilisée principalement par le BIOS VGA (chargé via QEMU) pour stocker les modes vidéo (`0x0049`) et le nombre de colonnes (`0x004A`). * **Custom BDA (`0050:0000`)** : Définie par `BDA_CUSTOM_SEG`. Stocke l'état des drivers : * **Souris** : Buffer d'entrée, état, coordonnées, buffer de sauvegarde du fond (pour le curseur). * **Gfx** : Position du curseur texte, attributs. * **GUI RAM** : Segment `0x0063` (Physique `0x00630`). * **Organisation** : Située en mémoire basse pour éviter toute collision avec la Pile (`0x0800`). #### Stack * **Stack** : Grandit vers le bas depuis l'adresse physique `0xFFFE` (Alignement sur 16 bits) du "stack Segment" défini par `STACK_SEG`. #### Video RAM (CGA High-Res) * **Segment** : `0xB800` * **Mode** : 640x200 Monochrome (1 bit par pixel). * **Organisation** : Entrelacée (Interleaved). * **Lignes Paires (0, 2, 4...)** : Offset `0x0000` à `0x1F3F` (Bank 0). * **Lignes Impaires (1, 3, 5...)** : Offset `0x2000` à `0x3F3F` (Bank 1). #### VGA RAM & Réservé Système * **VGA RAM (`0xA0000`)** : Fenêtre mémoire standard de 64 Ko pour les modes graphiques VGA. Bien que ce projet utilise principalement la mémoire CGA à `0xB8000`, cette zone est physiquement présente lorsque le matériel VGA est émulé. * **Réservé Système (`0xE0000`)** : Zone mémoire réservée, typiquement utilisée pour les extensions du BIOS de la carte mère ou le mappage de matériel spécifique. #### ROM * **Option ROMs (`0xC0000`)** : Espace scanné par `setup_load_rom` pour initialiser le BIOS VGA. * **System ROM (`0xF0000`)** : Contient le code binaire compilé. Le Vecteur de Reset est situé à `0xFFFF0`.