kernel/games/doom/ file paths throughout: DOOM was later moved out of the kernel entirely. The port has since been completed and DOOM now runs on MayteraOS in a desktop window, launched from the Applications menu as a userland program at /GAMES/DOOM/DOOM.ELF (source: userland/apps/doom/); no DOOM source remains in the kernel tree.DOOM Port for MayteraOS - Debug Notes
The port is built from id Software's DOOM engine source, released under id's own DOOM Source Code License (a separate, more restrictive license than the GPL, carried in every source file's header). It requires a user-supplied DOOM.WAD on the boot disk; no WAD game data is included with or distributed by MayteraOS.
Status at the time: NOT WORKING
Issue: Z_Malloc fails with zone size=0
Problem Summary
DOOM's zone memory allocator (z_zone.c) is receiving 0 bytes from I_ZoneBase(), causing all Z_Malloc calls to fail.
Root Cause Analysis
The Bug
I_ZoneBase() in i_system.c returns mb_used * 1024 * 1024 bytes, but mb_used is 0 at call time.
Why mb_used is 0
mb_usedis defined ini_system.casint mb_used = 32;m_misc.chas config entry{"mb_used", &mb_used, 32}M_LoadDefaults()runs BEFOREZ_Init()and setsmb_used = defaults[i].defaultvalue- However, something is still setting it to 0
Suspected Issues
- The config default array in m_misc.c may not be applying correctly
- There may be another place resetting mb_used
- Compiler optimization might be causing issues with extern variable linkage
Files Modified
kernel/games/doom/i_system.c
int mb_used = 32; // Changed from 6
byte* I_ZoneBase (int* size) {
*size = mb_used*1024*1024;
byte *ptr = (byte *)malloc(*size);
kprintf("[DOOM] I_ZoneBase: requested %d bytes, got ptr=%p\n", *size, ptr);
return ptr;
}
kernel/games/doom/m_misc.c
{"mb_used", &mb_used, 32}, // Changed default from 2 to 32
kernel/games/doom/z_zone.c
Added debug output:
kprintf("[DOOM] Z_Malloc FAIL: requested %d bytes, zone size=%d\n", size, mainzone->size);
kernel/mm/heap.c
#define HEAP_INITIAL_SIZE (64 * MB) // Changed from 16MB
kernel/gui/desktop.c
Added serial command handler (not fully working):
static void process_serial_commands(void);
// Called from desktop_run() main loop
What Works
- WAD file loading (the user-supplied 11MB DOOM.WAD loads successfully)
- M_Init() starts
- R_Init() starts loading lumps
- Kernel heap allocation (64MB initial)
What Fails
- Z_Init() gets 0 bytes from I_ZoneBase()
- All subsequent Z_Malloc() calls fail
- DOOM enters error loop
Suggested Fix (Not Yet Tested)
Hardcode the zone size directly in I_ZoneBase to bypass mb_used:
byte* I_ZoneBase (int* size) {
*size = 32 * 1024 * 1024; // Hardcode 32MB
byte *ptr = (byte *)malloc(*size);
kprintf("[DOOM] I_ZoneBase: allocated %d bytes at %p\n", *size, ptr);
return ptr;
}
Serial Command Feature
Added but not fully working at the time. Issue: the QEMU serial socket did not receive input correctly.
Location: kernel/gui/desktop.c - process_serial_commands()
The intent at the time was a serial command to launch DOOM plus a command listing. That handler was never shipped in this form; today DOOM is launched from the desktop (Applications menu), not by a dedicated serial command.
Backups
Timestamped backups of the modified files (d_main.c, desktop.c, heap.c, i_system.c, z_zone.c) were taken before the change, per the project backup workflow.
Next Steps to Fix
- Hardcode zone size in I_ZoneBase (bypass mb_used)
- Or: Add kprintf in M_LoadDefaults to trace mb_used value
- Or: Initialize mb_used in Z_Init before calling I_ZoneBase
- Test with DOOM1.WAD (shareware, smaller) if the user's registered WAD still fails
Test Procedure
- Start the test VM
- Wait ~90 seconds for GUI to load
- Click DOOM icon in Applications menu
- Check the captured serial log for
[DOOM]lines