summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/drivers/uart.h8
-rw-r--r--include/fs/fs.h3
-rw-r--r--include/kernel/config.h6
-rw-r--r--include/kernel/fdt.h45
-rw-r--r--include/kernel/pmm.h11
-rw-r--r--include/kernel/syscall.h103
-rw-r--r--include/lib/errno.h168
-rw-r--r--include/ulib/errno.h168
-rw-r--r--include/user/user.h48
9 files changed, 504 insertions, 56 deletions
diff --git a/include/drivers/uart.h b/include/drivers/uart.h
index 1cdc938..a56624c 100644
--- a/include/drivers/uart.h
+++ b/include/drivers/uart.h
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (C) 2026 Richard QIn
+ * Copyright (C) 2026 Richard Qin
*/
#pragma once
#include "common/types.h"
#include "drivers/uart_color.h"
+#include "kernel/fdt.h"
-#define UART0 0x10000000L
+// UART register offsets (NS16550A)
#define RHR 0 // Receive Holding Register (read mode)
#define THR 0 // Transmit Holding Register (write mode)
#define IER 1 // Interrupt Enable Register
@@ -21,6 +22,9 @@
#define UART_RX_BUF_SIZE 128
+// UART base address from FDT (use inline function to avoid macro issues)
+static inline uint64 uart_base() { return g_devices.uart.base_addr; }
+
namespace Drivers
{
void uart_init();
diff --git a/include/fs/fs.h b/include/fs/fs.h
index 967858b..b511a84 100644
--- a/include/fs/fs.h
+++ b/include/fs/fs.h
@@ -99,4 +99,7 @@ namespace VFS
Inode *namei(const char *path);
// Find the parent directory inode of the path, and copy the last part of the path (the file name) into the name buffer
Inode *nameiparent(const char *path, char *name);
+ // Register a file system
+ void register_fs(FileSystem *fs);
+
} // namespace VFS
diff --git a/include/kernel/config.h b/include/kernel/config.h
index 45d85cd..49df2ff 100644
--- a/include/kernel/config.h
+++ b/include/kernel/config.h
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (C) 2026 Richard QIn
+ * Copyright (C) 2026 Richard Qin
*/
#pragma once
#include "common/types.h"
+#include "kernel/fdt.h"
+// Legacy compat — these are still referenced in some places
extern uint64 g_uart_base;
-extern uint64 g_clint_base;
-extern uint64 g_plic_base;
extern uint64 g_dtb_addr; \ No newline at end of file
diff --git a/include/kernel/fdt.h b/include/kernel/fdt.h
new file mode 100644
index 0000000..89cbae6
--- /dev/null
+++ b/include/kernel/fdt.h
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Richard Qin
+ * LumeOS - FDT Device Discovery
+ */
+
+#pragma once
+#include "common/types.h"
+
+// Single device descriptor (populated from FDT)
+struct FdtDevice {
+ uint64 base_addr; // MMIO base address
+ uint64 size; // MMIO region size
+ uint32 irq; // Interrupt number (0 = none)
+};
+
+// Device registry — populated by fdt_parse(), consumed by drivers
+struct DeviceRegistry {
+ // Memory
+ uint64 mem_base;
+ uint64 mem_size;
+
+ // Core platform devices
+ FdtDevice uart;
+ FdtDevice plic;
+ FdtDevice clint;
+
+ // VirtIO devices (multiple possible)
+ static constexpr int MAX_VIRTIO = 8;
+ FdtDevice virtio[MAX_VIRTIO];
+ int virtio_count;
+
+ // MMIO ranges for kvminit() to map
+ static constexpr int MAX_MMIO = 16;
+ struct MmioRegion {
+ uint64 base;
+ uint64 size;
+ } mmio_regions[MAX_MMIO];
+ int mmio_count;
+};
+
+extern DeviceRegistry g_devices;
+
+// Parse FDT and populate g_devices
+void fdt_parse(uint64 dtb);
diff --git a/include/kernel/pmm.h b/include/kernel/pmm.h
index 1fc3070..261786d 100644
--- a/include/kernel/pmm.h
+++ b/include/kernel/pmm.h
@@ -1,16 +1,21 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (C) 2026 Richard QIn
+ * Copyright (C) 2026 Richard Qin
*/
#pragma once
#include "common/types.h"
#include "kernel/spinlock.h"
+#include "kernel/fdt.h" // For g_devices
// Physical Memory Layout Definition
#define KERNBASE 0x80000000
-// Set the memory size to 128MB
-#define PHYSIZE (128 * 1024 * 1024)
+
+// Dynamic memory size from FDT
+// Default to 128MB if FDT not present/parsed
+extern uint64 g_phys_size;
+
+#define PHYSIZE (g_phys_size)
#define PHYSTOP (KERNBASE + PHYSIZE)
// Buddy System Max Order
diff --git a/include/kernel/syscall.h b/include/kernel/syscall.h
index af4c474..3594c08 100644
--- a/include/kernel/syscall.h
+++ b/include/kernel/syscall.h
@@ -1,35 +1,84 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (C) 2026 Richard QIn
-*/
+ * Copyright (C) 2026 Richard Qin
+ * Lume OS - Linux Compatibility Layer
+ *
+ * Strictly aligned with Linux RISC-V 64 ABI (asm-generic)
+ * Reference: linux/usr/include/asm-generic/unistd.h
+ */
#pragma once
-#define SYS_putc 1
-#define SYS_fork 2
-#define SYS_exit 3
-#define SYS_wait 4
-#define SYS_pipe 5
-#define SYS_read 6
-#define SYS_kill 7
-#define SYS_exec 8
-#define SYS_fstat 9
-#define SYS_chdir 10
-#define SYS_dup 11
-#define SYS_getpid 12
-#define SYS_sbrk 13
-#define SYS_sleep 14
-#define SYS_uptime 15
-#define SYS_open 16
-#define SYS_write 17
-#define SYS_mknod 18
-#define SYS_unlink 19
-#define SYS_link 20
-#define SYS_mkdir 21
-#define SYS_close 22
-#define SYS_disk_test 23
-#define SYS_lseek 24
-#define SYS_shutdown 25
+// File System
+#define SYS_getcwd 17
+#define SYS_dup 23
+#define SYS_dup3 24
+#define SYS_fcntl 25
+#define SYS_ioctl 29
+#define SYS_mknodat 33
+#define SYS_mkdirat 34
+#define SYS_unlinkat 35
+#define SYS_linkat 37
+#define SYS_umount2 39
+#define SYS_mount 40
+#define SYS_statfs 43
+#define SYS_ftruncate 46
+#define SYS_faccessat 48
+#define SYS_chdir 49
+#define SYS_fchmod 52
+#define SYS_fchmodat 53
+#define SYS_fchownat 54
+#define SYS_openat 56
+#define SYS_close 57
+#define SYS_vhangup 58
+#define SYS_pipe2 59
+#define SYS_getdents64 61
+#define SYS_lseek 62
+#define SYS_read 63
+#define SYS_write 64
+#define SYS_readv 65
+#define SYS_writev 66
+#define SYS_pread64 67
+#define SYS_pwrite64 68
+#define SYS_pselect6 72
+#define SYS_ppoll 73
+#define SYS_readlinkat 78
+#define SYS_fstatat 79 // newfstatat
+#define SYS_fstat 80
+
+// Process Management
+#define SYS_exit 93
+#define SYS_exit_group 94
+#define SYS_set_tid_address 96
+#define SYS_nanosleep 101
+#define SYS_kill 129
+#define SYS_rt_sigaction 134
+#define SYS_times 153
+#define SYS_uname 160
+#define SYS_gettimeofday 169
+#define SYS_getpid 172
+#define SYS_getppid 173
+#define SYS_getuid 174
+#define SYS_geteuid 175
+#define SYS_getgid 176
+#define SYS_getegid 177
+#define SYS_sysinfo 179
+#define SYS_brk 214
+#define SYS_munmap 215
+#define SYS_mremap 216
+#define SYS_clone 220
+#define SYS_execve 221
+#define SYS_mmap 222
+#define SYS_wait4 260
+#define SYS_prlimit64 261
+
+// System
+#define SYS_reboot 142 // Used for shutdown
+
+// === Custom / Debug (Non-Standard) ===
+// Placed above 1000 to avoid conflicts with Linux ABI
+#define SYS_putc 1000
+#define SYS_disk_test 1001
#ifndef __ASSEMBLER__
void syscall();
diff --git a/include/lib/errno.h b/include/lib/errno.h
new file mode 100644
index 0000000..62fd3e5
--- /dev/null
+++ b/include/lib/errno.h
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Richard Qin
+ * Lume OS - Linux Compatibility Layer
+ *
+ * This file aligns strictly with Linux RISC-V 64 ABI (asm-generic).
+ * Reference: linux/include/uapi/asm-generic/errno-base.h
+ * Reference: linux/include/uapi/asm-generic/errno.h
+ */
+
+#ifndef _ERRNO_H
+#define _ERRNO_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* 1-34: asm-generic/errno-base.h */
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* I/O error */
+#define ENXIO 6 /* No such device or address */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file number */
+#define ECHILD 10 /* No child processes */
+#define EAGAIN 11 /* Try again */
+#define ENOMEM 12 /* Out of memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#define ENOTBLK 15 /* Block device required */
+#define EBUSY 16 /* Device or resource busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* No such device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* File table overflow */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Not a typewriter */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+#define EDOM 33 /* Math argument out of domain of func */
+#define ERANGE 34 /* Math result not representable */
+
+/* * CRITICAL FIX: Missing definitions (35-37) from asm-generic
+ * Without these, your file system and locking code will fail compliance.
+ */
+#define EDEADLK 35 /* Resource deadlock would occur */
+#define ENAMETOOLONG 36 /* File name too long */
+#define ENOLCK 37 /* No record locks available */
+
+#define ENOSYS 38 /* Invalid system call number */
+#define ENOTEMPTY 39 /* Directory not empty */
+#define ELOOP 40 /* Too many symbolic links encountered */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define ENOMSG 42 /* No message of desired type */
+#define EIDRM 43 /* Identifier removed */
+#define ECHRNG 44 /* Channel number out of range */
+#define EL2NSYNC 45 /* Level 2 not synchronized */
+#define EL3HLT 46 /* Level 3 halted */
+#define EL3RST 47 /* Level 3 reset */
+#define ELNRNG 48 /* Link number out of range */
+#define EUNATCH 49 /* Protocol driver not attached */
+#define ENOCSI 50 /* No CSI structure available */
+#define EL2HLT 51 /* Level 2 halted */
+#define EBADE 52 /* Invalid exchange */
+#define EBADR 53 /* Invalid request descriptor */
+#define EXFULL 54 /* Exchange full */
+#define ENOANO 55 /* No anode */
+#define EBADRQC 56 /* Invalid request code */
+#define EBADSLT 57 /* Invalid slot */
+
+#define EDEADLOCK EDEADLK
+
+#define EBFONT 59 /* Bad font file format */
+#define ENOSTR 60 /* Device not a stream */
+#define ENODATA 61 /* No data available */
+#define ETIME 62 /* Timer expired */
+#define ENOSR 63 /* Out of streams resources */
+#define ENONET 64 /* Machine is not on the network */
+#define ENOPKG 65 /* Package not installed */
+#define EREMOTE 66 /* Object is remote */
+#define ENOLINK 67 /* Link has been severed */
+#define EADV 68 /* Advertise error */
+#define ESRMNT 69 /* Srmount error */
+#define ECOMM 70 /* Communication error on send */
+#define EPROTO 71 /* Protocol error */
+#define EMULTIHOP 72 /* Multihop attempted */
+#define EDOTDOT 73 /* RFS specific error */
+#define EBADMSG 74 /* Not a data message */
+#define EOVERFLOW 75 /* Value too large for defined data type */
+#define ENOTUNIQ 76 /* Name not unique on network */
+#define EBADFD 77 /* File descriptor in bad state */
+#define EREMCHG 78 /* Remote address changed */
+#define ELIBACC 79 /* Can not access a needed shared library */
+#define ELIBBAD 80 /* Accessing a corrupted shared library */
+#define ELIBSCN 81 /* .lib section in a.out corrupted */
+#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
+#define ELIBEXEC 83 /* Cannot exec a shared library directly */
+#define EILSEQ 84 /* Illegal byte sequence */
+#define ERESTART 85 /* Interrupted system call should be restarted */
+#define ESTRPIPE 86 /* Streams pipe error */
+#define EUSERS 87 /* Too many users */
+#define ENOTSOCK 88 /* Socket operation on non-socket */
+#define EDESTADDRREQ 89 /* Destination address required */
+#define EMSGSIZE 90 /* Message too long */
+#define EPROTOTYPE 91 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 92 /* Protocol not available */
+#define EPROTONOSUPPORT 93 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
+#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
+#define EPFNOSUPPORT 96 /* Protocol family not supported */
+#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
+#define EADDRINUSE 98 /* Address already in use */
+#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
+#define ENETDOWN 100 /* Network is down */
+#define ENETUNREACH 101 /* Network is unreachable */
+#define ENETRESET 102 /* Network dropped connection because of reset */
+#define ECONNABORTED 103 /* Software caused connection abort */
+#define ECONNRESET 104 /* Connection reset by peer */
+#define ENOBUFS 105 /* No buffer space available */
+#define EISCONN 106 /* Transport endpoint is already connected */
+#define ENOTCONN 107 /* Transport endpoint is not connected */
+#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
+#define ETOOMANYREFS 109 /* Too many references: cannot splice */
+#define ETIMEDOUT 110 /* Connection timed out */
+#define ECONNREFUSED 111 /* Connection refused */
+#define EHOSTDOWN 112 /* Host is down */
+#define EHOSTUNREACH 113 /* No route to host */
+#define EALREADY 114 /* Operation already in progress */
+#define EINPROGRESS 115 /* Operation now in progress */
+#define ESTALE 116 /* Stale file handle */
+#define EUCLEAN 117 /* Structure needs cleaning */
+#define ENOTNAM 118 /* Not a XENIX named type file */
+#define ENAVAIL 119 /* No XENIX semaphores available */
+#define EISNAM 120 /* Is a named type file */
+#define EREMOTEIO 121 /* Remote I/O error */
+#define EDQUOT 122 /* Quota exceeded */
+#define ENOMEDIUM 123 /* No medium found */
+#define EMEDIUMTYPE 124 /* Wrong medium type */
+#define ECANCELED 125 /* Operation Canceled */
+#define ENOKEY 126 /* Required key not available */
+#define EKEYEXPIRED 127 /* Key has expired */
+#define EKEYREVOKED 128 /* Key has been revoked */
+#define EKEYREJECTED 129 /* Key was rejected by service */
+#define EOWNERDEAD 130 /* Owner died */
+#define ENOTRECOVERABLE 131 /* State not recoverable */
+#define ERFKILL 132 /* Operation not possible due to RF-kill */
+#define EHWPOISON 133 /* Memory page has hardware error */
+
+extern __thread int errno;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif \ No newline at end of file
diff --git a/include/ulib/errno.h b/include/ulib/errno.h
index 19da4d1..c1691db 100644
--- a/include/ulib/errno.h
+++ b/include/ulib/errno.h
@@ -1,6 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (C) 2026 Richard QIn
+ * Copyright (C) 2026 Richard Qin
+ * Lume OS - Linux Compatibility Layer
+ *
+ * This file aligns strictly with Linux RISC-V 64 ABI (asm-generic).
+ * Reference: linux/include/uapi/asm-generic/errno-base.h
+ * Reference: linux/include/uapi/asm-generic/errno.h
*/
#ifndef _ERRNO_H
@@ -11,24 +16,153 @@ extern "C"
{
#endif
-extern int errno;
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* I/O error */
+#define ENXIO 6 /* No such device or address */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file number */
+#define ECHILD 10 /* No child processes */
+#define EAGAIN 11 /* Try again */
+#define ENOMEM 12 /* Out of memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#define ENOTBLK 15 /* Block device required */
+#define EBUSY 16 /* Device or resource busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* No such device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* File table overflow */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Not a typewriter */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+#define EDOM 33 /* Math argument out of domain of func */
+#define ERANGE 34 /* Math result not representable */
+/*
+ * This error code is special: arch syscall entry code will return
+ * -ENOSYS if users try to call a syscall that doesn't exist. To keep
+ * failures of syscalls that really do exist distinguishable from
+ * failures due to attempts to use a nonexistent syscall, syscall
+ * implementations should refrain from returning -ENOSYS.
+ */
+#define ENOSYS 38 /* Invalid system call number */
+
+#define ENOTEMPTY 39 /* Directory not empty */
+#define ELOOP 40 /* Too many symbolic links encountered */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define ENOMSG 42 /* No message of desired type */
+#define EIDRM 43 /* Identifier removed */
+#define ECHRNG 44 /* Channel number out of range */
+#define EL2NSYNC 45 /* Level 2 not synchronized */
+#define EL3HLT 46 /* Level 3 halted */
+#define EL3RST 47 /* Level 3 reset */
+#define ELNRNG 48 /* Link number out of range */
+#define EUNATCH 49 /* Protocol driver not attached */
+#define ENOCSI 50 /* No CSI structure available */
+#define EL2HLT 51 /* Level 2 halted */
+#define EBADE 52 /* Invalid exchange */
+#define EBADR 53 /* Invalid request descriptor */
+#define EXFULL 54 /* Exchange full */
+#define ENOANO 55 /* No anode */
+#define EBADRQC 56 /* Invalid request code */
+#define EBADSLT 57 /* Invalid slot */
+
+#define EDEADLOCK EDEADLK
-// Linux/ASM-Generic
-#define EPERM 1 /* Operation not permitted */
-#define ENOENT 2 /* No such file or directory */
-#define ESRCH 3 /* No such process */
-#define EINTR 4 /* Interrupted system call */
-#define EIO 5 /* I/O error */
-#define ENXIO 6 /* No such device or address */
-#define E2BIG 7 /* Argument list too long */
-#define ENOEXEC 8 /* Exec format error */
-#define EBADF 9 /* Bad file number */
-#define ECHILD 10 /* No child processes */
-#define EAGAIN 11 /* Try again */
-#define ENOMEM 12 /* Out of memory */
-#define EACCES 13 /* Permission denied */
-#define EFAULT 14 /* Bad address */
+#define EBFONT 59 /* Bad font file format */
+#define ENOSTR 60 /* Device not a stream */
+#define ENODATA 61 /* No data available */
+#define ETIME 62 /* Timer expired */
+#define ENOSR 63 /* Out of streams resources */
+#define ENONET 64 /* Machine is not on the network */
+#define ENOPKG 65 /* Package not installed */
+#define EREMOTE 66 /* Object is remote */
+#define ENOLINK 67 /* Link has been severed */
+#define EADV 68 /* Advertise error */
+#define ESRMNT 69 /* Srmount error */
+#define ECOMM 70 /* Communication error on send */
+#define EPROTO 71 /* Protocol error */
+#define EMULTIHOP 72 /* Multihop attempted */
+#define EDOTDOT 73 /* RFS specific error */
+#define EBADMSG 74 /* Not a data message */
+#define EOVERFLOW 75 /* Value too large for defined data type */
+#define ENOTUNIQ 76 /* Name not unique on network */
+#define EBADFD 77 /* File descriptor in bad state */
+#define EREMCHG 78 /* Remote address changed */
+#define ELIBACC 79 /* Can not access a needed shared library */
+#define ELIBBAD 80 /* Accessing a corrupted shared library */
+#define ELIBSCN 81 /* .lib section in a.out corrupted */
+#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
+#define ELIBEXEC 83 /* Cannot exec a shared library directly */
+#define EILSEQ 84 /* Illegal byte sequence */
+#define ERESTART 85 /* Interrupted system call should be restarted */
+#define ESTRPIPE 86 /* Streams pipe error */
+#define EUSERS 87 /* Too many users */
+#define ENOTSOCK 88 /* Socket operation on non-socket */
+#define EDESTADDRREQ 89 /* Destination address required */
+#define EMSGSIZE 90 /* Message too long */
+#define EPROTOTYPE 91 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 92 /* Protocol not available */
+#define EPROTONOSUPPORT 93 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
+#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
+#define EPFNOSUPPORT 96 /* Protocol family not supported */
+#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
+#define EADDRINUSE 98 /* Address already in use */
+#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
+#define ENETDOWN 100 /* Network is down */
+#define ENETUNREACH 101 /* Network is unreachable */
+#define ENETRESET 102 /* Network dropped connection because of reset */
+#define ECONNABORTED 103 /* Software caused connection abort */
+#define ECONNRESET 104 /* Connection reset by peer */
+#define ENOBUFS 105 /* No buffer space available */
+#define EISCONN 106 /* Transport endpoint is already connected */
+#define ENOTCONN 107 /* Transport endpoint is not connected */
+#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
+#define ETOOMANYREFS 109 /* Too many references: cannot splice */
+#define ETIMEDOUT 110 /* Connection timed out */
+#define ECONNREFUSED 111 /* Connection refused */
+#define EHOSTDOWN 112 /* Host is down */
+#define EHOSTUNREACH 113 /* No route to host */
+#define EALREADY 114 /* Operation already in progress */
+#define EINPROGRESS 115 /* Operation now in progress */
+#define ESTALE 116 /* Stale file handle */
+#define EUCLEAN 117 /* Structure needs cleaning */
+#define ENOTNAM 118 /* Not a XENIX named type file */
+#define ENAVAIL 119 /* No XENIX semaphores available */
+#define EISNAM 120 /* Is a named type file */
+#define EREMOTEIO 121 /* Remote I/O error */
+#define EDQUOT 122 /* Quota exceeded */
+#define ENOMEDIUM 123 /* No medium found */
+#define EMEDIUMTYPE 124 /* Wrong medium type */
+#define ECANCELED 125 /* Operation Canceled */
+#define ENOKEY 126 /* Required key not available */
+#define EKEYEXPIRED 127 /* Key has expired */
+#define EKEYREVOKED 128 /* Key has been revoked */
+#define EKEYREJECTED 129 /* Key was rejected by service */
+
+/* for robust mutexes */
+#define EOWNERDEAD 130 /* Owner died */
+#define ENOTRECOVERABLE 131 /* State not recoverable */
+
+#define ERFKILL 132 /* Operation not possible due to RF-kill */
+
+#define EHWPOISON 133 /* Memory page has hardware error */
+
+extern int errno;
#ifdef __cplusplus
}
#endif
diff --git a/include/user/user.h b/include/user/user.h
index 0be036b..7af8bdd 100644
--- a/include/user/user.h
+++ b/include/user/user.h
@@ -1,11 +1,47 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (C) 2026 Richard QIn
+ * Copyright (C) 2026 Richard Qin
*/
#pragma once
+
typedef unsigned long long uint64;
-extern "C" {
+#define AT_FDCWD -100
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ // Raw Linux System Calls
+ int sys_openat(int dfd, const char *filename, int flags, int mode);
+ int sys_mknodat(int dfd, const char *filename, int mode, int dev);
+ int sys_mkdirat(int dfd, const char *path, int mode);
+ int sys_unlinkat(int dfd, const char *path, int flags);
+ int sys_linkat(int olddfd, const char *oldpath, int newdfd, const char *newpath, int flags);
+ int sys_chdir(const char *path);
+ int sys_dup(int oldfd);
+ int sys_fstat(int fd, void *statbuf);
+ int sys_read(int fd, void *buf, int count);
+ int sys_write(int fd, const void *buf, int count);
+ int sys_close(int fd);
+ int sys_pipe2(int pipefd[2], int flags);
+ int sys_clone(unsigned long flags, void *stack, int *ptid, void *tls, int *ctid);
+ int sys_execve(const char *path, char *const argv[], char *const envp[]);
+ int sys_wait4(int pid, int *status, int options, void *rusage);
+ int sys_exit(int status);
+ int sys_getpid();
+ int sys_brk(int n);
+ int sys_kill(int pid, int sig);
+ int sys_nanosleep(void *req, void *rem);
+ int sys_reboot(int magic1, int magic2, int cmd, void *arg);
+ int sys_lseek(int fd, int offset, int whence);
+
+ // Custom
+ void sys_putc(char c);
+ int sys_disk_test();
+
+ // POSIX Wrappers
int fork();
int exit(int status);
int wait(uint64 status_addr);
@@ -18,8 +54,8 @@ extern "C" {
int open(const char *, int);
int mknod(const char *, short, short);
int unlink(const char *);
- int fstat(int fd, void *st);
int link(const char *, const char *);
+ int fstat(int fd, void *st);
int mkdir(const char *);
int chdir(const char *);
int dup(int fd);
@@ -28,8 +64,12 @@ extern "C" {
int sleep(int ticks);
int uptime();
int shutdown();
+ int lseek(int fd, int offset, int whence);
// Debug
void putc(char c);
int disk_test();
-} \ No newline at end of file
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file