Documentation Index
Fetch the complete documentation index at: https://mintlify.com/CRISTOP-bot/cris-os-v2/llms.txt
Use this file to discover all available pages before exploring further.
asm.h declares C-callable assembly routines implemented in src/asm_utils.S and src/math_asm.S. These functions perform operations that require direct x86 instruction access: integer arithmetic (for educational demonstration via the shell’s asm command), CPU halt and reset, I/O port read/write used by every hardware driver, and fast VGA memory operations used by the console and GUI overlay. All routines use the standard i386 cdecl calling convention.
Integer Arithmetic
These four functions expose raw x86 arithmetic instructions through C-callable wrappers. They are used by the shell’s built-inasm <op> <a> <b> command to demonstrate low-level computation directly.
add_asm
add instruction. Implemented in src/math_asm.S.
First operand. Loaded into
%eax.Second operand. Added to
%eax via addl 12(%ebp), %eax.a + b as a signed 32-bit integer. Overflow wraps silently (no exception).
sub_asm
b from a using the x86 subl instruction. Implemented in src/asm_utils.S.
Minuend. Loaded into
%eax.Subtrahend. Subtracted from
%eax via subl 12(%ebp), %eax.a - b as a signed 32-bit integer.
mul_asm
imull instruction. Implemented in src/asm_utils.S.
First factor. Loaded into
%eax.Second factor. Multiplied into
%eax via imull 12(%ebp), %eax.a * b. High bits are discarded silently on overflow.
div_asm
a by b using the x86 cdq / idivl instruction sequence. The dividend in %eax is sign-extended into %edx:%eax via cdq before idivl computes the quotient in %eax. If b is zero the function returns 0 immediately (zero-check guard via testl/jnz). Implemented in src/asm_utils.S.
Dividend. Loaded into
%eax and sign-extended into %edx.Divisor. Loaded into
%ecx. If zero, the function returns 0 without executing idivl.a / b. The remainder (in %edx) is discarded.
CPU Control
halt_cpu
cli and then enters an infinite hlt loop. The CPU is permanently halted until the system is physically reset. Used by the kernel after a fatal error or panic. Implemented in src/asm_utils.S.
Returns: Never returns.
reboot_cpu
0xFE to PS/2 controller port 0x64. The PS/2 controller’s system reset line is pulsed, causing the CPU to reset. Interrupts are disabled with cli first. Implemented in src/asm_utils.S as:
outb the code spins in a local jump loop — the CPU should reset before reaching it.
Returns: Never returns under normal operation.
I/O Port Access
inb
port using the inb %dx, %al instruction. The port number is loaded into %dx and the result byte is zero-extended into %eax before returning. Used by every hardware driver in CrisOS v2 (keyboard, timer, PIC). Implemented in src/asm_utils.S.
16-bit I/O port address to read from.
The x86
in instruction is privileged in ring 3. CrisOS v2 runs entirely in ring 0 (kernel mode), so all I/O port access is unrestricted.outb
value to x86 I/O port port using the outb %al, %dx instruction. The port is loaded into %dx and the value into %al. Used by every hardware driver in CrisOS v2. Implemented in src/asm_utils.S.
16-bit I/O port address to write to.
Byte value to write to the port.
void).
The x86
out instruction is privileged in ring 3. CrisOS v2 runs entirely in ring 0, so all I/O port access is unrestricted.VGA Memory Helpers
console_putxy
c with VGA attribute byte attr directly to the VGA text-mode buffer at column x, row y. The VGA text buffer base address is 0xB8000; each cell occupies two bytes (low byte = character, high byte = attribute). The offset is calculated as (y * 80 + x) * 2. Implemented in src/asm_utils.S. Used by the GUI overlay to paint individual cells without going through the console scroll logic.
Column index (0–79 for a standard 80-column display).
Row index (0–24 for a standard 25-row display).
ASCII character to write.
VGA attribute byte. The high nibble is the background colour and the low nibble is the foreground colour. For example,
0x0F is bright white on black, 0x4F is bright white on red, and 0x1E is yellow on blue.void).
memsetw_asm
count consecutive 16-bit words starting at dest with value, using the rep stosw instruction for maximum throughput. %edi is set to dest, %ax to value, %ecx to count, and the direction flag is cleared with cld before the repeat. Used for fast VGA screen clearing — one call can blank the entire 80×25 text buffer (2000 words) in a single instruction burst. Implemented in src/asm_utils.S.
Pointer to the start of the destination region. For full-screen VGA clearing this is typically
(void *)0xB8000.16-bit word to fill with. For VGA, pack the character in the low byte and the attribute in the high byte (e.g.
0x0720 for a space with a light-grey-on-black attribute).Number of 16-bit words to write. For a full 80×25 VGA screen, pass
2000.void).