userland/) and has been corrected below.Python Support Implementation Progress
Current status, corrected
MayteraOS ships a MicroPython port as /APPS/PYTHON.ELF
(userland/python/micropython/, MIT-licensed port glue over
MicroPython's own MIT-licensed source), with MayteraOS-specific os,
socket and maytera modules for file, network and window
access from Python code. This is what the Start menu's Python entry and Files'
"Open With" launch.
A separate, much smaller hand-written Python-subset interpreter also exists
in the tree (userland/python/ examples plus an original minimal
interpreter, binary name python), predates the MicroPython work, and
implements a limited subset: variables, expressions, print(), basic
control flow, no classes or real standard library. It is original MayteraOS
code, not a third-party component, and is a separate binary from the
MicroPython-based PYTHON.ELF.
There is no CPython port in the current public repository or release. See the Python Support plan page for the original MicroPython recommendation this shipped from, and Licenses for the MicroPython 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/