From 9802de81e428970ccbdfe0c496f8bcff6d907b3d Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:06:29 -0400 Subject: [PATCH 01/21] Fix period --- notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes.md b/notes.md index a34a331..7b0be5a 100644 --- a/notes.md +++ b/notes.md @@ -59,7 +59,7 @@ section once they are finished. # Active -## 1, Task Scheduler +## 1. Task Scheduler Create a task scheduler and add a yield to most / all system calls. This scheduler should also handle the idle state when all processes are waiting. The From c6e8ab04927ffdbbcb93ad0291e89ddcfa175ed9 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:06:45 -0400 Subject: [PATCH 02/21] Add link and move quote title --- design/memory.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/design/memory.md b/design/memory.md index 24432f9..63c4ef9 100644 --- a/design/memory.md +++ b/design/memory.md @@ -2,7 +2,8 @@ ## Real Mode -See https://wiki.osdev.org/Memory_Map_(x86) for reserved BIOS memory. +See [https://wiki.osdev.org/Memory_Map_(x86)](https://wiki.osdev.org/Memory_Map_(x86)) +for reserved BIOS memory. | start | end | size | description | | ------ | ------- | --------- | --------------------------- | @@ -13,7 +14,8 @@ See https://wiki.osdev.org/Memory_Map_(x86) for reserved BIOS memory. | 0x7c00 | 0x07dff | 512 bytes | Boot Sector | | 0x7e00 | 0x9fbff | 607.5 KiB | Kernel (second stage) | -> [!IMPORTANT] Kernel Size in Protected Mode +> [!IMPORTANT] +> Kernel Size in Protected Mode > Reserved memory in protected mode starts at 0x9fc00 while real mode starts at > 0xa0000 From 116b50e9d2807b16fe42201425632166b7bd77ec Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:13:34 -0400 Subject: [PATCH 03/21] Try space and footnote --- design/memory.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/design/memory.md b/design/memory.md index 63c4ef9..006affe 100644 --- a/design/memory.md +++ b/design/memory.md @@ -16,13 +16,14 @@ for reserved BIOS memory. > [!IMPORTANT] > Kernel Size in Protected Mode +> > Reserved memory in protected mode starts at 0x9fc00 while real mode starts at > 0xa0000 ### Boot Parameters Boot parameters are set by the bootloader and passed to the second stage kernel -at address 0x500. +at address 0x500[^1]. | start | size | description | | ----- | ---- | ------------------ | @@ -236,3 +237,5 @@ the present flag set will be treated as the end of all entries. should be stored. All other tables are reachable via the linked list. TODO - everything else here + +[^1]: My footnote From 0bbc3ea896edc30d50e450f9fdfb895440707b9e Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:22:44 -0400 Subject: [PATCH 04/21] More upudates to render in GitHub --- design/memory.md | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/design/memory.md b/design/memory.md index 006affe..a12b250 100644 --- a/design/memory.md +++ b/design/memory.md @@ -15,15 +15,13 @@ for reserved BIOS memory. | 0x7e00 | 0x9fbff | 607.5 KiB | Kernel (second stage) | > [!IMPORTANT] -> Kernel Size in Protected Mode -> -> Reserved memory in protected mode starts at 0x9fc00 while real mode starts at -> 0xa0000 +> Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in +> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 ### Boot Parameters Boot parameters are set by the bootloader and passed to the second stage kernel -at address 0x500[^1]. +at address 0x500. | start | size | description | | ----- | ---- | ------------------ | @@ -36,8 +34,7 @@ x is the value of Memory Entry Count * 24 #### Memory Entry There is a single memory entry for each region of memory. It is possible to have -out of order and overlapping regions. See [BIOS Function: INT 0x15, EAX = -0xE820](https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820) +out of order and overlapping regions. See [BIOS Function: INT 0x15, EAX = 0xE820](https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820) | start | size | description | | ----- | ---- | ------------ | @@ -79,14 +76,14 @@ ACPI 3.0 Extended Attributes | ... | ... | ... | ... | | 0xb8000 | 0xb8fff | 0x01000 | VGA Memory | -> [!IMPORTANT] Kernel Size in Protected Mode -> Reserved memory in protected mode starts at 0x9fc00 while real mode starts at -> 0xa0000 +> [!IMPORTANT] +> Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in +> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 ### Virtual Address Space (stage 2) -See https://wiki.osdev.org/Paging for information about page tables and -directory. +See [https://wiki.osdev.org/Paging](https://wiki.osdev.org/Paging) for +information about page tables and directory. - The first page (0) is always null, accessing any address here will result in a (page fault?) @@ -151,11 +148,12 @@ pages in the region. | 4 | 2 | page count | | 8 | 2 | free count | ->[!IMPORTANT] Remember to mask the address -> The low 12 bits of each address are flags because the address is always page -> aligned. Remember to mask these bits when using the address. +> [!IMPORTANT] +> Remember to mask the address. The low 12 bits of each address are flags +> because the address is always page aligned. Remember to mask these bits when +> using the address. -> [!NOTE] Region size +> [!NOTE] > Each region can be up to 128 MiB (32768 pages) >- Page size = 4096 (0x1000) >- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000) @@ -176,8 +174,8 @@ bitmask for the region showing which pages are free. Any bits outside of the region should be set to 0 (ie. if the region is smaller than 128 MiB, bits for any pages after the region end should be 0). -> [!IMPORTANT] Bitmask bit 1 -> The first bit of the bitmask will always be 0 for the bitmask page itself. +> [!IMPORTANT] +> The first bit (bit 1) of the bitmask will always be 0 for the bitmask page itself. ## Paging Allocator (`memory.h`) @@ -211,11 +209,11 @@ for getting the page number or memory address. | 12 | 20 | page no (address if flags masked away) | | 32 | 32 | size in bytes (page aligned) | -> [!IMPORTANT] Size is page aligned +> [!IMPORTANT] > The size is page aligned such that a page no / address + size points to the > next valid, page aligned, address. -> [!NOTE] Size has unused bits +> [!NOTE] > Because the size is page aligned, the first 12 bits should always be 0 #### Flags @@ -237,5 +235,3 @@ the present flag set will be treated as the end of all entries. should be stored. All other tables are reachable via the linked list. TODO - everything else here - -[^1]: My footnote From fd4b371ac9a4febd7d4073c381bec99e3605d49c Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:25:21 -0400 Subject: [PATCH 05/21] Try inline --- design/memory.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/design/memory.md b/design/memory.md index a12b250..be7915a 100644 --- a/design/memory.md +++ b/design/memory.md @@ -5,29 +5,29 @@ See [https://wiki.osdev.org/Memory_Map_(x86)](https://wiki.osdev.org/Memory_Map_(x86)) for reserved BIOS memory. -| start | end | size | description | -| ------ | ------- | --------- | --------------------------- | -| 0x0000 | 0x4ff | 1.25 KiB | Unusable | -| 0x0500 | 0x00fff | 1.25 KiB | Boot Parameters | -| 0x1000 | 0x06fff | 24 KiB | Stack (real mode), top down | -| 0x7000 | 0x07bff | 3 KiB | Unused | -| 0x7c00 | 0x07dff | 512 bytes | Boot Sector | -| 0x7e00 | 0x9fbff | 607.5 KiB | Kernel (second stage) | +| start | end | size | description | +| -------- | --------- | --------- | --------------------------- | +| `0x0000` | `0x4ff` | 1.25 KiB | Unusable | +| `0x0500` | `0x00fff` | 1.25 KiB | Boot Parameters | +| `0x1000` | `0x06fff` | 24 KiB | Stack (real mode), top down | +| `0x7000` | `0x07bff` | 3 KiB | Unused | +| `0x7c00` | `0x07dff` | 512 bytes | Boot Sector | +| `0x7e00` | `0x9fbff` | 607.5 KiB | Kernel (second stage) | > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 +> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` ### Boot Parameters Boot parameters are set by the bootloader and passed to the second stage kernel -at address 0x500. +at address `0x500`. | start | size | description | | ----- | ---- | ------------------ | -| 0 | 2 | Low Memory Size | -| 2 | 2 | Memory Entry Count | -| 4 | x | Memory Map Entries | +| `0` | 2 | Low Memory Size | +| `2` | 2 | Memory Entry Count | +| `4` | x | Memory Map Entries | x is the value of Memory Entry Count * 24 From 23e02186c3e38f66d4222cc64d312e1694bdbd52 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:26:35 -0400 Subject: [PATCH 06/21] more --- design/memory.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/design/memory.md b/design/memory.md index be7915a..9f978d0 100644 --- a/design/memory.md +++ b/design/memory.md @@ -25,9 +25,9 @@ at address `0x500`. | start | size | description | | ----- | ---- | ------------------ | -| `0` | 2 | Low Memory Size | -| `2` | 2 | Memory Entry Count | -| `4` | x | Memory Map Entries | +| 0 | 2 | Low Memory Size | +| 2 | 2 | Memory Entry Count | +| 4 | x | Memory Map Entries | x is the value of Memory Entry Count * 24 @@ -65,10 +65,10 @@ ACPI 3.0 Extended Attributes | start | end | size | description | | ------- | ------- | --------- | --------------------- | -| 0x00000 | 0x004ff | 1.25 KiB | Unused | -| 0x00500 | 0x00fff | 2.75 KiB | Boot Parameters | -| 0x01000 | 0x01fff | 4 KiB | Page Directory | -| 0x02000 | 0x02fff | 4 KiB | ram region table | +| `0x00000` | 0x004ff | 1.25 KiB | Unused | +| `0x00500` | 0x00fff | 2.75 KiB | Boot Parameters | +| `0x01000` | 0x01fff | 4 KiB | Page Directory | +| `0x02000` | 0x02fff | 4 KiB | ram region table | | 0x03000 | 0x06fff | 16 KiB | Stack | | 0x07000 | 0x07bff | 3 KiB | Unused | | 0x07c00 | 0x07dff | 512 bytes | GDT | From f4c5c3cb7824fb0aba63c63a3cac16d5d3706812 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:30:30 -0400 Subject: [PATCH 07/21] All inline --- design/memory.md | 80 ++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/design/memory.md b/design/memory.md index 9f978d0..926a45e 100644 --- a/design/memory.md +++ b/design/memory.md @@ -34,7 +34,7 @@ x is the value of Memory Entry Count * 24 #### Memory Entry There is a single memory entry for each region of memory. It is possible to have -out of order and overlapping regions. See [BIOS Function: INT 0x15, EAX = 0xE820](https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820) +out of order and overlapping regions. See [BIOS Function: INT `0x15`, EAX = `0xE820`](https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_`0x15`.2C_EAX_.3D_`0xE820`) | start | size | description | | ----- | ---- | ------------ | @@ -63,22 +63,22 @@ ACPI 3.0 Extended Attributes ## Protected Mode -| start | end | size | description | -| ------- | ------- | --------- | --------------------- | -| `0x00000` | 0x004ff | 1.25 KiB | Unused | -| `0x00500` | 0x00fff | 2.75 KiB | Boot Parameters | -| `0x01000` | 0x01fff | 4 KiB | Page Directory | -| `0x02000` | 0x02fff | 4 KiB | ram region table | -| 0x03000 | 0x06fff | 16 KiB | Stack | -| 0x07000 | 0x07bff | 3 KiB | Unused | -| 0x07c00 | 0x07dff | 512 bytes | GDT | -| 0x07e00 | 0x9fbff | 607.5 KiB | Kernel (second stage) | -| ... | ... | ... | ... | -| 0xb8000 | 0xb8fff | 0x01000 | VGA Memory | +| start | end | size | description | +| --------- | --------- | --------- | --------------------- | +| `0x00000` | `0x004ff` | 1.25 KiB | Unused | +| `0x00500` | `0x00fff` | 2.75 KiB | Boot Parameters | +| `0x01000` | `0x01fff` | 4 KiB | Page Directory | +| `0x02000` | `0x02fff` | 4 KiB | ram region table | +| `0x03000` | `0x06fff` | 16 KiB | Stack | +| `0x07000` | `0x07bff` | 3 KiB | Unused | +| `0x07c00` | `0x07dff` | 512 bytes | GDT | +| `0x07e00` | `0x9fbff` | 607.5 KiB | Kernel (second stage) | +| ... | ... | ... | ... | +| `0xb8000` | `0xb8fff` | `0x01000` | VGA Memory | > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 +> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` ### Virtual Address Space (stage 2) @@ -88,34 +88,34 @@ information about page tables and directory. - The first page (0) is always null, accessing any address here will result in a (page fault?) - Each page directory and table contain 1024 entries -- 0x1000 will always point to the active page directory -- 0x2000 will always point to the ram region table -- 0xb9000 will always point to the first ram region bitmasks - - There are 512 sequential pages of ram bitmasks ending at 0x2b9fff -- _0x400000 is the first virtual address of the second page table_ +- `0x1000` will always point to the active page directory +- `0x2000` will always point to the ram region table +- `0xb9000` will always point to the first ram region bitmasks + - There are 512 sequential pages of ram bitmasks ending at `0x2b9fff` +- _`0x400000` is the first virtual address of the second page table_ - It is suggested to keep kernel level memory bellow this address to allow user space application switching out the second+ page table - This can be used as the entry point address for all user space applications - This region is ~3.99 GB -- 0xffc00000 will always point to the first page table (kernel table) - - This goes up to 0xffffffff as the last address in all of virtual space +- `0xffc00000` will always point to the first page table (kernel table) + - This goes up to `0xffffffff` as the last address in all of virtual space - Each of the 1024 tables from the page directory are stored here sequentially - The first table includes the null page and kernel memory mapping (see bellow) | start | end | pages | physical addr | description | | ---------- | ---------- | ---------- | ------------- | --------------------------------------------------------- | -| 0x00000000 | 0x00000fff | 0x00001 | 0x00000000 | null page (not present) | -| 0x00001000 | 0x00001fff | 0x00001 | 0x00001000 | Page Directory | -| 0x00002000 | 0x00002fff | 0x00001 | 0x00002000 | ram region table | -| 0x00003000 | 0x00006fff | 0x00004 | 0x00003000 | Stack | -| 0x00007000 | 0x0009efff | 0x00098 | 0x00007000 | Kernel (from 0x7e00 to 0x9efff) | -| 0x0009f000 | 0x000b7fff | 0x00019 | | _temp pages for mapping_ | -| 0x000b8000 | 0x000b8fff | 0x00001 | 0x000b8000 | VGA Memory | -| 0x000b9000 | 0x000b9fff | 0x00001 | | First page table (kernel's page) of any page directory | -| 0x000ba000 | x - 1 | <= 0x00200 | | ram region bitmasks | +| `0x00000000` | `0x00000fff` | `0x00001` | `0x00000000` | null page (not present) | +| `0x00001000` | `0x00001fff` | `0x00001` | `0x00001000` | Page Directory | +| `0x00002000` | `0x00002fff` | `0x00001` | `0x00002000` | ram region table | +| `0x00003000` | `0x00006fff` | `0x00004` | `0x00003000` | Stack | +| `0x00007000` | `0x0009efff` | `0x00098` | `0x00007000` | Kernel (from `0x7e00` to `0x9efff`) | +| `0x0009f000` | `0x000b7fff` | `0x00019` | | _temp pages for mapping_ | +| `0x000b8000` | `0x000b8fff` | `0x00001` | `0x000b8000` | VGA Memory | +| `0x000b9000` | `0x000b9fff` | `0x00001` | | First page table (kernel's page) of any page directory | +| `0x000ba000` | x - 1 | <= `0x00200` | | ram region bitmasks | | x | y - 1 | | | _free memory for kmalloc (remainder of first page table)_ | -| y | 0x003fffff | | | _kernel stack (grows down)_ | -| 0x00400000 | 0xffffffff | 0xffb00 | | _free memory for user (second+ page tables)_ | +| y | `0x003fffff` | | | _kernel stack (grows down)_ | +| `0x00400000` | `0xffffffff` | `0xffb00` | | _free memory for user (second+ page tables)_ | _Pages with a blank physical address are allocated form free physical memory._ @@ -155,17 +155,17 @@ pages in the region. > [!NOTE] > Each region can be up to 128 MiB (32768 pages) ->- Page size = 4096 (0x1000) ->- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000) ->- Max pages per region = Bits per page = 32768 (0x8000) (includes bitmask page) +>- Page size = 4096 (`0x1000`) +>- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) +>- Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) >- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 -> (0x8000000) = 128 MiB +> (`0x8000000`) = 128 MiB #### Flags | flag | description | | ---- | ---------------------------------------------------------- | -| 0x1 | Present - this region table entry points to a valid region | +| `0x1` | Present - this region table entry points to a valid region | ### Region Bitmask @@ -200,7 +200,7 @@ There are a total of 511 entries per table. The first 12 bits of a table entry are flags. The page number can be converted to a memory address by shifting it left by 12 bits, or by using the max -(0xfffff000). Because the size is page aligned, the same strategy can be used +(`0xfffff000`). Because the size is page aligned, the same strategy can be used for getting the page number or memory address. | start | size | description | @@ -223,8 +223,8 @@ the present flag set will be treated as the end of all entries. | flag | description | | ---- | --------------------------------------- | -| 0x1 | Present - this is a valid entry | -| 0x2 | Free (1 if memory is free, 0 if in use) | +| `0x1` | Present - this is a valid entry | +| `0x2` | Free (1 if memory is free, 0 if in use) | ### Algorithm From e1e50c464f66870da2c5a9c6f59921a45402d6fd Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:32:03 -0400 Subject: [PATCH 08/21] I like this better --- design/memory.md | 100 +++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/design/memory.md b/design/memory.md index 926a45e..a12b250 100644 --- a/design/memory.md +++ b/design/memory.md @@ -5,23 +5,23 @@ See [https://wiki.osdev.org/Memory_Map_(x86)](https://wiki.osdev.org/Memory_Map_(x86)) for reserved BIOS memory. -| start | end | size | description | -| -------- | --------- | --------- | --------------------------- | -| `0x0000` | `0x4ff` | 1.25 KiB | Unusable | -| `0x0500` | `0x00fff` | 1.25 KiB | Boot Parameters | -| `0x1000` | `0x06fff` | 24 KiB | Stack (real mode), top down | -| `0x7000` | `0x07bff` | 3 KiB | Unused | -| `0x7c00` | `0x07dff` | 512 bytes | Boot Sector | -| `0x7e00` | `0x9fbff` | 607.5 KiB | Kernel (second stage) | +| start | end | size | description | +| ------ | ------- | --------- | --------------------------- | +| 0x0000 | 0x4ff | 1.25 KiB | Unusable | +| 0x0500 | 0x00fff | 1.25 KiB | Boot Parameters | +| 0x1000 | 0x06fff | 24 KiB | Stack (real mode), top down | +| 0x7000 | 0x07bff | 3 KiB | Unused | +| 0x7c00 | 0x07dff | 512 bytes | Boot Sector | +| 0x7e00 | 0x9fbff | 607.5 KiB | Kernel (second stage) | > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` +> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 ### Boot Parameters Boot parameters are set by the bootloader and passed to the second stage kernel -at address `0x500`. +at address 0x500. | start | size | description | | ----- | ---- | ------------------ | @@ -34,7 +34,7 @@ x is the value of Memory Entry Count * 24 #### Memory Entry There is a single memory entry for each region of memory. It is possible to have -out of order and overlapping regions. See [BIOS Function: INT `0x15`, EAX = `0xE820`](https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_`0x15`.2C_EAX_.3D_`0xE820`) +out of order and overlapping regions. See [BIOS Function: INT 0x15, EAX = 0xE820](https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820) | start | size | description | | ----- | ---- | ------------ | @@ -63,22 +63,22 @@ ACPI 3.0 Extended Attributes ## Protected Mode -| start | end | size | description | -| --------- | --------- | --------- | --------------------- | -| `0x00000` | `0x004ff` | 1.25 KiB | Unused | -| `0x00500` | `0x00fff` | 2.75 KiB | Boot Parameters | -| `0x01000` | `0x01fff` | 4 KiB | Page Directory | -| `0x02000` | `0x02fff` | 4 KiB | ram region table | -| `0x03000` | `0x06fff` | 16 KiB | Stack | -| `0x07000` | `0x07bff` | 3 KiB | Unused | -| `0x07c00` | `0x07dff` | 512 bytes | GDT | -| `0x07e00` | `0x9fbff` | 607.5 KiB | Kernel (second stage) | -| ... | ... | ... | ... | -| `0xb8000` | `0xb8fff` | `0x01000` | VGA Memory | +| start | end | size | description | +| ------- | ------- | --------- | --------------------- | +| 0x00000 | 0x004ff | 1.25 KiB | Unused | +| 0x00500 | 0x00fff | 2.75 KiB | Boot Parameters | +| 0x01000 | 0x01fff | 4 KiB | Page Directory | +| 0x02000 | 0x02fff | 4 KiB | ram region table | +| 0x03000 | 0x06fff | 16 KiB | Stack | +| 0x07000 | 0x07bff | 3 KiB | Unused | +| 0x07c00 | 0x07dff | 512 bytes | GDT | +| 0x07e00 | 0x9fbff | 607.5 KiB | Kernel (second stage) | +| ... | ... | ... | ... | +| 0xb8000 | 0xb8fff | 0x01000 | VGA Memory | > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` +> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 ### Virtual Address Space (stage 2) @@ -88,34 +88,34 @@ information about page tables and directory. - The first page (0) is always null, accessing any address here will result in a (page fault?) - Each page directory and table contain 1024 entries -- `0x1000` will always point to the active page directory -- `0x2000` will always point to the ram region table -- `0xb9000` will always point to the first ram region bitmasks - - There are 512 sequential pages of ram bitmasks ending at `0x2b9fff` -- _`0x400000` is the first virtual address of the second page table_ +- 0x1000 will always point to the active page directory +- 0x2000 will always point to the ram region table +- 0xb9000 will always point to the first ram region bitmasks + - There are 512 sequential pages of ram bitmasks ending at 0x2b9fff +- _0x400000 is the first virtual address of the second page table_ - It is suggested to keep kernel level memory bellow this address to allow user space application switching out the second+ page table - This can be used as the entry point address for all user space applications - This region is ~3.99 GB -- `0xffc00000` will always point to the first page table (kernel table) - - This goes up to `0xffffffff` as the last address in all of virtual space +- 0xffc00000 will always point to the first page table (kernel table) + - This goes up to 0xffffffff as the last address in all of virtual space - Each of the 1024 tables from the page directory are stored here sequentially - The first table includes the null page and kernel memory mapping (see bellow) | start | end | pages | physical addr | description | | ---------- | ---------- | ---------- | ------------- | --------------------------------------------------------- | -| `0x00000000` | `0x00000fff` | `0x00001` | `0x00000000` | null page (not present) | -| `0x00001000` | `0x00001fff` | `0x00001` | `0x00001000` | Page Directory | -| `0x00002000` | `0x00002fff` | `0x00001` | `0x00002000` | ram region table | -| `0x00003000` | `0x00006fff` | `0x00004` | `0x00003000` | Stack | -| `0x00007000` | `0x0009efff` | `0x00098` | `0x00007000` | Kernel (from `0x7e00` to `0x9efff`) | -| `0x0009f000` | `0x000b7fff` | `0x00019` | | _temp pages for mapping_ | -| `0x000b8000` | `0x000b8fff` | `0x00001` | `0x000b8000` | VGA Memory | -| `0x000b9000` | `0x000b9fff` | `0x00001` | | First page table (kernel's page) of any page directory | -| `0x000ba000` | x - 1 | <= `0x00200` | | ram region bitmasks | +| 0x00000000 | 0x00000fff | 0x00001 | 0x00000000 | null page (not present) | +| 0x00001000 | 0x00001fff | 0x00001 | 0x00001000 | Page Directory | +| 0x00002000 | 0x00002fff | 0x00001 | 0x00002000 | ram region table | +| 0x00003000 | 0x00006fff | 0x00004 | 0x00003000 | Stack | +| 0x00007000 | 0x0009efff | 0x00098 | 0x00007000 | Kernel (from 0x7e00 to 0x9efff) | +| 0x0009f000 | 0x000b7fff | 0x00019 | | _temp pages for mapping_ | +| 0x000b8000 | 0x000b8fff | 0x00001 | 0x000b8000 | VGA Memory | +| 0x000b9000 | 0x000b9fff | 0x00001 | | First page table (kernel's page) of any page directory | +| 0x000ba000 | x - 1 | <= 0x00200 | | ram region bitmasks | | x | y - 1 | | | _free memory for kmalloc (remainder of first page table)_ | -| y | `0x003fffff` | | | _kernel stack (grows down)_ | -| `0x00400000` | `0xffffffff` | `0xffb00` | | _free memory for user (second+ page tables)_ | +| y | 0x003fffff | | | _kernel stack (grows down)_ | +| 0x00400000 | 0xffffffff | 0xffb00 | | _free memory for user (second+ page tables)_ | _Pages with a blank physical address are allocated form free physical memory._ @@ -155,17 +155,17 @@ pages in the region. > [!NOTE] > Each region can be up to 128 MiB (32768 pages) ->- Page size = 4096 (`0x1000`) ->- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) ->- Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) +>- Page size = 4096 (0x1000) +>- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000) +>- Max pages per region = Bits per page = 32768 (0x8000) (includes bitmask page) >- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 -> (`0x8000000`) = 128 MiB +> (0x8000000) = 128 MiB #### Flags | flag | description | | ---- | ---------------------------------------------------------- | -| `0x1` | Present - this region table entry points to a valid region | +| 0x1 | Present - this region table entry points to a valid region | ### Region Bitmask @@ -200,7 +200,7 @@ There are a total of 511 entries per table. The first 12 bits of a table entry are flags. The page number can be converted to a memory address by shifting it left by 12 bits, or by using the max -(`0xfffff000`). Because the size is page aligned, the same strategy can be used +(0xfffff000). Because the size is page aligned, the same strategy can be used for getting the page number or memory address. | start | size | description | @@ -223,8 +223,8 @@ the present flag set will be treated as the end of all entries. | flag | description | | ---- | --------------------------------------- | -| `0x1` | Present - this is a valid entry | -| `0x2` | Free (1 if memory is free, 0 if in use) | +| 0x1 | Present - this is a valid entry | +| 0x2 | Free (1 if memory is free, 0 if in use) | ### Algorithm From f40366133a610ffcbe769b627ef803c4035fc853 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:33:17 -0400 Subject: [PATCH 09/21] Add comment --- design/memory.md | 1 + 1 file changed, 1 insertion(+) diff --git a/design/memory.md b/design/memory.md index a12b250..1e12606 100644 --- a/design/memory.md +++ b/design/memory.md @@ -5,6 +5,7 @@ See [https://wiki.osdev.org/Memory_Map_(x86)](https://wiki.osdev.org/Memory_Map_(x86)) for reserved BIOS memory. + | start | end | size | description | | ------ | ------- | --------- | --------------------------- | | 0x0000 | 0x4ff | 1.25 KiB | Unusable | From 076998a0958c79f96c7b9687700ffab79622d4ad Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:36:28 -0400 Subject: [PATCH 10/21] Try toc --- design/memory.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/design/memory.md b/design/memory.md index 1e12606..567ceb9 100644 --- a/design/memory.md +++ b/design/memory.md @@ -1,5 +1,10 @@ # Memory Map +\[ [Real Mode](#real-mode) \] +\[ [Protected Mode](#protected-mode) \] +\[ [Physical Allocator](#physical-allocator-ramh) \] +\[ [Paging Allocator](#paging-allocator-memoryh) \] + ## Real Mode See [https://wiki.osdev.org/Memory_Map_(x86)](https://wiki.osdev.org/Memory_Map_(x86)) From 645454d7175b2921e3676e9e6b64f37ee8a46a91 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Fri, 26 Jun 2026 23:37:32 -0400 Subject: [PATCH 11/21] Add comment --- design/memory.md | 1 + 1 file changed, 1 insertion(+) diff --git a/design/memory.md b/design/memory.md index 567ceb9..86941e3 100644 --- a/design/memory.md +++ b/design/memory.md @@ -1,5 +1,6 @@ # Memory Map + \[ [Real Mode](#real-mode) \] \[ [Protected Mode](#protected-mode) \] \[ [Physical Allocator](#physical-allocator-ramh) \] From cbe563fbb16faa44333fe9c96a35274711266497 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 00:48:55 -0400 Subject: [PATCH 12/21] Add style guide --- design/STYLE.md | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 design/STYLE.md diff --git a/design/STYLE.md b/design/STYLE.md new file mode 100644 index 0000000..1f58124 --- /dev/null +++ b/design/STYLE.md @@ -0,0 +1,92 @@ +# Style Guide for Design + + + +\[ [Table of Contents](#table-of-contents) \] +\[ [Inline Code](#inline-code) \] + +## Table of Contents + +The auto-generated bullet point list has very limited control over content and +styling with editors like vscode where the list is automatically updated. A +cleaner solution is a single line linking to the primary sections of the +document, showing only a single level (eg. all level 2 headers). + +**Example** this is the ToC for this document. A comment is included to explain +what headers are included for future additions or changes. + +```markdown + +\[ [Table of Contents](#table-of-contents) \] +\[ [Inline Code](#inline-code) \] +``` + +One drawback is the need for manual updates, however these headers are not +frequently updated for well established documents. + +## Inline Code + + +Inline code can be used to display potentially ambiguous characters (eg. lower +and upper case L, letter O and number 0) and to distinguish text from it's +surroundings like hexadecimal numbers (eg. `0x123`). + + +Inline code, however, reduce the contrast between text and background +making long strings of repeated characters more difficult to read (eg. `0000` vs +0000) or close, similar patterns of characters (eg. `0x0000` near `0x0600` vs +0x0000 near 0x06000). In most case, **bold** can be used to distinguish text +from it's surroundings (eg. **0x00000** near **0x06000**). Avoid using inline +code for tables, near formulas, in headers and in links. Exceptions can be made +when deemed necessary. Put a comment `` near these exceptional use cases +to explain why they are appropriate. + + +**Good Usage** - Inline hexadecimal numbers with area between + +> Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in +> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` + +**Bad Usage** - Hexadecimal column values in a table, smaller font with lower contrast + +> | Start | End | size | description | +> | -------- | --------- | --------- | -------------------------------------- | +> | `0x0000` | `0x4ff` | 1.25 KiB | Bad, small font with low contrast | +> | `0x0500` | `0x00fff` | 1.25 KiB | Bad, small font with low contrast | + +Compared to + +> | Start | End | size | description | +> | -------- | --------- | --------- | -------------------------------------- | +> | 0x7000 | 0x07bff | 3 KiB | Good, larger font with higher contrast | +> | 0x7c00 | 0x07dff | 512 bytes | Good, larger font with higher contrast | + +**Bad Usage** - Mix of numbers with plain text numbers and inline code + +>- Page size = 4096 (`0x1000`) +>- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) +>- Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) +>- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 +> (`0x8000000`) = 128 MiB + +**Bad Usage** - Numbers in formula without the operators + +> Bits per page = Page Size * `8` = `4096` * `8` = `32768` (`0x8000`) + +If you're going to quote a formula, include all operators and numbers in a +single quote. Exceptions can be made where impractical. + +**Good Usage** - Formula including numbers and operators + +> Bits per page = `Page Size * 8` = `4096 * 8` = `32768 (0x8000)` + +**Bad Usage** - Quote entire line + +> `Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000)` + +If a quote spans the entire line, try to use a code block instead. Code blocks +use a larger font with higher contrast between letters and background. + +> ``` +> Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000) +> ``` From c22cb0dc813fb08a95502f306b6b1f3fd09e9f98 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 00:49:08 -0400 Subject: [PATCH 13/21] Add table of contents and try to follow my own guidance --- design/boot_stages.md | 10 ++++++++-- design/memory.md | 20 +++++++++++--------- design/process.md | 5 +++++ design/system_call.md | 4 ++++ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/design/boot_stages.md b/design/boot_stages.md index 25468ab..4a0dea0 100644 --- a/design/boot_stages.md +++ b/design/boot_stages.md @@ -1,5 +1,11 @@ # Boot Stages + +\[ [Stage 0 - BIOS](#stage-0---bios) \] +\[ [Stage 1 - Boot](#stage-1---boot) \] +\[ [Stage 2 - Loader](#stage-2---loader) \] +\[ [Stage 3 - OS](#stage-3---os) \] + This describes the planned stages and steps, it does not represent the current implementation or progress. @@ -9,8 +15,8 @@ The BIOS firmware does a lot more than this, only the steps to launch the kernel are included. 1. Power On Self Test (POST) -2. Load boot sector (512 Bytes) into memory at `0x7c00` -3. Jump to `0x7c00` +2. Load boot sector (512 Bytes) into memory at 0x7c00 +3. Jump to 0x7c00 ## Stage 1 - Boot diff --git a/design/memory.md b/design/memory.md index 86941e3..a2643c2 100644 --- a/design/memory.md +++ b/design/memory.md @@ -23,12 +23,12 @@ for reserved BIOS memory. > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 +> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` ### Boot Parameters Boot parameters are set by the bootloader and passed to the second stage kernel -at address 0x500. +at address `0x500`. | start | size | description | | ----- | ---- | ------------------ | @@ -85,7 +85,7 @@ ACPI 3.0 Extended Attributes > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 +> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` ### Virtual Address Space (stage 2) @@ -95,17 +95,17 @@ information about page tables and directory. - The first page (0) is always null, accessing any address here will result in a (page fault?) - Each page directory and table contain 1024 entries -- 0x1000 will always point to the active page directory -- 0x2000 will always point to the ram region table -- 0xb9000 will always point to the first ram region bitmasks - - There are 512 sequential pages of ram bitmasks ending at 0x2b9fff +- `0x1000` will always point to the active page directory +- `0x2000` will always point to the ram region table +- `0xb9000` will always point to the first ram region bitmasks + - There are 512 sequential pages of ram bitmasks ending at `0x2b9fff` - _0x400000 is the first virtual address of the second page table_ - It is suggested to keep kernel level memory bellow this address to allow user space application switching out the second+ page table - This can be used as the entry point address for all user space applications - This region is ~3.99 GB -- 0xffc00000 will always point to the first page table (kernel table) - - This goes up to 0xffffffff as the last address in all of virtual space +- `0xffc00000` will always point to the first page table (kernel table) + - This goes up to `0xffffffff` as the last address in all of virtual space - Each of the 1024 tables from the page directory are stored here sequentially - The first table includes the null page and kernel memory mapping (see bellow) @@ -186,6 +186,8 @@ any pages after the region end should be 0). ## Paging Allocator (`memory.h`) +Paging allocator (aka **pmalloc** and **pfree**) is responsible for connecting the + Paging allocator (aka `pmalloc` and `pfree`) is responsible for connecting the physical memory allocator (ram) and page tables (mmu). This allocator keeps a linked list of tables, 1022 entries each. diff --git a/design/process.md b/design/process.md index d96fa25..b6de9d3 100644 --- a/design/process.md +++ b/design/process.md @@ -1,5 +1,10 @@ # Process + +\[ [Creating a Process](#creating-a-process) \] +\[ [Switch Task](#switch-task) \] +\[ [Ring Scheduler](#ring-scheduler) \] + The process tracks and manages the following information. - Process Id diff --git a/design/system_call.md b/design/system_call.md index fafdd15..d7d8b2a 100644 --- a/design/system_call.md +++ b/design/system_call.md @@ -1,5 +1,9 @@ # System Calls + +\[ [Sending System Calls](#sending-system-calls) \] +\[ [Receiving System Calls](#receiving-system-calls) \] + System calls are the mechanism by which processes communicate with the kernel both for sending commands and retrieving data. Some examples include file io, memory management, process management, etc. System calls are initiated by the From be4cc254dc824f2471e6665ec0cc39a24cd2b54b Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 00:50:10 -0400 Subject: [PATCH 14/21] Add Files --- design/STYLE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/STYLE.md b/design/STYLE.md index 1f58124..14a4b4d 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -1,4 +1,4 @@ -# Style Guide for Design +# Style Guide for Design Files From dcc74cacab4679527aab249216414c53f4b519cd Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 00:51:08 -0400 Subject: [PATCH 15/21] Copy with no quote block --- design/STYLE.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/design/STYLE.md b/design/STYLE.md index 14a4b4d..59f4d74 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -69,10 +69,18 @@ Compared to >- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 > (`0x8000000`) = 128 MiB +- Page size = 4096 (`0x1000`) +- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) +- Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) +- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 + (`0x8000000`) = 128 MiB + **Bad Usage** - Numbers in formula without the operators > Bits per page = Page Size * `8` = `4096` * `8` = `32768` (`0x8000`) +Bits per page = Page Size * `8` = `4096` * `8` = `32768` (`0x8000`) + If you're going to quote a formula, include all operators and numbers in a single quote. Exceptions can be made where impractical. @@ -80,10 +88,14 @@ single quote. Exceptions can be made where impractical. > Bits per page = `Page Size * 8` = `4096 * 8` = `32768 (0x8000)` +Bits per page = `Page Size * 8` = `4096 * 8` = `32768 (0x8000)` + **Bad Usage** - Quote entire line > `Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000)` +`Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000)` + If a quote spans the entire line, try to use a code block instead. Code blocks use a larger font with higher contrast between letters and background. From 87d96a88aef71bd7104f79fdfbc9af280812dae1 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 00:52:16 -0400 Subject: [PATCH 16/21] Now without quotes --- design/STYLE.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/design/STYLE.md b/design/STYLE.md index 59f4d74..f9f9424 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -63,12 +63,6 @@ Compared to **Bad Usage** - Mix of numbers with plain text numbers and inline code ->- Page size = 4096 (`0x1000`) ->- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) ->- Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) ->- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 -> (`0x8000000`) = 128 MiB - - Page size = 4096 (`0x1000`) - Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) - Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) @@ -77,8 +71,6 @@ Compared to **Bad Usage** - Numbers in formula without the operators -> Bits per page = Page Size * `8` = `4096` * `8` = `32768` (`0x8000`) - Bits per page = Page Size * `8` = `4096` * `8` = `32768` (`0x8000`) If you're going to quote a formula, include all operators and numbers in a @@ -86,14 +78,10 @@ single quote. Exceptions can be made where impractical. **Good Usage** - Formula including numbers and operators -> Bits per page = `Page Size * 8` = `4096 * 8` = `32768 (0x8000)` - Bits per page = `Page Size * 8` = `4096 * 8` = `32768 (0x8000)` **Bad Usage** - Quote entire line -> `Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000)` - `Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000)` If a quote spans the entire line, try to use a code block instead. Code blocks From 19bb8b62611bfbc8d3166a0e0a92c850d5f84011 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 00:52:55 -0400 Subject: [PATCH 17/21] Back to quote blocks --- design/STYLE.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/design/STYLE.md b/design/STYLE.md index f9f9424..14a4b4d 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -63,26 +63,26 @@ Compared to **Bad Usage** - Mix of numbers with plain text numbers and inline code -- Page size = 4096 (`0x1000`) -- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) -- Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) -- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 - (`0x8000000`) = 128 MiB +>- Page size = 4096 (`0x1000`) +>- Bits per page = Page Size * 8 = 4096 * 8 = 32768 (`0x8000`) +>- Max pages per region = Bits per page = 32768 (`0x8000`) (includes bitmask page) +>- Max region size = Max pages per region * Page size = 32768 * 4096 = 134217728 +> (`0x8000000`) = 128 MiB **Bad Usage** - Numbers in formula without the operators -Bits per page = Page Size * `8` = `4096` * `8` = `32768` (`0x8000`) +> Bits per page = Page Size * `8` = `4096` * `8` = `32768` (`0x8000`) If you're going to quote a formula, include all operators and numbers in a single quote. Exceptions can be made where impractical. **Good Usage** - Formula including numbers and operators -Bits per page = `Page Size * 8` = `4096 * 8` = `32768 (0x8000)` +> Bits per page = `Page Size * 8` = `4096 * 8` = `32768 (0x8000)` **Bad Usage** - Quote entire line -`Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000)` +> `Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000)` If a quote spans the entire line, try to use a code block instead. Code blocks use a larger font with higher contrast between letters and background. From 8014758e2aa7242dcc6c8d1f9c72e61268d938d8 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 01:02:53 -0400 Subject: [PATCH 18/21] Try with c --- design/STYLE.md | 3 ++- design/boot_stages.md | 14 +++++++------- design/filesystem.md | 2 +- design/memory.md | 36 +++++++++++++++++------------------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/design/STYLE.md b/design/STYLE.md index 14a4b4d..6cbc950 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -29,7 +29,8 @@ frequently updated for well established documents. Inline code can be used to display potentially ambiguous characters (eg. lower and upper case L, letter O and number 0) and to distinguish text from it's -surroundings like hexadecimal numbers (eg. `0x123`). +surroundings like hexadecimal numbers (eg. `0x123`). It's use is not mandatory +and typically used as needed rather than by default. Inline code, however, reduce the contrast between text and background diff --git a/design/boot_stages.md b/design/boot_stages.md index 4a0dea0..cb06a0a 100644 --- a/design/boot_stages.md +++ b/design/boot_stages.md @@ -23,14 +23,14 @@ are included. Execution of the first 512 bytes "boot sector". 1. Store boot drive id from `dl` register -2. Set stack `sp` and base `bp` pointers to `0x6fff` -3. Read memory map to `0x500` +2. Set stack `sp` and base `bp` pointers to 0x6fff +3. Read memory map to 0x500 1. Detect and store lower memory size using `int 0x12` - 2. Detect upper memory regions using `int 0x15` with `aex = 0xe820` -4. Read stage 2 from boot drive to `0x7e00` + 2. Detect upper memory regions using `int 0x15` with aex = 0xe820 +4. Read stage 2 from boot drive to 0x7e00 5. Setup GDT (kernel) 6. Switch to protected mode -7. Jump to loader at `0x7e00` +7. Jump to loader at 0x7e00 ## Stage 2 - Loader @@ -48,11 +48,11 @@ initialize the kernel then load and launch init program. 5. Initialize GDT 6. Initialize TSS 7. Enable paging -8. Initialize kernel (`kernel_init`) +8. Initialize kernel (**kernel_init**) 1. Clear kernel struct 2. Install ISR and IDT 3. Setup System Calls - 4. Initialize `kmalloc` + 4. Initialize **kmalloc** 5. (TMP) Setup Event Bus 6. Create Process Manager 7. Initialize Scheduler diff --git a/design/filesystem.md b/design/filesystem.md index 048a1ab..f25b82e 100644 --- a/design/filesystem.md +++ b/design/filesystem.md @@ -26,7 +26,7 @@ The type show what the block type is. Example to get decode an address -```text +```c block = loc & 0xff group = (loc >> 8) & 0x3fff type = loc >> 30 diff --git a/design/memory.md b/design/memory.md index a2643c2..7e4f6c2 100644 --- a/design/memory.md +++ b/design/memory.md @@ -23,12 +23,12 @@ for reserved BIOS memory. > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` +> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 ### Boot Parameters Boot parameters are set by the bootloader and passed to the second stage kernel -at address `0x500`. +at address 0x500. | start | size | description | | ----- | ---- | ------------------ | @@ -85,7 +85,7 @@ ACPI 3.0 Extended Attributes > [!IMPORTANT] > Kernel Size in Protected Mode is smaller than in real mode. Reserved memory in -> protected mode starts at `0x9fc00` while real mode starts at `0xa0000` +> protected mode starts at 0x9fc00 while real mode starts at 0xa0000 ### Virtual Address Space (stage 2) @@ -95,17 +95,17 @@ information about page tables and directory. - The first page (0) is always null, accessing any address here will result in a (page fault?) - Each page directory and table contain 1024 entries -- `0x1000` will always point to the active page directory -- `0x2000` will always point to the ram region table -- `0xb9000` will always point to the first ram region bitmasks - - There are 512 sequential pages of ram bitmasks ending at `0x2b9fff` -- _0x400000 is the first virtual address of the second page table_ +- **0x1000** will always point to the active page directory +- **0x2000** will always point to the ram region table +- **0xb9000** will always point to the first ram region bitmasks + - There are 512 sequential pages of ram bitmasks ending at 0x2b9fff +- _**0x400000** is the first virtual address of the second page table_ - It is suggested to keep kernel level memory bellow this address to allow user space application switching out the second+ page table - This can be used as the entry point address for all user space applications - This region is ~3.99 GB -- `0xffc00000` will always point to the first page table (kernel table) - - This goes up to `0xffffffff` as the last address in all of virtual space +- **0xffc00000** will always point to the first page table (kernel table) + - This goes up to 0xffffffff as the last address in all of virtual space - Each of the 1024 tables from the page directory are stored here sequentially - The first table includes the null page and kernel memory mapping (see bellow) @@ -186,11 +186,9 @@ any pages after the region end should be 0). ## Paging Allocator (`memory.h`) -Paging allocator (aka **pmalloc** and **pfree**) is responsible for connecting the - -Paging allocator (aka `pmalloc` and `pfree`) is responsible for connecting the -physical memory allocator (ram) and page tables (mmu). This allocator keeps a -linked list of tables, 1022 entries each. +Paging allocator (aka **pmalloc** and **pfree**) is responsible for connecting +the physical memory allocator (ram) and page tables (mmu). This allocator keeps +a linked list of tables, 1022 entries each. Each entry of the table describes a region of memory with address, flags and size in bytes (page aligned). @@ -208,9 +206,9 @@ There are a total of 511 entries per table. ### Memory Table Entries The first 12 bits of a table entry are flags. The page number can be converted -to a memory address by shifting it left by 12 bits, or by using the max -(0xfffff000). Because the size is page aligned, the same strategy can be used -for getting the page number or memory address. +to a memory address by shifting it left by 12 bits, or by using the max of +0xfffff000. Because the size is page aligned, the same strategy can be used for +getting the page number or memory address. | start | size | description | | ----- | ---- | -------------------------------------- | @@ -243,4 +241,4 @@ the present flag set will be treated as the end of all entries. - Memory tables can be moved and removed. Only a pointer to the first table should be stored. All other tables are reachable via the linked list. -TODO - everything else here +**TODO** - everything else here From 4a151eb72a29fad972b27f56f89655b869407177 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 01:28:13 -0400 Subject: [PATCH 19/21] More docs --- design/STYLE.md | 36 +++++++++++++++++++++++++++++++++++- design/boot_stages.md | 4 ++-- design/filesystem.md | 4 +++- design/process.md | 16 ++++++++-------- design/signals.md | 4 ++-- design/system_call.md | 13 ++++++------- design/time.md | 9 +++++---- 7 files changed, 61 insertions(+), 25 deletions(-) diff --git a/design/STYLE.md b/design/STYLE.md index 6cbc950..bca2e2f 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -10,7 +10,7 @@ The auto-generated bullet point list has very limited control over content and styling with editors like vscode where the list is automatically updated. A cleaner solution is a single line linking to the primary sections of the -document, showing only a single level (eg. all level 2 headers). +document, showing only a single level (eg. all level 2 headers). **Example** this is the ToC for this document. A comment is included to explain what headers are included for future additions or changes. @@ -91,3 +91,37 @@ use a larger font with higher contrast between letters and background. > ``` > Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000) > ``` + +## NOTE and TODO + +An alternative to alerts ia **Note** and **ToDo** (can also be upper case +**NOTE** and **TODO**). These are bold at the start of a paragraph followed by +non-bold text. **Note** is typically used to communicate details that may be +unintuitive or not obvious, but are not important enough to ues an alert. +**ToDo** is typically used as a note or reminder to the writer for future +content and communicates to the reader that a section may be incomplete or +inaccurate. + +## Alerts / Callouts / Admonitions + +Alerts can be useful to call attention to some information or visually break up +sections of text. To retain meaning and effectiveness at capturing the readers +attention, alerts should be uses sparingly and with short content. + +**Note** In vscode, alerts can have an altered title by following the type `[!...]` with +some text. This fails to render in GitHub so should be avoided. + +> [!NOTE] +> Note block + +> [!TIP] +> Tip block + +> [!IMPORTANT] +> Important block + +> [!WARNING] +> Warning block + +> [!CAUTION] +> Caution block diff --git a/design/boot_stages.md b/design/boot_stages.md index cb06a0a..43bf99e 100644 --- a/design/boot_stages.md +++ b/design/boot_stages.md @@ -25,8 +25,8 @@ Execution of the first 512 bytes "boot sector". 1. Store boot drive id from `dl` register 2. Set stack `sp` and base `bp` pointers to 0x6fff 3. Read memory map to 0x500 - 1. Detect and store lower memory size using `int 0x12` - 2. Detect upper memory regions using `int 0x15` with aex = 0xe820 + 1. Detect and store lower memory size using interrupt 18 (`int 0x12`) + 2. Detect upper memory regions using interrupt 18 (`int 0x15`) with aex = 0xe820 4. Read stage 2 from boot drive to 0x7e00 5. Setup GDT (kernel) 6. Switch to protected mode diff --git a/design/filesystem.md b/design/filesystem.md index f25b82e..775da59 100644 --- a/design/filesystem.md +++ b/design/filesystem.md @@ -26,7 +26,8 @@ The type show what the block type is. Example to get decode an address -```c + +```text block = loc & 0xff group = (loc >> 8) & 0x3fff type = loc >> 30 @@ -34,6 +35,7 @@ type = loc >> 30 Example to encode an address + ```text address = block address |= (group << 8) diff --git a/design/process.md b/design/process.md index b6de9d3..236e31d 100644 --- a/design/process.md +++ b/design/process.md @@ -16,7 +16,7 @@ The process tracks and manages the following information. - Registers - Signal callbacks - Link to next process -- *TBD Stats about process +- (TBD) Stats about process ## Creating a Process @@ -67,13 +67,13 @@ previous for list removal). When a task switch is performed, the next process in checked for fulfillment of the event filter. This is repeated until a ready to run task is found. -> [!WARNING] There must be at least one process ready to run -> -> There must always be a "next" task ready to run. In the case where the current -> process is yielding with an event filter, another process must be ready to -> launch. This will most likely be init, so there needs to be some documentation -> for init behavior written which includes that it must never yield with an -> event filter. +> [!WARNING] +> There must always be at least one process (a "next" task) ready to run. In the +> case where the current process is yielding with an event filter, another +> process must be ready to launch or resume. +> +> This will most likely be init, so documentation is needed for init behavior +> written which includes that it must never yield with an event filter. ### Process Manager diff --git a/design/signals.md b/design/signals.md index 1a2dc25..e20086f 100644 --- a/design/signals.md +++ b/design/signals.md @@ -11,7 +11,7 @@ TODO # Old -The `register_signals` call will hook a function in libc to receive all signals. -It will then store all registered callbacks of the process. +The **register_signals** call will hook a function in libc to receive all +signals. It will then store all registered callbacks of the process. TODO - keyboard event diff --git a/design/system_call.md b/design/system_call.md index d7d8b2a..143193d 100644 --- a/design/system_call.md +++ b/design/system_call.md @@ -54,9 +54,9 @@ void system_call_register(uint16_t family, sys_call_handler_t handler); ### Call Arguments -Arguments are accessible from `args_data` which is a pointer to the va_args in -the caller process stack. A struct can be used to decompose the argument values -from this pointer. +Arguments are accessible from **args_data** which is a pointer to the `va_args` +in the caller process stack. A struct can be used to decompose the argument +values from this pointer. ```c struct _args { @@ -67,10 +67,9 @@ struct _args { ``` > [!WARNING] -> -> Argument data is stored in the process stack. After changing the page directory -> the values in `arg_data` will be invalid. Copy values to the kernel stack or -> heap before switching to retrain access. +> Argument data is stored in the process stack. After changing the page +> directory the values in `arg_data` will be invalid. Copy values to the kernel +> stack or heap before switching to retrain access. ### Return Value diff --git a/design/time.md b/design/time.md index 8393f3f..99eeb39 100644 --- a/design/time.md +++ b/design/time.md @@ -17,9 +17,9 @@ Each channel counts down, starting at the reload value, and when they reach 0 the output is switched (low -> high or high -> low). In most cases the channel is then set to the reload value. -TODO in what cases is the reload value not used when a channel reaches 0? +**TODO** in what cases is the reload value not used when a channel reaches 0? -> [!NOTE] Reload Value +> [!NOTE] > The reload value of a channel is the value it will set it's count to after > reaching zero. Depending on the mode, that reset can be triggered by various > conditions. @@ -57,7 +57,7 @@ _only channel 0_ This mode will wait until a software trigger to begin the countdown. -TODO does the countdown happen with the clock or on each sw trigger? +**TODO** does the countdown happen with the clock or on each sw trigger? ### Mode 1 - Hardware Re-triggerable One-Shot @@ -120,6 +120,7 @@ selected in the command. | | 111 = Mode 3 (square wave generator, same as 011) | | 0 | BCD / Binary Mode (0 = 16-bit binary, 1 = four digit BCD) | -> [!TIP] Bits 0 - 5 are the same as the mode / command +> [!TIP] +> Bits 0 - 5 are the same as the mode / command # Real Time Clock (RTC) From 73ad923309dfd477ecf283e6db6d77e0002821e0 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 01:30:08 -0400 Subject: [PATCH 20/21] Update table of contents --- design/STYLE.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/design/STYLE.md b/design/STYLE.md index bca2e2f..315392b 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -4,6 +4,8 @@ \[ [Table of Contents](#table-of-contents) \] \[ [Inline Code](#inline-code) \] +\[ [Note and ToDO](#note-and-todo) \] +\[ [Alerts / Callouts / Admonitions](#alerts--callouts--admonitions) \] ## Table of Contents @@ -19,6 +21,8 @@ what headers are included for future additions or changes. \[ [Table of Contents](#table-of-contents) \] \[ [Inline Code](#inline-code) \] +\[ [Note and ToDO](#note-and-todo) \] +\[ [Alerts / Callouts / Admonitions](#alerts--callouts--admonitions) \] ``` One drawback is the need for manual updates, however these headers are not @@ -92,7 +96,7 @@ use a larger font with higher contrast between letters and background. > Bits per page = Page Size * 8 = 4096 * 8 = 32768 (0x8000) > ``` -## NOTE and TODO +## Note and ToDo An alternative to alerts ia **Note** and **ToDo** (can also be upper case **NOTE** and **TODO**). These are bold at the start of a paragraph followed by From 9d76aabfd09a495f11177519164683744e2fb71b Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Sat, 27 Jun 2026 01:35:28 -0400 Subject: [PATCH 21/21] More changes --- design/STYLE.md | 4 ++++ design/system_call.md | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/design/STYLE.md b/design/STYLE.md index 315392b..a239f5d 100644 --- a/design/STYLE.md +++ b/design/STYLE.md @@ -106,6 +106,10 @@ unintuitive or not obvious, but are not important enough to ues an alert. content and communicates to the reader that a section may be incomplete or inaccurate. +When used with all caps, **TODO** can also be highlighted by vscode using the +[TODO Highlights](https://marketplace.visualstudio.com/items?itemName=wayou.vscode-todo-highlight) +extension. + ## Alerts / Callouts / Admonitions Alerts can be useful to call attention to some information or visually break up diff --git a/design/system_call.md b/design/system_call.md index 143193d..d127f68 100644 --- a/design/system_call.md +++ b/design/system_call.md @@ -3,6 +3,7 @@ \[ [Sending System Calls](#sending-system-calls) \] \[ [Receiving System Calls](#receiving-system-calls) \] +\[ [Example Handler](#example-handler) \] System calls are the mechanism by which processes communicate with the kernel both for sending commands and retrieving data. Some examples include file io, @@ -77,7 +78,7 @@ Each call handler can optionally returns a single `int` value to the caller process by returning a value from the handler function. If no value is returned to the caller process, the call handler should return 0. -### Example Handler +## Example Handler A typical call handler uses a switch block to select the correct logic based on the `call_id`.