PMM Rewrite:
- Replace ~8KB record array with compact bitmaps
(PhysPresent/PhysAlloc/PhysScanned, 128B each)
- Add PhysOwner[0..1023] for per-block ownership tracking
- new_block: O(1) amortised via NextFreeHint + dword-level BSF scan,
returns 0 as OOM sentinel
- free_block: O(1) direct bit clear with double-free detection
- alloc_block: validates PhysPresent and PhysAlloc bits before allocation
- Add pmm_free_blocks/pmm_total_blocks stats functions
VMM Correctness Fixes:
- Fix free_page block extraction (Address SHR 10, was using
raw Address field)
- Fix invlpg operand (use virtual address, was passing PDE index)
- Clear PDE entry on free_page before returning block to PMM
- Remove map_page double-write (delegate to map_page_ex only)
- Add OOM propagation (new_page returns false if PMM returns 0)
- Fix missing pop_trace in new_page error path
LMM Rewrite:
- Replace per-entry record array with bitmap allocator
(93% vs 43% page efficiency)
- Layout: Header(24B) + Bitmap(64512B) + Padding + Data at 0x10000
- SIZE_PREFIX=16 for 16-byte aligned returns (SSE MOVAPS requirement)
- Next-fit bitmap scan with roving hint (NextFree) and dword-level
fast skip
- Large alloc sentinel (LARGE_ALLOC_MAGIC=$FFFFFFFE) so kfree detects
klalloc'd memory
- Implement klfree (was previously a no-op - pages could never
be returned)
- Implement try_release_page (return fully-free heap pages to VMM/PMM)
- Fix interrupt safety: stack-balanced pushfd/cli/pop +
restore_if (sti only)
Fixes Bad TSS caused by popfd restoring dangerous EFLAGS bits (NT, IOPL)
- Zero memory via rep stosd instead of byte-by-byte loop
Hardening:
- kalloc OOM now triggers BSOD instead of returning nil
(90% of callers don't check)
- Double-free detection in kfree (verify bitmap bits set before clearing)
- Guard bytes ({$IFDEF DEBUG_LMM}): $DEADBEEF sentinel for buffer overrun detection
- kpalloc: bounds check (block >= 1024 -> GPF) + syslog MMIO mapping audit log
Observability:
- Add MEMINFO command as src/prog/meminfo.pas (moved from inline kernel.pas)
- Displays multiboot memory, PMM block stats, LMM heap stats
- Register via progmanager.pas following standard prog pattern
Files changed:
- src/pmemorymanager.pas
- src/vmemorymanager.pas
- src/lmemorymanager.pas
- src/kernel.pas
- src/progmanager.pas
- src/prog/meminfo.pas
Asuro
We welcome everyone to give building/breaking/fixing/shooting Asuro a go, feel free to follow the steps below and mess with Asuro for fun or profit.
Setting up your build environment
Prerequisites
- WSL2 WSL2 is used in conjunction with Docker to predefine a build environment for Asuro.
- Docker for Windows Docker is used to ensure a predefined environment with the correct versions of; Freepascal, Binutils, NASM, Make, xorriso & grub-mk-rescue installed is used for compilation. An ISO will be generated at the end of the build process.
- Git (Obviously) I don't think this needs an explaination.
- VSCode (Optional, but highly recommended)
Visual Studio code is our IDE of choice, and we have a number of recommended plugins.
- PowerShell Plugin by Microsoft This plugin gives you the ability to use the 'PowerShell' task type, allowing the automatic launching of virtualbox with the resulting image generated during compilation of Asuro.
- VirtualBox Virtualbox is our Virtualisation environment of choice, don't ask why, it just is.
Installation (correct as of 2021/06/20)
-
Install WSL2 as described in the article linked above & ensure Virtualization is enabled in the BIOS.
-
Ensure WSL2 is used by default with the following command:
wsl --set-default-version 2 -
Install Docker for Windows.
-
Install Git for Windows.
-
Install VSCode & the listed plugins.
-
Install VirtualBox (v7+).
-
Clone this repository.
-
Run the following command in the root of the repo to build the docker image:
docker compose build builder -
Run the following command to compile Asuro:
docker compose run builder -
Create a new virtual machine in Virtualbox and mount the
Asuro.isogenerated in step 9 as a boot image. -
Add the virtualbox installation directory to your
%PATH%environment variable, usually:%PROGRAMFILES%\Oracle\VirtualBox -
Naviage to your virtualbox machines folder, this is usually the following
%userprofile%\VirtualBox VMs\<VM Name>Open the Virtual Machine Definition file (.vbox) in your text editor of choice and find the following line:
<Machine uuid="{7d395c96-891c-4139-b77d-9b6b144b0b93}" name="Asuro" OSType="Linux" snapshotFolder="Snapshots" lastStateChange="2021-06-20T20:33:07Z">Copy the uuid, in our case
7d395c96-891c-4139-b77d-9b6b144b0b93& create alocalenv.jsonfile in the project root with the following content:{ "VirtualBox":{ "MachineName":"<YOUR_UUID_OR_MACHINE_NAME>" } }This will allow VSCode to automatically launch VirtualBox once Asuro has been compiled.
You can also enable the serial adapter "COM1" in mode "Raw File", give it a path, and provide this path in the
localenv.jsonas follows:{ "VirtualBox" : { "MachineName": "<YOUR_UUID_OR_MACHINE_NAME>", "LogLocation": "Fully\\Qualified\\Path\\To\\Your\\Log\\File" } }This will allow you to see the console output from Asuro in your host terminal.
-
Open your project folder in VSCode, use CTRL+SHIFT+B to build & F5 to build + run in VBox.
-
Congratulations! You can now play with Asuro!
Notes & Gotchas
- The above process has been updated to be compatible with VirtualBox 7+, in which VBoxSDL was removed and vboxmanage should be used in its place. A small wrapper powershell script is used to achieve this.
- It was noted that Windows builds above
20H2seem to have issues installing WSL2. We may have to wait for a patch from Microsoft to fix this. Our devs are currently using build20H2.