Python Support Implementation Progress
Current status (verified 2026-08-06)
MayteraOS ships CPython 3.11.9, cross-compiled freestanding, as
/APPS/PYTHON.ELF. It is what the Start menu's Python entry, the Files
app's "Open With", and the IDE app's integrated run/debug all launch
(userland/apps/compositor/startmenu.c, userland/apps/files/main.c,
userland/apps/ide/main.c). The MayteraOS-authored side of the port -
the launcher, the libc shims CPython needed, and the kernel syscall-header
diffs it was built against - lives in userland/apps/python/port/ and is
committed to the source-of-truth repository; upstream CPython itself (467 MB)
is not vendored and is fetched at build time.
Two honest gaps, stated so this page cannot be read as claiming more than it should:
- The shipping
PYTHON.ELFis not currently rebuilt by the standard golden build. When the CPython port source is present the build relinks it fresh as a position-independent binary; when it is not, the golden falls back to carrying forward the existing asset-base binary, which isET_EXEC(no PIE, no ASLR) and built without a stack canary. This is a tracked, allowlisted gap, not a silent one. - A separate, much smaller hand-written Python-subset interpreter
(
userland/apps/python/main.c, binary namepython, notPYTHON.ELF) also exists in the tree and predates the CPython port. It implements a limited subset (variables, expressions,print(), basic control flow, no classes or real standard library) and is not wired into the Start menu, Files, or the IDE; it is not what a user reaches by opening "Python" in the desktop.
See the Python Support plan page for how the original MicroPython recommendation related to this, and Licenses for CPython's license.
Historical: Phase 1 prerequisite work (January 2026)
Date: January 27, 2026 Status: Phase 1 Prerequisites Complete
Completed Work
P1 Priority Functions (Essential for MicroPython)
1. setjmp/longjmp Implementation
Files:
userland/libc/setjmp.h- Header with jmp_buf structureuserland/libc/setjmp.asm- x86_64 assembly implementation
Features:
- Saves/restores callee-saved registers (RBX, RBP, R12-R15)
- Saves stack pointer and return address
- Returns 0 on first call, specified value on longjmp
- Correctly handles x86_64 calling convention
2. snprintf/vsnprintf Implementation
Files:
userland/libc/stdio.c- Updated with new functionsuserland/libc/stdio.h- Updated declarations
Features:
- Buffer size limiting with null termination
- Support for %d, %i, %u, %x, %X, %p, %c, %s, %%
- Width and zero-padding support
- Left/right justification with '-' flag
- Length modifiers: l, ll, z
3. strtol/strtoul Functions
Files:
userland/libc/stdlib.c- Implementationuserland/libc/stdlib.h- Declarations
Functions implemented:
strtol()- Convert string to longstrtoul()- Convert string to unsigned longstrtoll()- Convert string to long longstrtoull()- Convert string to unsigned long long
Features:
- Automatic base detection (0x for hex, 0b for binary, 0 for octal)
- Support for bases 2-36
- Whitespace skipping
- Sign handling
- End pointer support
Build System
- Updated
userland/libc/Makefileto include setjmp.asm - Updated
userland/libc/maytera.hto include setjmp.h - All files compile successfully
Next Steps for MicroPython Port
Phase 1 Remaining Work
- Download MicroPython Source
git clone https://github.com/micropython/micropython.git
cd micropython
git checkout v1.22.0 # or latest stable
- Create Directory Structure
kernel/python/
├── mpconfigport.h # MayteraOS configuration
├── mphalport.h # HAL function declarations
├── mphalport.c # HAL function implementations
├── qstrdefsport.h # QSTR definitions
└── Makefile # Build integration
- Implement HAL Functions
mp_hal_stdin_rx_chr()- Read character from keyboardmp_hal_stdout_tx_strn()- Write string to console/serialmp_hal_ticks_ms()- Get milliseconds since bootmp_hal_delay_ms()- Delay function
- Configure Memory
- Allocate GC heap (256KB-1MB)
- Implement memory wrappers if needed
- Test Basic REPL
- Verify VM initialization
- Test basic Python operations
Files Modified This Session
| File | Changes |
|---|---|
userland/libc/setjmp.h | Created - jmp_buf structure |
userland/libc/setjmp.asm | Created - x86_64 setjmp/longjmp |
userland/libc/stdio.c | Added snprintf, vsnprintf, sprintf |
userland/libc/stdio.h | Added function declarations |
userland/libc/stdlib.c | Added strtol, strtoul, strtoll, strtoull |
userland/libc/stdlib.h | Added function declarations |
userland/libc/maytera.h | Added setjmp.h include |
userland/libc/Makefile | Added setjmp.asm to build |
Test Verification
The libc builds successfully:
$ cd userland/libc && make
gcc ... -c string.c -o string.o
gcc ... -c stdio.c -o stdio.o
gcc ... -c stdlib.c -o stdlib.o
nasm -f elf64 -g syscall.asm -o syscall.o
nasm -f elf64 -g setjmp.asm -o setjmp.o
ar rcs libc.a string.o stdio.o stdlib.o syscall.o setjmp.o
Built libc.a
References
- Original plan:
docs/python-support-plan.md - MicroPython porting guide: https://docs.micropython.org/en/latest/develop/porting.html
- MicroPython minimal port example:
micropython/ports/minimal/