Home / Docs / Python Progress

Historical engineering note, with a current-status update below. Everything from "Completed Work" onward is a point-in-time snapshot from January 2026, capturing early libc prerequisite work for a planned MicroPython port. It undersells where the project actually ended up: MayteraOS moved past MicroPython entirely and now ships real CPython instead. See "Current status" immediately below for what is true today.

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.ELF is 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 is ET_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 name python, not PYTHON.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 structure
  • userland/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 functions
  • userland/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 - Implementation
  • userland/libc/stdlib.h - Declarations

Functions implemented:

  • strtol() - Convert string to long
  • strtoul() - Convert string to unsigned long
  • strtoll() - Convert string to long long
  • strtoull() - 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/Makefile to include setjmp.asm
  • Updated userland/libc/maytera.h to include setjmp.h
  • All files compile successfully

Next Steps for MicroPython Port

Phase 1 Remaining Work

  1. Download MicroPython Source
   git clone https://github.com/micropython/micropython.git
   cd micropython
   git checkout v1.22.0  # or latest stable
  1. 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
  1. Implement HAL Functions
  • mp_hal_stdin_rx_chr() - Read character from keyboard
  • mp_hal_stdout_tx_strn() - Write string to console/serial
  • mp_hal_ticks_ms() - Get milliseconds since boot
  • mp_hal_delay_ms() - Delay function
  1. Configure Memory
  • Allocate GC heap (256KB-1MB)
  • Implement memory wrappers if needed
  1. Test Basic REPL
  • Verify VM initialization
  • Test basic Python operations

Files Modified This Session

FileChanges
userland/libc/setjmp.hCreated - jmp_buf structure
userland/libc/setjmp.asmCreated - x86_64 setjmp/longjmp
userland/libc/stdio.cAdded snprintf, vsnprintf, sprintf
userland/libc/stdio.hAdded function declarations
userland/libc/stdlib.cAdded strtol, strtoul, strtoll, strtoull
userland/libc/stdlib.hAdded function declarations
userland/libc/maytera.hAdded setjmp.h include
userland/libc/MakefileAdded 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/