From b19b1c353d22ca525544b6a012776ad660fa6d7a Mon Sep 17 00:00:00 2001 From: antifallobst Date: Mon, 29 May 2023 02:05:02 +0200 Subject: [PATCH] documented process configuration and driver syscalls --- kernel/sysabi.md | 99 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/kernel/sysabi.md b/kernel/sysabi.md index 81aa169..fad1143 100644 --- a/kernel/sysabi.md +++ b/kernel/sysabi.md @@ -39,20 +39,22 @@ The following calls should be implemented to some degree in noxos 1.0. | 0x0104 | `nx_mem_unlabel` | Takes the file descriptor away from a memory region. | fd | | | | status | N/A | ## Processes -| ID | Name | Description | Arg1 | Arg2 | Arg3 | Arg4 | Result | Status | -|--------|------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|------|--------|----------|------|--------|--------| -| 0x0201 | `nx_proc_create` | Creates a new process with the configuration _conf_ (which format is described below) and writes its process id to _pid_. | conf | *pid | | | status | N/A | -| 0x0202 | `nx_proc_signal_send` | Send the signal _signal_ to _pid_. See below for a list of signals. | pid | signal | | | status | N/A | -| 0x0203 | `nx_proc_signal_set_handler` | Sets a handler for the signal _signal_ in the process _pid_. Not all signals can have a handler. Look at the list for more information. | pid | signal | *handler | | status | N/A | -| 0x0204 | `nx_proc_thread_create` | Spawns a new thread for the current process. The starting point is defined by _addr_. The threads' ID is written into _tid_. | addr | *tid | | | status | N/A | -| 0x0205 | `nx_proc_thread_start` | Starts the current processes' thread with thread id _tid_. | tid | | | | status | N/A | -| 0x0206 | `nx_proc_thread_pause` | Pauses the current processes' thread with thread id _tid_. | tid | | | | status | N/A | -| 0x0207 | `nx_proc_thread_kill` | Kills the current processes' thread with thread id _tid_. | tid | | | | status | N/A | +| ID | Name | Description | Arg1 | Arg2 | Arg3 | Arg4 | Result | Status | +|--------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|--------|----------|------|------|--------|--------| +| 0x0201 | `nx_proc_create` | Creates a new process with the configuration _conf_ (which format is described below) and writes its process id to _pid_. | *conf | *pid | | | status | N/A | +| 0x0202 | `nx_proc_signal_send` | Send the signal _signal_ to _pid_. See below for a list of signals. | pid | signal | | | status | N/A | +| 0x0203 | `nx_proc_signal_set_handler` | Sets a handler for the signal _signal_ in the current process. Not all signals can have a handler. Look at the list for more information. | signal | *handler | | | status | N/A | +| 0x0204 | `nx_proc_thread_create` | Spawns a new thread for the current process. The starting point is defined by _addr_. The threads' ID is written into _tid_. | addr | *tid | | | status | N/A | +| 0x0205 | `nx_proc_thread_start` | Starts the current processes' thread with thread id _tid_. | tid | | | | status | N/A | +| 0x0206 | `nx_proc_thread_pause` | Pauses the current processes' thread with thread id _tid_. | tid | | | | status | N/A | +| 0x0207 | `nx_proc_thread_kill` | Kills the current processes' thread with thread id _tid_. | tid | | | | status | N/A | ## Drivers -| ID | Name | Description | Arg1 | Arg2 | Arg3 | Arg4 | Result | Status | -|-----|------|-------------|------|------|------|------|--------|--------| -| | | | | | | | | | +| ID | Name | Description | Arg1 | Arg2 | Arg3 | Arg4 | Result | Status | +|--------|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|------|-------|------|--------|--------| +| 0x0301 | `nx_drv_register` | Registers the executable at the _n_ bytes long _path_ as driver with the configuration _conf_. The format of the conf struct can be found below. | path | len | *conf | | status | N/A | +| 0x0302 | `nx_drv_create_command_buffer` | This has to be called from a driver. Registers _addr_ as command queue buffer with the length _len_, which has to be greater or equal 16384. If _addr_ is NULL or not aligned to 32 bytes or _len_ is less than 16384, the kernel will map a command queue buffer into the drivers address space, which is of length _len_ but at least 16384. The address to the registered buffer will be returned. | addr | len | | | addr | N/A | +| 0x0303 | `nx_drv_flush_command_buffer` | This has to be called from a driver. Flushes the command queue buffer at _addr_. | addr | | | | status | N/A | ## Kernel The kernel syscalls can only be called from the kernels main process [link to processing article needed]. @@ -74,6 +76,7 @@ If another process calls them, they will just return without doing anything. | 0 | `permissions` | Who has what permission to access the file | uint16_t | N/A | | 1 | `size` | The files size in bytes | uint64_t | N/A | +--- ### Memory mapping flags @@ -82,8 +85,35 @@ If another process calls them, they will just return without doing anything. | 0 | `write` | Enables write access to the mapped pages. | | 1 | `no_exec` | Prevents execution of the mapped pages. | +--- + ### Process configuration +**header:** + +| Length(bytes) | Name | Description | +|--------------------------|-----------------|--------------------------------------------------------------------------------| +| 0x01 | privilege_level | Specifies the privilege level the process runs on. (described below) | +| 0x80 | name | The processes' name (ascii). | +| 0x08 | executable | A file descriptor to the executable the process will be loaded from. | +| 0x04 | num_inherit_fds | The amount of file descriptors that will be inherited to the process. | +| 0x0F * `num_inherit_fds` | inherit_fds | The file descriptors that will be inherited to the process. (described below) | + +**header.privilege_level:** + +| Value | Name | Description | +|-------|-----------|-------------------------------------------------------------------------| +| 0 | as_parent | The new process will spawn with the same privilege level as its parent. | +| 1 | default | The new process will spawn with default user permissions. | + +**header.inherit_fds:** + +| Length(bytes) | Name | Description | +|---------------|-----------|--------------------------------------------------------------------------------| +| 0x08 | at_parent | The file descriptor, the parent process wants to inherit. | +| 0x08 | at_child | The file descriptor in the new child process. Same as `at_parent` if set to 0. | + + ### Process signals - __SIGSTART__: starts the process - __SIGPAUSE__: pauses the process @@ -91,3 +121,48 @@ If another process calls them, they will just return without doing anything. - __SIGEXIT__: send by the kernel before stopping the process - handler implementation possible - __SIGPFAULT__: sends when the process access memory it is not permitted to. Followed by SIGEXIT - handler implementation possible - __SIGMATHAULT__: sends when the process does stuff like dividing by zero. Followed by SIGEXIT - handler implementation possible + +--- + +### Driver configuration + +**header:** + +| Length(bytes) | Name | Description | +|---------------|--------------------|------------------------------------------------------------------------------| +| 0x01 | transport_protocol | Specifies the protocol over which the driver communicates. (described below) | +| 0x02 | length | Specifies the length of the `specific_config` section. | +| `length` | specific_config | Configuration specific to the transport protocol. (described below) | + + +**header.transport_protocol:** + +| Value | Name | Description | +|-------|--------|------------------------------------------------------------------------------------------| +| 0 | PCI(e) | The driver connects to devices on the _Peripheral Component Interconnect (express)_ Bus. | +| 1 | USB | The driver connects to devices on the _Universal Serial Bus_. | +| 2 | FS | The driver provides filesystem functionalities. | + + +**header.specific_config.pci:** + +| Length(bytes) | Name | Description | +|-------------------------|----------------|---------------------------------------------------------------| +| 0x02 | num_vendor_ids | The amount of PCI vendor ids the driver can handle. | +| 0x02 | num_device_ids | The amount of PCI device ids the driver can handle. | +| 0x02 * `num_vendor_ids` | vendor_ids | An array containing all PCI vendor ids the driver can handle. | +| 0x02 * `num_device_ids` | device_ids | An array containing all PCI device ids the driver can handle. | + + +**header.specific_config.usb:** + +| Length(bytes) | Name | Description | +|---------------|-------------|-----------------------------------------| +| 0x01 | min_version | The minimum required major USB version. | + +**header.specific_config.fs:** + +| Length(bytes) | Name | Description | +|---------------|----------|-------------------------------------------------------------------------| +| 0x0F | gpt_guid | The gpt GUID of the file system type that the driver handles. | +| 0x01 | mbr_type | The mbr partition type of the file system type that the driver handles. | \ No newline at end of file