Skip to content

Syscalls

George Kulikov edited this page Aug 13, 2025 · 1 revision

OpenDOS Syscalls Documentation (not implemented yet)

Overview

System calls (syscalls) in OpenDOS provide a controlled interface for user-space programs to request services from the kernel. They allow interaction with standard devices and system functions without giving direct access to kernel memory or hardware.


Syscall Numbers

Number Name Description
0 SYS_INPUT Read input from standard input (keyboard).
1 SYS_PRINT Write a string to standard output (screen).
2 SYS_PRINTERR Write a string to standard error (screen, red text).
5 SYS_EXIT Terminate the current program.

⚠️ Note: Numbers are fixed and must be used by programs to request the correct service.


Usage

General Structure

#include "syscalls.h"

uint32_t handle_syscall(uint32_t number, uint32_t arg1);

  • number — syscall number.

  • arg1 — argument, usually a pointer to a string or buffer, or a return code.


Example: Printing Text

handle_syscall(SYS_PRINT, (uint32_t)"Hello, OpenDOS!\n");
handle_syscall(SYS_PRINTERR, (uint32_t)"Error message!\n");
  • SYS_PRINT prints normally.

  • SYS_PRINTERR prints in red using ANSI escape codes.


Example: Reading Input

uint32_t c = handle_syscall(SYS_INPUT, 0);
// c contains the ASCII code of the pressed key

Example: Exiting a Program

handle_syscall(SYS_EXIT, 0);

Implementation Notes

  1. All syscalls are handled by handle_syscall() in syscall.c.

  2. Strings are printed using k_printf(), which supports ANSI escape codes for colored output.

  3. SYS_PRINTERR outputs text in red by wrapping the string with \x1b[31m ... \x1b[0m.

  4. Future syscalls can be added by extending the switch statement in handle_syscall() and assigning a new number.