-
Notifications
You must be signed in to change notification settings - Fork 0
System Calls
System calls in MVM (Micro Virtual Machine) allow your assembly programs to request services from the underlying operating system or environment. These services include file operations, gathering system information, and more.
The SYSCALL
instruction executes a system call. Before executing SYSCALL
, you must set the following registers:
- S0: The system call ID (a number that identifies the specific system call).
- S1 - S3: Arguments for the system call (if any). The meaning of these arguments depends on the specific system call being invoked.
System calls typically return a result in register R2. Some system calls may not return a value. All errors encountered during system calls will immediately terminate the program.*
LIT S0 14 // System call ID for "time" (get current time)
SYSCALL // Execute the system call. The current time is now in R2.
MOV R2 G1 // Store the returned time from R2 into general register G1.
The System Call Table provides a comprehensive list of all available system calls, their IDs, arguments, and return values.
This section describes some of the frequently used system calls:
-
File I/O:
-
openFile(path)
(ID: 3): Opens the file specified by the null-terminated string at the memory address inS1
. Returns a file descriptor inR2
. -
readFile(fd)
(ID: 1): Reads data from the file identified by the file descriptor (fd
) inS1
. Stores the starting address of the read data in memory inR2
. -
writeFile(fd, buffer)
(ID: 2): Writes data to a file. holds the file descriptor, andS2
contains the starting address of the buffer in memory that holds the data to be written. -
closeFile(fd)
(ID: 4): Closes the file specified by the file descriptor inS1
.
-
-
Process Management:
-
exit(exitCode)
(ID: 5): Terminates the MVM program with the exit code provided inS1
.
-
-
System Information:
-
time()
(ID: 14): Returns the current time in milliseconds inR2
. -
getpid()
(ID: 16): Returns the process ID of the MVM instance inR2
. -
getuid()
(ID: 17): Returns the user ID inR2
.
-
-
Input/Output:
-
writeIo(stringAddr)
(ID: 24): Prints the null-terminated string at the memory address inS1
to the console. -
readIo()
(ID: 25): Reads a line from standard input and stores it as a null-terminated string in memory. Returns the starting address of the string inR2
.
-
-
Array Operations:
-
createArray(size)
(ID: 26): Creates an array of the specifiedsize
(inS1
). Returns the base address of the allocated array inR2
. -
arraySet(arrayAddr, index, value)
(ID: 27): Sets the element atindex
of the array atarrayAddr
tovalue
. Arguments:arrayAddr
inS1
,index
inS2
,value
inS3
. -
arrayGet(arrayAddr, index)
(ID: 28): Returns the value of the element atindex
in the array at addressarrayAddr
. Arguments are passed in the same order asarraySet
. The element's value is returned inR2
.
-
// ...get file descriptor (fd) in R1 using openFile...
// String to write (must be null-terminated)
STR S2 "Hello, file!\n" // S2 holds the string's address
LIT S0 2 // System call ID for writeFile
MOV R2 S1 // File descriptor (fd) as the first argument in S1
CPY S2 S2 // Address of the string to write as the second argument in S2
SYSCALL // Call writeFile
MVM (Micro Virtual Machine) Wiki | Made with love and kotlin
warning, docs rewrite
Getting Started
Programming Guide
- Introduction to MVM Assembly
- Instruction Set
- Registers
- Memory and Addressing
- System Calls
- Standard Library
- Subroutines (Functions)
Reference Tables
VM Internals (Advanced)
- Architecture Overview
- Execution Engine NOT UPDATED
- System Call Implementation NOT UPDATED
- Memory Management NOT UPDATED
- Plans
Project