Skip to content

Assembly Files

Levente Santha edited this page May 9, 2026 · 1 revision

Assembly Files

While JNode is primarily written in Java, low-level bootstrapping, CPU initialization, and core OS primitives require native x86 assembly. These files are assembled by JNasm during the build process.

Location

All assembly files are located in core/src/native/x86/.

The Boot Sequence

These files are executed before the Java Virtual Machine is fully operational.

File Role
kernel.asm The absolute entry point. Contains the Multiboot header recognized by GRUB. Sets up the initial kernel stack, parses multiboot parameters, and transitions into the VM.
ap-boot.asm Application Processor bootstrap. Used for initializing secondary CPU cores in an SMP (Symmetric Multiprocessing) system.
console.asm Early VGA text-mode console. Used for raw debug output (Unsafe.debug()) before the Java-level System.out and GUI console are ready.

Memory Management (Paging)

These files handle the raw hardware-level memory initialization.

File Role
mm32.asm 32-bit memory management. Sets up the Global Descriptor Table (GDT), Task State Segment (TSS), and initial 32-bit page tables (4KB and 4MB pages). Enables paging.
mm64.asm 64-bit memory management. Sets up the Page Map Level 4 (PML4) tables and transitions the CPU from 32-bit protected mode into 64-bit long mode.

Interrupts & Traps

Hardware interrupts and CPU exceptions (like page faults) are caught here before being routed to Java.

File Role
ints.asm Core interrupt handling setup. Constructs the Interrupt Descriptor Table (IDT).
ints32.asm / ints64.asm 32-bit / 64-bit specific interrupt service routines (ISRs) and trap handlers.
vm-ints.asm Bridges the gap between raw hardware interrupts (caught in ints.asm) and the Java-level org.jnode.vm.scheduler.IRQManager. Handles context saving before jumping to Java.

CPU & System Details

File Role
cpu.asm / cpu32.asm Detects CPU features using the CPUID instruction and handles basic CPU control register manipulation.
syscall.asm Fast system call entry point (SYSENTER / SYSCALL). Currently experimental or reserved for future use.
kdb.asm Very low-level kernel debugger stubs.
jnode.asm / version.asm Macros and version strings baked into the binary.

VM Support & Unsafe Operations

These files provide native implementations for operations that cannot be expressed in pure Java or require direct processor access.

File Role
vm.asm Core VM native methods. Includes the vm_invoke routine used for dynamically invoking Java methods from native code.
unsafe.asm Native implementations for org.jnode.vm.Unsafe. Includes atomic operations (CAS), raw memory reads/writes, and I/O port instructions (IN, OUT).
unsafe-binop.asm Native binary operations (like atomic adds).
unsafe-setmulti.asm Native block memory operations (like memset or memcpy).
unsafex86.asm x86-specific unsafe operations.
unsafex86-cpuid.asm CPUID instruction wrapper for Java.
unsafex86-mm.asm Native memory management operations (flushing TLB, reading CR2 for page faults).

Headers (.h files)

JNasm supports basic C-style macros and includes.

File Role
i386.h / i386_bits.h Definitions for x86 control registers (CR0, CR4), EFLAGS bits, and page fault error codes.
console.h Macros for printing strings and hex values in early boot.
rmconfig.h Configuration constants.

Related Pages

  • Boot-Sequence — How kernel.asm and mm32.asm orchestrate the boot process.
  • Memory-Management — How the hardware paging interacts with Java heaps.
  • VM-Magic — How Unsafe operations in Java translate to unsafe.asm routines.

Clone this wiki locally