System calls
Access to kernel resources and IPC primitives is accomplished primarily through system calls (syscalls). There are a small number of syscalls that are used primarily to interact with capabilities. Note that the syscall API differs from the capability API, which is largely built on top of of SYS_call.
Common ABI types
Type declarations for Hare code are provided by the uapi module in the kernel source tree.
| Type | Description |
|---|---|
| u8 | 8-bit unsinged integer |
| u16 | 16-bit unsinged integer |
| u32 | 32-bit unsinged integer |
| u64 | 64-bit unsinged integer |
| uaddr | 64-bit memory address |
| caddr | 32-bit capability address |
| ctype | 8-bit capability type |
Capability types
| ID | Type | Description |
|---|---|---|
| 0 | NULL | Empty capability slot |
| 1 | MEMORY | General-purpose memory |
| 2 | CSPACE | Capability space |
| 3 | VSPACE | Virtual address space |
| 4 | TASK | Schedulable task |
| 5 | PAGE | Page of memory |
| 6 | NOTIFICATION | IPC notification |
| 7 | ENDPOINT | IPC endpoint |
| 8 | REPLY | IPC reply |
x86_64 specific
| ID | Type | Description |
|---|---|---|
| 9 | PDPT | Page-directory pointer table |
| 10 | PD | Page directory |
| 11 | PT | Page table |
| 12 | IOCONTROL | I/O control |
| 13 | IOPORT | I/O port |
| 14 | IRQCONTROL | IRQ control |
| 15 | IRQ | IRQ |
x86_64 ABI
The x86_64 syscall ABI is based on the System-V ABI. All arguments are passed in registers. Note that floating point registers are not used by the ABI (and are preserved by the kernel).
Input registers
| Register | Purpose |
|---|---|
| %rax | Syscall number (8 bits) & flags |
| %rdi | (a1) 1st argument register |
| %rsi | (a2) 2nd argument register |
| %rdx | (a3) 3rd argument register |
| %r10 | (a4) 4th argument register1 |
| %r8 | (a5) 5th argument register |
| %r9 | (a6) 6th argument register |
Output registers
| Register | Purpose |
|---|---|
| %rax | Syscall outcome (8 bits) + 56 syscall-specific bits |
| %rsi | (r1) 1st return register |
| %rdx | (r1) 2nd return register |
The syscall outcome is 0 on success or an error code on failure.
Other registers
| Register | Purpose |
|---|---|
| %r12-%r15 | Kernel-saved |
| %rbp | Kernel-saved |
| %rbx | Kernel-saved |
| %fs, %gs | Kernel-saved |
Note
Certain syscalls, notably SYS_call and SYS_recv, differ from the standard register allocation.
Error codes
The following error codes are defined:
| Code | Name | Description |
|---|---|---|
| 0 | n/a | Indicates a successful outcome. |
| 1 | EWRONGTYPE | An incorrect resource type was used in an operation. |
| 2 | ENOMEM | Insufficient memory available for requested operation. |
| 3 | EINVALID | An invalid parameter was supplied for an operation. |
| 4 | EINVALCADDR | An invalid capability address was used. |
| 5 | ERANGE | A parameter exceeds the permissible range. |
| 6 | EEXIST | A resource already exists at the given address. |
| 7 | ENOENT | A required resource does not exist. |
| 8 | EBUSY | A required resource is currently in use. |
| 9 | ENOTSUP | The requested operation is not supported. |
| 10 | ENOSYS | Invalid syscall or function. |
| 11 | EFAULT | Use of invalid address. |
| 12 | EL1PT | VSpace mapping is missing a required level 1 page table. |
| 13 | EL2PT | VSpace mapping is missing a required level 2 page table. |
| 14 | EL3PT | VSpace mapping is missing a required level 3 page table. |
| 15 | EL4PT | VSpace mapping is missing a required level 4 page table. |
| 16 | EDESTROYED | A resource was destroyed during the operation. |
-
Note that the System-V ABI assigns the 4th argument to %rcx. ↩