-
Notifications
You must be signed in to change notification settings - Fork 1
Syscalls
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.
| 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.
#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.
handle_syscall(SYS_PRINT, (uint32_t)"Hello, OpenDOS!\n");
handle_syscall(SYS_PRINTERR, (uint32_t)"Error message!\n");
-
SYS_PRINTprints normally. -
SYS_PRINTERRprints in red using ANSI escape codes.
uint32_t c = handle_syscall(SYS_INPUT, 0);
// c contains the ASCII code of the pressed key
handle_syscall(SYS_EXIT, 0);
-
All syscalls are handled by
handle_syscall()insyscall.c. -
Strings are printed using
k_printf(), which supports ANSI escape codes for colored output. -
SYS_PRINTERRoutputs text in red by wrapping the string with\x1b[31m...\x1b[0m. -
Future syscalls can be added by extending the
switchstatement inhandle_syscall()and assigning a new number.