├── target ├── files │ ├── ab.txt │ ├── hahaverylongname.txt │ ├── untitled.txt │ └── code │ │ ├── fr.c │ │ └── fr.asm ├── usr │ ├── include │ │ ├── bits │ │ │ ├── hwcap.h │ │ │ ├── poll.h │ │ │ ├── socket.h │ │ │ ├── ioctl_fix.h │ │ │ ├── resource.h │ │ │ ├── ipcstat.h │ │ │ ├── kd.h │ │ │ ├── limits.h │ │ │ ├── vt.h │ │ │ ├── link.h │ │ │ ├── mman.h │ │ │ ├── soundcard.h │ │ │ ├── setjmp.h │ │ │ ├── posix.h │ │ │ ├── ipc.h │ │ │ ├── statfs.h │ │ │ ├── dirent.h │ │ │ ├── sem.h │ │ │ ├── msg.h │ │ │ ├── ptrace.h │ │ │ ├── stat.h │ │ │ ├── shm.h │ │ │ ├── float.h │ │ │ ├── stdint.h │ │ │ ├── reg.h │ │ │ ├── fenv.h │ │ │ ├── fcntl.h │ │ │ └── user.h │ │ ├── lastlog.h │ │ ├── memory.h │ │ ├── sys │ │ │ ├── kd.h │ │ │ ├── vt.h │ │ │ ├── stropts.h │ │ │ ├── syslog.h │ │ │ ├── vfs.h │ │ │ ├── ucontext.h │ │ │ ├── soundcard.h │ │ │ ├── dir.h │ │ │ ├── poll.h │ │ │ ├── errno.h │ │ │ ├── fcntl.h │ │ │ ├── signal.h │ │ │ ├── termios.h │ │ │ ├── syscall.h │ │ │ ├── reg.h │ │ │ ├── klog.h │ │ │ ├── user.h │ │ │ ├── auxv.h │ │ │ ├── io.h │ │ │ ├── fsuid.h │ │ │ ├── file.h │ │ │ ├── sendfile.h │ │ │ ├── random.h │ │ │ ├── times.h │ │ │ ├── swap.h │ │ │ ├── cachectl.h │ │ │ ├── reboot.h │ │ │ ├── sysmacros.h │ │ │ ├── timeb.h │ │ │ ├── utsname.h │ │ │ ├── eventfd.h │ │ │ ├── un.h │ │ │ ├── statfs.h │ │ │ ├── timerfd.h │ │ │ ├── membarrier.h │ │ │ ├── sysinfo.h │ │ │ ├── ipc.h │ │ │ ├── param.h │ │ │ ├── ttydefaults.h │ │ │ ├── xattr.h │ │ │ ├── signalfd.h │ │ │ ├── msg.h │ │ │ ├── acct.h │ │ │ ├── procfs.h │ │ │ ├── statvfs.h │ │ │ ├── sem.h │ │ │ ├── select.h │ │ │ ├── uio.h │ │ │ ├── epoll.h │ │ │ ├── inotify.h │ │ │ ├── personality.h │ │ │ ├── wait.h │ │ │ └── shm.h │ │ ├── syscall.h │ │ ├── arpa │ │ │ ├── nameser_compat.h │ │ │ ├── tftp.h │ │ │ ├── inet.h │ │ │ └── ftp.h │ │ ├── wait.h │ │ ├── stdnoreturn.h │ │ ├── netinet │ │ │ ├── in_systm.h │ │ │ ├── ether.h │ │ │ ├── udp.h │ │ │ └── igmp.h │ │ ├── libgen.h │ │ ├── stdbool.h │ │ ├── ulimit.h │ │ ├── alloca.h │ │ ├── iso646.h │ │ ├── crypt.h │ │ ├── scsi │ │ │ └── scsi_ioctl.h │ │ ├── pty.h │ │ ├── stdc-predef.h │ │ ├── nl_types.h │ │ ├── ar.h │ │ ├── stdarg.h │ │ ├── malloc.h │ │ ├── utime.h │ │ ├── errno.h │ │ ├── iconv.h │ │ ├── fnmatch.h │ │ ├── monetary.h │ │ ├── stdalign.h │ │ ├── sysexits.h │ │ ├── assert.h │ │ ├── fenv.h │ │ ├── err.h │ │ ├── ucontext.h │ │ ├── byteswap.h │ │ ├── stddef.h │ │ ├── cpio.h │ │ ├── getopt.h │ │ ├── tar.h │ │ ├── ifaddrs.h │ │ ├── uchar.h │ │ ├── stdio_ext.h │ │ ├── ftw.h │ │ ├── wordexp.h │ │ ├── shadow.h │ │ ├── fmtmsg.h │ │ ├── semaphore.h │ │ ├── dlfcn.h │ │ ├── values.h │ │ ├── libintl.h │ │ ├── mntent.h │ │ ├── paths.h │ │ ├── features.h │ │ ├── pwd.h │ │ ├── glob.h │ │ ├── strings.h │ │ ├── link.h │ │ ├── termios.h │ │ ├── setjmp.h │ │ ├── utmp.h │ │ ├── poll.h │ │ ├── grp.h │ │ ├── mqueue.h │ │ ├── float.h │ │ ├── net │ │ │ └── ethernet.h │ │ ├── regex.h │ │ ├── utmpx.h │ │ ├── search.h │ │ ├── netpacket │ │ │ └── packet.h │ │ └── aio.h │ └── README.txt ├── etc │ ├── ld-musl-x86_64.path │ ├── hosts │ ├── group │ ├── passwd │ ├── resolv.conf │ ├── X11 │ │ └── xorg.conf.d │ │ │ └── 69-cavos.conf │ ├── profile │ └── inputrc ├── lorem.zip ├── fonts │ └── README.txt ├── root │ ├── .xinitrc │ └── .bashrc └── boot │ └── limine │ └── limine.conf ├── src ├── software │ ├── badtest │ │ ├── .gitignore │ │ ├── start.S │ │ └── Makefile │ ├── drawimg │ │ ├── .gitignore │ │ └── Makefile │ └── test │ │ ├── .gitignore │ │ ├── main.c │ │ ├── utils.h │ │ ├── Makefile │ │ └── utils.c ├── kernel │ ├── compile_flags.txt │ ├── include │ │ ├── testing.h │ │ ├── ansi.h │ │ ├── vga.h │ │ ├── caching.h │ │ ├── printf_config.h │ │ ├── schedule.h │ │ ├── sys.h │ │ ├── shell.h │ │ ├── fastSyscall.h │ │ ├── pmm.h │ │ ├── kernel_helper.h │ │ ├── vmm.h │ │ ├── timer.h │ │ ├── acpi.h │ │ ├── proc.h │ │ ├── rtc.h │ │ ├── stack.h │ │ ├── malloc_glue.h │ │ ├── mouse.h │ │ ├── dents.h │ │ ├── idt.h │ │ ├── socket.h │ │ ├── serial.h │ │ ├── kb.h │ │ ├── avl_tree.h │ │ ├── netports.h │ │ ├── psf.h │ │ ├── netqueue.h │ │ ├── string.h │ │ ├── types.h │ │ ├── console.h │ │ ├── disk.h │ │ ├── spinlock.h │ │ ├── rtl8139.h │ │ ├── bootloader.h │ │ ├── ne2k.h │ │ ├── eth.h │ │ ├── rtl8169.h │ │ ├── circular.h │ │ ├── arp.h │ │ ├── linked_list.h │ │ ├── ipv4.h │ │ ├── gdt.h │ │ ├── isr.h │ │ ├── bitmap.h │ │ ├── apic.h │ │ ├── md5.h │ │ └── system.h │ ├── .gitignore │ ├── networking │ │ ├── lwip │ │ │ ├── include │ │ │ │ ├── lwip │ │ │ │ │ └── apps │ │ │ │ │ │ ├── FILES │ │ │ │ │ │ ├── snmp_snmpv2_usm.h │ │ │ │ │ │ └── snmp_snmpv2_framework.h │ │ │ │ ├── netif │ │ │ │ │ ├── etharp.h │ │ │ │ │ └── ppp │ │ │ │ │ │ └── chap-md5.h │ │ │ │ ├── arch │ │ │ │ │ ├── cc.h │ │ │ │ │ └── sys_arch.h │ │ │ │ └── compat │ │ │ │ │ ├── posix │ │ │ │ │ ├── netdb.h │ │ │ │ │ ├── arpa │ │ │ │ │ │ └── inet.h │ │ │ │ │ └── sys │ │ │ │ │ │ └── socket.h │ │ │ │ │ └── stdc │ │ │ │ │ └── errno.h │ │ │ ├── FILES │ │ │ └── netif │ │ │ │ ├── ppp │ │ │ │ └── polarssl │ │ │ │ │ └── README │ │ │ │ └── FILES │ │ ├── socket_v6.c │ │ └── stack │ │ │ └── netqueue.c │ ├── memory │ │ ├── caching.c │ │ └── malloc_glue.c │ ├── cpu │ │ ├── sse.asm │ │ ├── idt.c │ │ └── fastSyscall.c │ ├── filesystems │ │ └── vfs │ │ │ └── vfs_poll.c │ ├── utilities │ │ ├── dents.c │ │ └── fakefs │ │ │ └── null.c │ └── drivers │ │ ├── vga.c │ │ └── serial.c ├── libs │ ├── system │ │ ├── .gitignore │ │ ├── crt0.c │ │ ├── Makefile │ │ ├── system.h │ │ └── main.c │ └── musl │ │ ├── cavos-out │ │ ├── README.txt │ │ └── .gitignore │ │ └── .gitignore └── bootloader │ └── assert.sh ├── .vscode ├── c_cpp_properties.json ├── tasks.json └── settings.json ├── patches ├── bash.diff ├── pkg-config.diff └── patch.diff ├── .github └── workflows │ └── formatting-check.yml ├── tools ├── kernel │ ├── cleanup.sh │ └── uacpi.sh ├── toolchain │ ├── get_formatter.sh │ └── get_autotools.sh ├── shared │ ├── pass_acq.sh │ ├── chroot.sh │ └── cross_compile.sh └── toy │ └── png_to_cavimg.py └── .gitignore /target/files/ab.txt: -------------------------------------------------------------------------------- 1 | abcd -------------------------------------------------------------------------------- /target/usr/include/bits/hwcap.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /target/usr/include/bits/poll.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /target/usr/include/bits/socket.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/software/badtest/.gitignore: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /target/usr/include/bits/ioctl_fix.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /target/usr/include/bits/resource.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/software/drawimg/.gitignore: -------------------------------------------------------------------------------- 1 | drawimg 2 | -------------------------------------------------------------------------------- /src/software/test/.gitignore: -------------------------------------------------------------------------------- 1 | testing 2 | -------------------------------------------------------------------------------- /src/kernel/compile_flags.txt: -------------------------------------------------------------------------------- 1 | -I./include/ 2 | -------------------------------------------------------------------------------- /target/files/hahaverylongname.txt: -------------------------------------------------------------------------------- 1 | Oh, who is she? -------------------------------------------------------------------------------- /target/usr/include/lastlog.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/memory.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/sys/kd.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/sys/vt.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /src/libs/system/.gitignore: -------------------------------------------------------------------------------- 1 | libsystem.a 2 | main.cav 3 | -------------------------------------------------------------------------------- /target/etc/ld-musl-x86_64.path: -------------------------------------------------------------------------------- 1 | /usr/lib 2 | /lib 3 | 4 | -------------------------------------------------------------------------------- /target/usr/README.txt: -------------------------------------------------------------------------------- 1 | Here the musl binaries go... yeah -------------------------------------------------------------------------------- /target/usr/include/bits/ipcstat.h: -------------------------------------------------------------------------------- 1 | #define IPC_STAT 2 2 | -------------------------------------------------------------------------------- /target/usr/include/bits/kd.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/bits/limits.h: -------------------------------------------------------------------------------- 1 | #define PAGESIZE 4096 2 | -------------------------------------------------------------------------------- /target/usr/include/bits/vt.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/sys/stropts.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/sys/syslog.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/sys/vfs.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/syscall.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/etc/hosts: -------------------------------------------------------------------------------- 1 | 127.0.0.1 localhost 2 | ::1 localhost 3 | -------------------------------------------------------------------------------- /target/usr/include/bits/link.h: -------------------------------------------------------------------------------- 1 | typedef uint32_t Elf_Symndx; 2 | -------------------------------------------------------------------------------- /target/usr/include/bits/mman.h: -------------------------------------------------------------------------------- 1 | #define MAP_32BIT 0x40 2 | -------------------------------------------------------------------------------- /target/usr/include/sys/ucontext.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /src/libs/musl/cavos-out/README.txt: -------------------------------------------------------------------------------- 1 | Here the musl binaries go... yeah -------------------------------------------------------------------------------- /target/files/untitled.txt: -------------------------------------------------------------------------------- 1 | Yet another text file with no real purpose! -------------------------------------------------------------------------------- /target/usr/include/bits/soundcard.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /target/usr/include/sys/soundcard.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /src/libs/musl/cavos-out/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !README.txt 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /target/usr/include/bits/setjmp.h: -------------------------------------------------------------------------------- 1 | typedef unsigned long __jmp_buf[8]; 2 | -------------------------------------------------------------------------------- /src/kernel/include/testing.h: -------------------------------------------------------------------------------- 1 | #include "./types.h" 2 | 3 | void testingInit(); -------------------------------------------------------------------------------- /target/usr/include/arpa/nameser_compat.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | -------------------------------------------------------------------------------- /target/usr/include/sys/dir.h: -------------------------------------------------------------------------------- 1 | #include 2 | #define direct dirent 3 | -------------------------------------------------------------------------------- /src/libs/musl/.gitignore: -------------------------------------------------------------------------------- 1 | /cavos-build/ 2 | /musl-*.tar.gz 3 | 4 | /musl-*/ 5 | -------------------------------------------------------------------------------- /src/kernel/include/ansi.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | bool ansiHandle(int charnum); 4 | -------------------------------------------------------------------------------- /target/lorem.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malwarepad/cavOS/HEAD/target/lorem.zip -------------------------------------------------------------------------------- /target/usr/include/bits/posix.h: -------------------------------------------------------------------------------- 1 | #define _POSIX_V6_LP64_OFF64 1 2 | #define _POSIX_V7_LP64_OFF64 1 3 | -------------------------------------------------------------------------------- /target/etc/group: -------------------------------------------------------------------------------- 1 | root:x:0: 2 | 3 | klogd:x:100:klogd 4 | shadow:x:42: 5 | messagebus:x:101:messagebus 6 | -------------------------------------------------------------------------------- /src/software/test/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Hello world!\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /target/files/code/fr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Hello world!\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /target/usr/include/sys/poll.h: -------------------------------------------------------------------------------- 1 | #warning redirecting incorrect #include to 2 | #include 3 | -------------------------------------------------------------------------------- /target/usr/include/wait.h: -------------------------------------------------------------------------------- 1 | #warning redirecting incorrect #include to 2 | #include 3 | -------------------------------------------------------------------------------- /src/kernel/include/vga.h: -------------------------------------------------------------------------------- 1 | #ifndef VGA_H 2 | #define VGA_H 3 | 4 | #include "types.h" 5 | 6 | void initiateVGA(); 7 | 8 | #endif -------------------------------------------------------------------------------- /target/usr/include/sys/errno.h: -------------------------------------------------------------------------------- 1 | #warning redirecting incorrect #include to 2 | #include 3 | -------------------------------------------------------------------------------- /target/usr/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | #warning redirecting incorrect #include to 2 | #include 3 | -------------------------------------------------------------------------------- /target/usr/include/sys/signal.h: -------------------------------------------------------------------------------- 1 | #warning redirecting incorrect #include to 2 | #include 3 | -------------------------------------------------------------------------------- /target/usr/include/sys/termios.h: -------------------------------------------------------------------------------- 1 | #warning redirecting incorrect #include to 2 | #include 3 | -------------------------------------------------------------------------------- /target/usr/include/sys/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SYSCALL_H 2 | #define _SYS_SYSCALL_H 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/kernel/include/caching.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef CACHING_H 4 | #define CACHING_H 5 | 6 | size_t cachingInfoBlocks(); 7 | 8 | #endif -------------------------------------------------------------------------------- /src/software/test/utils.h: -------------------------------------------------------------------------------- 1 | #include 2 | uint16_t strlength(char *ch); 3 | int atoi(char *str); 4 | void itoa(int n, char s[]); -------------------------------------------------------------------------------- /target/etc/passwd: -------------------------------------------------------------------------------- 1 | root:x:0:0:root:/root:/bin/bash 2 | klogd:x:100:100:klogd:/dev/null:/sbin/nologin 3 | messagebus:x:101:101:messagebus:/dev/null:/sbin/nologin 4 | -------------------------------------------------------------------------------- /src/kernel/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | 3 | # NOTE TO SELF! EXTREMELY IMPORTANT! 4 | # When adding stuff here DO NOT FORGET "make format" 5 | acpi/uacpi/ 6 | include/uacpi/ 7 | -------------------------------------------------------------------------------- /src/kernel/include/printf_config.h: -------------------------------------------------------------------------------- 1 | #define PRINTF_SUPPORT_DECIMAL_SPECIFIERS 0 2 | #define PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS 0 3 | #define PRINTF_SUPPORT_LONG_LONG 0 -------------------------------------------------------------------------------- /target/fonts/README.txt: -------------------------------------------------------------------------------- 1 | When booted, cavOS will try to load the embedded "gohufont" 2 | font. Unless a file on this directory exists by the name of: 3 | "u_custom.psf" -------------------------------------------------------------------------------- /target/usr/include/sys/reg.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_REG_H 2 | #define _SYS_REG_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/kernel/include/schedule.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef SCHEDULE_H 4 | #define SCHEDULE_H 5 | 6 | uint64_t rsp_fix(uint64_t rsp); 7 | void schedule(uint64_t rsp); 8 | 9 | #endif -------------------------------------------------------------------------------- /target/usr/include/stdnoreturn.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDNORETURN_H 2 | #define _STDNORETURN_H 3 | #ifndef __cplusplus 4 | #include 5 | #define noreturn _Noreturn 6 | #endif 7 | #endif 8 | -------------------------------------------------------------------------------- /src/kernel/include/sys.h: -------------------------------------------------------------------------------- 1 | #include "fakefs.h" 2 | #include "types.h" 3 | #include "vfs.h" 4 | 5 | #ifndef SYS_H 6 | #define SYS_H 7 | 8 | bool sysMount(MountPoint *mount); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/lwip/apps/FILES: -------------------------------------------------------------------------------- 1 | This directory contains application headers. 2 | Every application shall provide one api file APP.h and optionally one options file APP_opts.h 3 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/netif/etharp.h: -------------------------------------------------------------------------------- 1 | /* ARP has been moved to core/ipv4, provide this #include for compatibility only */ 2 | #include "lwip/etharp.h" 3 | #include "netif/ethernet.h" 4 | -------------------------------------------------------------------------------- /src/kernel/include/shell.h: -------------------------------------------------------------------------------- 1 | #ifndef SHELL_H 2 | #define SHELL_H 3 | #include "types.h" 4 | 5 | void launch_shell(int n); 6 | bool run(char *binary, bool wait, int _argc, char **_argv); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/kernel/include/fastSyscall.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef FAST_SYSCALL_H 4 | #define FAST_SYSCALL_H 5 | 6 | void initiateSyscallInst(); 7 | 8 | extern void syscall_entry(); 9 | 10 | #endif -------------------------------------------------------------------------------- /target/etc/resolv.conf: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by the cavOS bootstrapping script ports.sh. In order to stop that, you will have to modify it yourself. 2 | nameserver 1.1.1.1 3 | nameserver 1.0.0.1 4 | -------------------------------------------------------------------------------- /src/software/badtest/start.S: -------------------------------------------------------------------------------- 1 | /* I truly do hate AT&T assembly... */ 2 | 3 | .text 4 | .p2align 2 5 | .globl _start 6 | _start: 7 | /*popq %rdi*/ 8 | mov %rsp, %rdi 9 | call _start_c 10 | .size _start,.-_start -------------------------------------------------------------------------------- /target/usr/include/netinet/in_systm.h: -------------------------------------------------------------------------------- 1 | #ifndef _NETINET_IN_SYSTM_H 2 | #define _NETINET_IN_SYSTM_H 3 | 4 | #include 5 | 6 | typedef uint16_t n_short; 7 | typedef uint32_t n_long, n_time; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/arch/cc.h: -------------------------------------------------------------------------------- 1 | // a bunch of messy includes 2 | 3 | #include "linux.h" 4 | #include "malloc.h" 5 | #include "memory.h" 6 | #include "system.h" 7 | #include "task.h" 8 | #include "types.h" 9 | #include "util.h" -------------------------------------------------------------------------------- /target/usr/include/bits/ipc.h: -------------------------------------------------------------------------------- 1 | struct ipc_perm { 2 | key_t __ipc_perm_key; 3 | uid_t uid; 4 | gid_t gid; 5 | uid_t cuid; 6 | gid_t cgid; 7 | mode_t mode; 8 | int __ipc_perm_seq; 9 | long __pad1; 10 | long __pad2; 11 | }; 12 | -------------------------------------------------------------------------------- /target/usr/include/sys/klog.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_KLOG_H 2 | #define _SYS_KLOG_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int klogctl (int, char *, int); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /target/usr/include/bits/statfs.h: -------------------------------------------------------------------------------- 1 | struct statfs { 2 | unsigned long f_type, f_bsize; 3 | fsblkcnt_t f_blocks, f_bfree, f_bavail; 4 | fsfilcnt_t f_files, f_ffree; 5 | fsid_t f_fsid; 6 | unsigned long f_namelen, f_frsize, f_flags, f_spare[4]; 7 | }; 8 | -------------------------------------------------------------------------------- /target/usr/include/libgen.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBGEN_H 2 | #define _LIBGEN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | char *dirname(char *); 9 | char *basename(char *); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /target/usr/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | #ifndef __cplusplus 5 | 6 | #define true 1 7 | #define false 0 8 | #define bool _Bool 9 | 10 | #endif 11 | 12 | #define __bool_true_false_are_defined 1 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/src/kernel/include/" 7 | ] 8 | } 9 | ], 10 | "version": 4 11 | } -------------------------------------------------------------------------------- /target/usr/include/bits/dirent.h: -------------------------------------------------------------------------------- 1 | #define _DIRENT_HAVE_D_RECLEN 2 | #define _DIRENT_HAVE_D_OFF 3 | #define _DIRENT_HAVE_D_TYPE 4 | 5 | struct dirent { 6 | ino_t d_ino; 7 | off_t d_off; 8 | unsigned short d_reclen; 9 | unsigned char d_type; 10 | char d_name[256]; 11 | }; 12 | -------------------------------------------------------------------------------- /src/kernel/include/pmm.h: -------------------------------------------------------------------------------- 1 | #ifndef PMM_H 2 | #define PMM_H 3 | 4 | #include "bitmap.h" 5 | #include "types.h" 6 | 7 | DS_Bitmap physical; 8 | 9 | void initiatePMM(); 10 | 11 | size_t PhysicalAllocate(int pages); 12 | void PhysicalFree(size_t ptr, int pages); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /target/usr/include/ulimit.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULIMIT_H 2 | #define _ULIMIT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define UL_GETFSIZE 1 9 | #define UL_SETFSIZE 2 10 | 11 | long ulimit (int, ...); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /target/usr/include/sys/user.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_USER_H 2 | #define _SYS_USER_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /target/usr/include/bits/sem.h: -------------------------------------------------------------------------------- 1 | struct semid_ds { 2 | struct ipc_perm sem_perm; 3 | time_t sem_otime; 4 | long __unused1; 5 | time_t sem_ctime; 6 | long __unused2; 7 | unsigned short sem_nsems; 8 | char __sem_nsems_pad[sizeof(long)-sizeof(short)]; 9 | long __unused3; 10 | long __unused4; 11 | }; 12 | -------------------------------------------------------------------------------- /target/usr/include/sys/auxv.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_AUXV_H 2 | #define _SYS_AUXV_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | unsigned long getauxval(unsigned long); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/kernel/include/kernel_helper.h: -------------------------------------------------------------------------------- 1 | #include "task.h" 2 | #include "types.h" 3 | 4 | #ifndef KERNEL_HELPER_H 5 | #define KERNEL_HELPER_H 6 | 7 | Task *netHelperTask; 8 | void kernelHelpEntry(); 9 | 10 | Spinlock LOCK_REAPER; 11 | Task *reaperTask; 12 | 13 | void initiateKernelThreads(); 14 | 15 | #endif -------------------------------------------------------------------------------- /target/usr/include/bits/msg.h: -------------------------------------------------------------------------------- 1 | struct msqid_ds { 2 | struct ipc_perm msg_perm; 3 | time_t msg_stime; 4 | time_t msg_rtime; 5 | time_t msg_ctime; 6 | unsigned long msg_cbytes; 7 | msgqnum_t msg_qnum; 8 | msglen_t msg_qbytes; 9 | pid_t msg_lspid; 10 | pid_t msg_lrpid; 11 | unsigned long __unused[2]; 12 | }; 13 | -------------------------------------------------------------------------------- /target/usr/include/sys/io.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_IO_H 2 | #define _SYS_IO_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #include 10 | 11 | int iopl(int); 12 | int ioperm(unsigned long, unsigned long, int); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | #endif 18 | -------------------------------------------------------------------------------- /src/libs/system/crt0.c: -------------------------------------------------------------------------------- 1 | extern int main(int argc, char *argv[]); 2 | 3 | void _start() { 4 | int argc = syscallGetArgc(); 5 | char *argv[argc]; 6 | 7 | for (int i = 0; i < argc; i++) { 8 | argv[i] = syscallGetArgv(i); 9 | } 10 | 11 | int returnCode = main(argc, argv); 12 | syscallExitTask(returnCode); 13 | } -------------------------------------------------------------------------------- /target/root/.xinitrc: -------------------------------------------------------------------------------- 1 | xsetroot -solid "#006666" & 2 | #xeyes & 3 | #feh /1.jpg & 4 | #nedit & 5 | #xclock -update 1 & 6 | #st & 7 | #links -g & 8 | #links -g https://ash-speed.hetzner.com/ & 9 | #ClassiCube > /dev/null & 10 | #doom -iwad doom.wad & 11 | st & 12 | #hexchat & 13 | #pcmanfm > /dev/null 2>/dev/null & 14 | twm 15 | -------------------------------------------------------------------------------- /src/kernel/include/vmm.h: -------------------------------------------------------------------------------- 1 | #include "bitmap.h" 2 | #include "types.h" 3 | 4 | #ifndef VMM_H 5 | #define VMM_H 6 | 7 | DS_Bitmap virtual; 8 | 9 | void initiateVMM(); 10 | 11 | void *VirtualAllocate(int pages); 12 | void *VirtualAllocatePhysicallyContiguous(int pages); 13 | bool VirtualFree(void *ptr, int pages); 14 | 15 | #endif -------------------------------------------------------------------------------- /target/usr/include/alloca.h: -------------------------------------------------------------------------------- 1 | #ifndef _ALLOCA_H 2 | #define _ALLOCA_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __NEED_size_t 9 | #include 10 | 11 | void *alloca(size_t); 12 | 13 | #define alloca __builtin_alloca 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | /* Accessible with Control + Shift + b (for the default task) */ 2 | 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "dev", 8 | "type": "shell", 9 | "command": "make dev", 10 | "problemMatcher": [], 11 | "group": { "kind": "build", "isDefault": true } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /target/usr/include/sys/fsuid.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_FSUID_H 2 | #define _SYS_FSUID_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __NEED_uid_t 9 | #define __NEED_gid_t 10 | 11 | #include 12 | 13 | int setfsuid(uid_t); 14 | int setfsgid(gid_t); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/kernel/memory/caching.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void cachingInfoCb(void *data, void *ctx) { 6 | MountPoint *fs = data; 7 | *(size_t *)ctx += fs->blocksCached; 8 | } 9 | 10 | size_t cachingInfoBlocks() { 11 | size_t ret = 0; 12 | LinkedListTraverse(&dsMountPoint, cachingInfoCb, &ret); 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /src/kernel/include/timer.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #define TIMER_ACCURANCY 1193182 4 | 5 | #ifndef TIMER_H 6 | #define TIMER_H 7 | 8 | uint32_t timerFrequency; 9 | uint64_t timerTicks; 10 | uint64_t timerBootUnix; 11 | 12 | uint64_t apicFreq; 13 | 14 | void timerTick(uint64_t rsp); 15 | uint32_t sleep(uint32_t time); 16 | void initiateApicTimer(); 17 | 18 | #endif -------------------------------------------------------------------------------- /src/kernel/cpu/sse.asm: -------------------------------------------------------------------------------- 1 | bits 64 2 | 3 | global asm_enable_SSE 4 | asm_enable_SSE: 5 | ;now enable SSE and the like 6 | mov rax, cr0 7 | and ax, 0xFFFB ;clear coprocessor emulation CR0.EM 8 | or ax, 0x2 ;set coprocessor monitoring CR0.MP 9 | mov cr0, rax 10 | mov rax, cr4 11 | or ax, 3 << 9 ;set CR4.OSFXSR and CR4.OSXMMEXCPT at the same time 12 | mov cr4, rax 13 | ret 14 | -------------------------------------------------------------------------------- /target/usr/include/iso646.h: -------------------------------------------------------------------------------- 1 | #ifndef _ISO646_H 2 | #define _ISO646_H 3 | 4 | #ifndef __cplusplus 5 | 6 | #define and && 7 | #define and_eq &= 8 | #define bitand & 9 | #define bitor | 10 | #define compl ~ 11 | #define not ! 12 | #define not_eq != 13 | #define or || 14 | #define or_eq |= 15 | #define xor ^ 16 | #define xor_eq ^= 17 | 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /target/usr/include/sys/file.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_FILE_H 2 | #define _SYS_FILE_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define LOCK_SH 1 8 | #define LOCK_EX 2 9 | #define LOCK_NB 4 10 | #define LOCK_UN 8 11 | 12 | #define L_SET 0 13 | #define L_INCR 1 14 | #define L_XTND 2 15 | 16 | int flock(int, int); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /src/kernel/include/acpi.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #include "uacpi/acpi.h" 4 | #include "uacpi/resources.h" 5 | #include "uacpi/tables.h" 6 | #include "uacpi/uacpi.h" 7 | #include "uacpi/utilities.h" 8 | 9 | #ifndef ACPI_H 10 | #define ACPI_H 11 | 12 | struct acpi_madt *madt; 13 | 14 | void initiateACPI(); 15 | 16 | size_t acpiPoweroff(); 17 | size_t acpiReboot(); 18 | 19 | #endif -------------------------------------------------------------------------------- /target/usr/include/crypt.h: -------------------------------------------------------------------------------- 1 | #ifndef _CRYPT_H 2 | #define _CRYPT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | struct crypt_data { 9 | int initialized; 10 | char __buf[256]; 11 | }; 12 | 13 | char *crypt(const char *, const char *); 14 | char *crypt_r(const char *, const char *, struct crypt_data *); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/software/drawimg/Makefile: -------------------------------------------------------------------------------- 1 | COMPILER = ~/opt/cross/bin/x86_64-cavos-gcc 2 | CFLAGS = -std=gnu99 -Wall -Wextra -static 3 | OUTPUT = drawimg 4 | TARGET = ../../../target/usr/bin/ 5 | 6 | all: clean compile install 7 | 8 | compile: 9 | $(COMPILER) main.c -o $(OUTPUT) $(CFLAGS) 10 | 11 | install: 12 | mkdir -p $(TARGET) 13 | sudo cp $(OUTPUT) $(TARGET) 14 | 15 | clean: 16 | rm -f $(OUTPUT) 17 | -------------------------------------------------------------------------------- /src/software/test/Makefile: -------------------------------------------------------------------------------- 1 | COMPILER = ~/opt/cross/bin/x86_64-cavos-gcc 2 | CFLAGS = -std=gnu99 -Wall -Wextra -static 3 | OUTPUT = testing 4 | TARGET = ../../../target/usr/bin/ 5 | 6 | all: clean compile install 7 | 8 | compile: 9 | $(COMPILER) main.c utils.c -o $(OUTPUT) $(CFLAGS) 10 | 11 | install: 12 | mkdir -p $(TARGET) 13 | sudo cp $(OUTPUT) $(TARGET) 14 | 15 | clean: 16 | rm -f $(OUTPUT) 17 | -------------------------------------------------------------------------------- /target/usr/include/scsi/scsi_ioctl.h: -------------------------------------------------------------------------------- 1 | #ifndef _SCSI_IOCTL_H 2 | #define _SCSI_IOCTL_H 3 | #define SCSI_IOCTL_SEND_COMMAND 1 4 | #define SCSI_IOCTL_TEST_UNIT_READY 2 5 | #define SCSI_IOCTL_BENCHMARK_COMMAND 3 6 | #define SCSI_IOCTL_SYNC 4 7 | #define SCSI_IOCTL_START_UNIT 5 8 | #define SCSI_IOCTL_STOP_UNIT 6 9 | #define SCSI_IOCTL_DOORLOCK 0x5380 10 | #define SCSI_IOCTL_DOORUNLOCK 0x5381 11 | #endif 12 | -------------------------------------------------------------------------------- /patches/bash.diff: -------------------------------------------------------------------------------- 1 | diff --git a/m4/strtoimax.m4 b/m4/strtoimax.m4 2 | index 3098572..d311c9d 100644 3 | --- a/m4/strtoimax.m4 4 | +++ b/m4/strtoimax.m4 5 | @@ -29,7 +29,7 @@ AC_CACHE_VAL(bash_cv_func_strtoimax, 6 | fi 7 | ]) 8 | AC_MSG_RESULT($bash_cv_func_strtoimax) 9 | -if test $bash_cv_func_strtoimax = yes; then 10 | +if test $bash_cv_func_strtoimax = no; then 11 | AC_LIBOBJ(strtoimax) 12 | fi 13 | ]) 14 | -------------------------------------------------------------------------------- /target/usr/include/pty.h: -------------------------------------------------------------------------------- 1 | #ifndef _PTY_H 2 | #define _PTY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | int openpty(int *, int *, char *, const struct termios *, const struct winsize *); 12 | int forkpty(int *, char *, const struct termios *, const struct winsize *); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /target/usr/include/stdc-predef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDC_PREDEF_H 2 | #define _STDC_PREDEF_H 3 | 4 | #define __STDC_ISO_10646__ 201206L 5 | 6 | #if !defined(__GCC_IEC_559) || __GCC_IEC_559 > 0 7 | #define __STDC_IEC_559__ 1 8 | #endif 9 | 10 | #if !defined(__STDC_UTF_16__) 11 | #define __STDC_UTF_16__ 1 12 | #endif 13 | 14 | #if !defined(__STDC_UTF_32__) 15 | #define __STDC_UTF_32__ 1 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/software/badtest/Makefile: -------------------------------------------------------------------------------- 1 | COMPILER = ~/opt/cross/bin/x86_64-cavos-gcc 2 | CFLAGS = -std=gnu99 -w -ffreestanding -nostartfiles -nostdlib 3 | OUTPUT = a 4 | TARGET = ../../../target/usr/bin/ 5 | 6 | all: clean compile install 7 | 8 | compile: 9 | $(COMPILER) badtest.c start.S -o $(OUTPUT) $(CFLAGS) 10 | 11 | install: 12 | mkdir -p $(TARGET) 13 | sudo cp $(OUTPUT) $(TARGET) 14 | 15 | clean: 16 | rm -f $(OUTPUT) 17 | -------------------------------------------------------------------------------- /src/kernel/include/proc.h: -------------------------------------------------------------------------------- 1 | #include "fakefs.h" 2 | #include "types.h" 3 | #include "vfs.h" 4 | 5 | #ifndef PROC_H 6 | #define PROC_H 7 | 8 | bool procMount(MountPoint *mount); 9 | 10 | size_t procEachOpen(char *filename, int flags, int mode, OpenFile *fd, 11 | char **symlinkResolve); 12 | bool procEachDuplicate(OpenFile *original, OpenFile *orphan); 13 | bool procEachClose(OpenFile *fd); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /target/usr/include/sys/sendfile.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SENDFILE_H 2 | #define _SYS_SENDFILE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | ssize_t sendfile(int, int, off_t *, size_t); 12 | 13 | #if defined(_LARGEFILE64_SOURCE) 14 | #define sendfile64 sendfile 15 | #define off64_t off_t 16 | #endif 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /target/usr/include/nl_types.h: -------------------------------------------------------------------------------- 1 | #ifndef _NL_TYPES_H 2 | #define _NL_TYPES_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define NL_SETD 1 9 | #define NL_CAT_LOCALE 1 10 | 11 | typedef int nl_item; 12 | typedef void *nl_catd; 13 | 14 | nl_catd catopen (const char *, int); 15 | char *catgets (nl_catd, int, int, const char *); 16 | int catclose (nl_catd); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /target/usr/include/sys/random.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_RANDOM_H 2 | #define _SYS_RANDOM_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define __NEED_size_t 8 | #define __NEED_ssize_t 9 | #include 10 | 11 | #define GRND_NONBLOCK 0x0001 12 | #define GRND_RANDOM 0x0002 13 | #define GRND_INSECURE 0x0004 14 | 15 | ssize_t getrandom(void *, size_t, unsigned); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /target/usr/include/sys/times.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TIMES_H 2 | #define _SYS_TIMES_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __NEED_clock_t 9 | #include 10 | 11 | struct tms { 12 | clock_t tms_utime; 13 | clock_t tms_stime; 14 | clock_t tms_cutime; 15 | clock_t tms_cstime; 16 | }; 17 | 18 | clock_t times (struct tms *); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /target/usr/include/ar.h: -------------------------------------------------------------------------------- 1 | #ifndef _AR_H 2 | #define _AR_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define ARMAG "!\n" 9 | #define SARMAG 8 10 | #define ARFMAG "`\n" 11 | 12 | struct ar_hdr { 13 | char ar_name[16]; 14 | char ar_date[12]; 15 | char ar_uid[6], ar_gid[6]; 16 | char ar_mode[8]; 17 | char ar_size[10]; 18 | char ar_fmag[2]; 19 | }; 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/kernel/include/rtc.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef RTC_H 4 | #define RTC_H 5 | 6 | typedef struct { 7 | unsigned char second; 8 | unsigned char minute; 9 | unsigned char hour; 10 | unsigned char day; 11 | unsigned char month; 12 | unsigned int year; 13 | } RTC; 14 | 15 | int readFromCMOS(RTC *rtc); 16 | uint64_t rtcToUnix(RTC *rtc); 17 | bool isLeapYear(int year); 18 | 19 | int century_register; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /target/usr/include/sys/swap.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SWAP_H 2 | #define _SYS_SWAP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | #define SWAP_FLAG_PREFER 0x8000 10 | #define SWAP_FLAG_PRIO_MASK 0x7fff 11 | #define SWAP_FLAG_PRIO_SHIFT 0 12 | #define SWAP_FLAG_DISCARD 0x10000 13 | 14 | int swapon (const char *, int); 15 | int swapoff (const char *); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/kernel/include/stack.h: -------------------------------------------------------------------------------- 1 | #include "task.h" 2 | #include "types.h" 3 | 4 | #ifndef STACK_H 5 | #define STACK_H 6 | 7 | void stackGenerateUser(Task *target, uint32_t argc, char **argv, uint32_t envc, 8 | char **envv, uint8_t *out, size_t filesize, 9 | void *elf_ehdr_ptr, size_t at_base, 10 | size_t executableBase); 11 | void stackGenerateKernel(Task *target, uint64_t parameter); 12 | 13 | #endif -------------------------------------------------------------------------------- /src/kernel/include/malloc_glue.h: -------------------------------------------------------------------------------- 1 | #include "system.h" 2 | #include "types.h" 3 | #include "util.h" 4 | 5 | #ifndef MALLOC_GLUE_H 6 | #define MALLOC_GLUE_H 7 | 8 | // malloc.c provides it's own headers for a lot of stuff apparently! 9 | 10 | // spinlocks 11 | typedef Spinlock MLOCK_T; 12 | 13 | MLOCK_T malloc_global_mutex; 14 | int ACQUIRE_LOCK(Spinlock *lock); 15 | int RELEASE_LOCK(Spinlock *lock); 16 | int INITIAL_LOCK(Spinlock *lock); 17 | 18 | #endif -------------------------------------------------------------------------------- /src/kernel/include/mouse.h: -------------------------------------------------------------------------------- 1 | #include "dev.h" 2 | #include "types.h" 3 | 4 | #ifndef MOUSE_H 5 | #define MOUSE_H 6 | 7 | #define MOUSE_PORT 0x60 8 | #define MOUSE_STATUS 0x64 9 | #define MOUSE_ABIT 0x02 10 | #define MOUSE_BBIT 0x01 11 | #define MOUSE_WRITE 0xD4 12 | #define MOUSE_F_BIT 0x20 13 | #define MOUSE_V_BIT 0x08 14 | 15 | #define MOUSE_TIMEOUT 100000 16 | 17 | void initiateMouse(); 18 | void mouseIrq(); 19 | 20 | DevInputEvent *mouseEvent; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/libs/system/Makefile: -------------------------------------------------------------------------------- 1 | COMPILER = ~/opt/cross/bin/i686-cavos-gcc 2 | ARCHIVER = ~/opt/cross/bin/i686-cavos-ar 3 | CFLAGS = -std=gnu99 -ffreestanding -Wall -Wextra -fno-builtin -nostartfiles -nostdlib -c -fpic 4 | 5 | BIN_OUTPUT = main.cav 6 | LIB_OUTPUT = libsystem.a 7 | 8 | all: clean compile 9 | 10 | compile: 11 | $(COMPILER) $(CFLAGS) -o $(BIN_OUTPUT) main.c 12 | $(ARCHIVER) rcs $(LIB_OUTPUT) $(BIN_OUTPUT) 13 | 14 | clean: 15 | rm -f $(LIB_OUTPUT) $(BIN_OUTPUT) -------------------------------------------------------------------------------- /target/usr/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __NEED_va_list 9 | 10 | #include 11 | 12 | #define va_start(v,l) __builtin_va_start(v,l) 13 | #define va_end(v) __builtin_va_end(v) 14 | #define va_arg(v,l) __builtin_va_arg(v,l) 15 | #define va_copy(d,s) __builtin_va_copy(d,s) 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /.github/workflows/formatting-check.yml: -------------------------------------------------------------------------------- 1 | name: Formatting check 2 | 3 | on: 4 | pull_request: 5 | branches: ["*"] 6 | 7 | jobs: 8 | formatting-check: 9 | name: Run code formatting checks 10 | runs-on: ubuntu-latest 11 | permissions: 12 | contents: read 13 | actions: read 14 | steps: 15 | - name: Checkout repository 16 | uses: actions/checkout@v4 17 | 18 | - name: Check formatting 19 | run: make format_check 20 | -------------------------------------------------------------------------------- /target/usr/include/sys/cachectl.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_CACHECTL_H 2 | #define _SYS_CACHECTL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define ICACHE (1<<0) 9 | #define DCACHE (1<<1) 10 | #define BCACHE (ICACHE|DCACHE) 11 | #define CACHEABLE 0 12 | #define UNCACHEABLE 1 13 | 14 | int cachectl(void *, int, int); 15 | int cacheflush(void *, int, int); 16 | int _flush_cache(void *, int, int); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /target/files/code/fr.asm: -------------------------------------------------------------------------------- 1 | global _start 2 | 3 | section .text 4 | 5 | _start: 6 | mov rax, 1 ; write( 7 | mov rdi, 1 ; STDOUT_FILENO, 8 | mov rsi, msg ; "Hello, world!\n", 9 | mov rdx, msglen ; sizeof("Hello, world!\n") 10 | syscall ; ); 11 | 12 | mov rax, 60 ; exit( 13 | mov rdi, 0 ; EXIT_SUCCESS 14 | syscall ; ); 15 | 16 | section .rodata 17 | msg: db "Hello, world!", 10 18 | msglen: equ $ - msg 19 | -------------------------------------------------------------------------------- /target/usr/include/sys/reboot.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_REBOOT_H 2 | #define _SYS_REBOOT_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define RB_AUTOBOOT 0x01234567 8 | #define RB_HALT_SYSTEM 0xcdef0123 9 | #define RB_ENABLE_CAD 0x89abcdef 10 | #define RB_DISABLE_CAD 0 11 | #define RB_POWER_OFF 0x4321fedc 12 | #define RB_SW_SUSPEND 0xd000fce2 13 | #define RB_KEXEC 0x45584543 14 | 15 | int reboot(int); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /target/usr/include/sys/sysmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SYSMACROS_H 2 | #define _SYS_SYSMACROS_H 3 | 4 | #define major(x) \ 5 | ((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) )) 6 | #define minor(x) \ 7 | ((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) )) 8 | 9 | #define makedev(x,y) ( \ 10 | (((x)&0xfffff000ULL) << 32) | \ 11 | (((x)&0x00000fffULL) << 8) | \ 12 | (((y)&0xffffff00ULL) << 12) | \ 13 | (((y)&0x000000ffULL)) ) 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /target/usr/include/malloc.h: -------------------------------------------------------------------------------- 1 | #ifndef _MALLOC_H 2 | #define _MALLOC_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __NEED_size_t 9 | 10 | #include 11 | 12 | void *malloc (size_t); 13 | void *calloc (size_t, size_t); 14 | void *realloc (void *, size_t); 15 | void free (void *); 16 | void *valloc (size_t); 17 | void *memalign(size_t, size_t); 18 | 19 | size_t malloc_usable_size(void *); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /target/usr/include/utime.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIME_H 2 | #define _UTIME_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_time_t 11 | 12 | #include 13 | 14 | struct utimbuf { 15 | time_t actime; 16 | time_t modtime; 17 | }; 18 | 19 | int utime (const char *, const struct utimbuf *); 20 | 21 | #if _REDIR_TIME64 22 | __REDIR(utime, __utime64); 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/kernel/include/dents.h: -------------------------------------------------------------------------------- 1 | #include "linux.h" 2 | #include "types.h" 3 | 4 | #ifndef DENTS_H 5 | #define DENTS_H 6 | 7 | typedef enum { 8 | DENTS_NO_SPACE = 0, 9 | DENTS_SUCCESS = 1, 10 | DENTS_RETURN = 2, 11 | } DENTS_RES; 12 | 13 | DENTS_RES dentsAdd(void *buffStart, struct linux_dirent64 **dirp, 14 | size_t *allocatedlimit, unsigned int hardlimit, 15 | char *filename, size_t filenameLength, size_t inode, 16 | unsigned char type); 17 | 18 | #endif -------------------------------------------------------------------------------- /target/boot/limine/limine.conf: -------------------------------------------------------------------------------- 1 | # Timeout in seconds that Limine will use before automatically booting. 2 | timeout: 0 3 | 4 | # The entry name that will be displayed in the boot menu. 5 | /cavOS 6 | # We use the Limine boot protocol. 7 | protocol: limine 8 | 9 | # Disable KASLR (it is enabled by default for relocatable kernels) 10 | kaslr: yes 11 | 12 | # Path to the kernel to boot. boot():/ represents the partition on which limine.conf is located. 13 | kernel_path: boot():/kernel.bin -------------------------------------------------------------------------------- /target/usr/include/sys/timeb.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TIMEB_H 2 | #define _SYS_TIMEB_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #define __NEED_time_t 10 | 11 | #include 12 | 13 | struct timeb { 14 | time_t time; 15 | unsigned short millitm; 16 | short timezone, dstflag; 17 | }; 18 | 19 | int ftime(struct timeb *); 20 | 21 | #if _REDIR_TIME64 22 | __REDIR(ftime, __ftime64); 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /target/usr/include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERRNO_H 2 | #define _ERRNO_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #include 11 | 12 | #ifdef __GNUC__ 13 | __attribute__((const)) 14 | #endif 15 | int *__errno_location(void); 16 | #define errno (*__errno_location()) 17 | 18 | #ifdef _GNU_SOURCE 19 | extern char *program_invocation_short_name, *program_invocation_name; 20 | #endif 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /target/usr/include/iconv.h: -------------------------------------------------------------------------------- 1 | #ifndef _ICONV_H 2 | #define _ICONV_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | 12 | #include 13 | 14 | typedef void *iconv_t; 15 | 16 | iconv_t iconv_open(const char *, const char *); 17 | size_t iconv(iconv_t, char **__restrict, size_t *__restrict, char **__restrict, size_t *__restrict); 18 | int iconv_close(iconv_t); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /target/usr/include/fnmatch.h: -------------------------------------------------------------------------------- 1 | #ifndef _FNMATCH_H 2 | #define _FNMATCH_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define FNM_PATHNAME 0x1 9 | #define FNM_NOESCAPE 0x2 10 | #define FNM_PERIOD 0x4 11 | #define FNM_LEADING_DIR 0x8 12 | #define FNM_CASEFOLD 0x10 13 | #define FNM_FILE_NAME FNM_PATHNAME 14 | 15 | #define FNM_NOMATCH 1 16 | #define FNM_NOSYS (-1) 17 | 18 | int fnmatch(const char *, const char *, int); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /target/usr/include/monetary.h: -------------------------------------------------------------------------------- 1 | #ifndef _MONETARY_H 2 | #define _MONETARY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_ssize_t 11 | #define __NEED_size_t 12 | #define __NEED_locale_t 13 | 14 | #include 15 | 16 | ssize_t strfmon(char *__restrict, size_t, const char *__restrict, ...); 17 | ssize_t strfmon_l(char *__restrict, size_t, locale_t, const char *__restrict, ...); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /target/usr/include/stdalign.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDALIGN_H 2 | #define _STDALIGN_H 3 | 4 | #ifndef __cplusplus 5 | 6 | /* this whole header only works in C11 or with compiler extensions */ 7 | #if __STDC_VERSION__ < 201112L && defined( __GNUC__) 8 | #define _Alignas(t) __attribute__((__aligned__(t))) 9 | #define _Alignof(t) __alignof__(t) 10 | #endif 11 | 12 | #define alignas _Alignas 13 | #define alignof _Alignof 14 | 15 | #endif 16 | 17 | #define __alignas_is_defined 1 18 | #define __alignof_is_defined 1 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /target/usr/include/sys/utsname.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_UTSNAME_H 2 | #define _SYS_UTSNAME_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | struct utsname { 11 | char sysname[65]; 12 | char nodename[65]; 13 | char release[65]; 14 | char version[65]; 15 | char machine[65]; 16 | #ifdef _GNU_SOURCE 17 | char domainname[65]; 18 | #else 19 | char __domainname[65]; 20 | #endif 21 | }; 22 | 23 | int uname (struct utsname *); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /target/usr/include/bits/ptrace.h: -------------------------------------------------------------------------------- 1 | #define PTRACE_GET_THREAD_AREA 25 2 | #define PTRACE_SET_THREAD_AREA 26 3 | #define PTRACE_ARCH_PRCTL 30 4 | #define PTRACE_SYSEMU 31 5 | #define PTRACE_SYSEMU_SINGLESTEP 32 6 | #define PTRACE_SINGLEBLOCK 33 7 | 8 | #define PT_GET_THREAD_AREA PTRACE_GET_THREAD_AREA 9 | #define PT_SET_THREAD_AREA PTRACE_SET_THREAD_AREA 10 | #define PT_ARCH_PRCTL PTRACE_ARCH_PRCTL 11 | #define PT_SYSEMU PTRACE_SYSEMU 12 | #define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP 13 | #define PT_STEPBLOCK PTRACE_SINGLEBLOCK 14 | -------------------------------------------------------------------------------- /target/usr/include/sys/eventfd.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_EVENTFD_H 2 | #define _SYS_EVENTFD_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | typedef uint64_t eventfd_t; 12 | 13 | #define EFD_SEMAPHORE 1 14 | #define EFD_CLOEXEC O_CLOEXEC 15 | #define EFD_NONBLOCK O_NONBLOCK 16 | 17 | int eventfd(unsigned int, int); 18 | int eventfd_read(int, eventfd_t *); 19 | int eventfd_write(int, eventfd_t); 20 | 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* sys/eventfd.h */ 27 | -------------------------------------------------------------------------------- /target/usr/include/sysexits.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSEXITS_H 2 | #define _SYSEXITS_H 3 | #define EX_OK 0 4 | #define EX__BASE 64 5 | #define EX_USAGE 64 6 | #define EX_DATAERR 65 7 | #define EX_NOINPUT 66 8 | #define EX_NOUSER 67 9 | #define EX_NOHOST 68 10 | #define EX_UNAVAILABLE 69 11 | #define EX_SOFTWARE 70 12 | #define EX_OSERR 71 13 | #define EX_OSFILE 72 14 | #define EX_CANTCREAT 73 15 | #define EX_IOERR 74 16 | #define EX_TEMPFAIL 75 17 | #define EX_PROTOCOL 76 18 | #define EX_NOPERM 77 19 | #define EX_CONFIG 78 20 | #define EX__MAX 78 21 | #endif 22 | -------------------------------------------------------------------------------- /src/kernel/include/idt.h: -------------------------------------------------------------------------------- 1 | #ifndef IDT_H 2 | #define IDT_H 3 | 4 | #include "types.h" 5 | 6 | typedef struct { 7 | uint16_t isr_low; 8 | uint16_t kernel_cs; 9 | uint8_t ist; 10 | uint8_t attributes; 11 | uint16_t isr_mid; 12 | uint32_t isr_high; 13 | uint32_t reserved; 14 | } __attribute__((packed)) idt_gate_t; 15 | 16 | typedef struct { 17 | uint16_t limit; 18 | uint64_t base; 19 | } __attribute__((packed)) idt_register_t; 20 | 21 | void set_idt_gate(int n, uint64_t handler, uint8_t flags); 22 | void set_idt(); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /target/usr/include/assert.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #undef assert 4 | 5 | #ifdef NDEBUG 6 | #define assert(x) (void)0 7 | #else 8 | #define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) 9 | #endif 10 | 11 | #if __STDC_VERSION__ >= 201112L && !defined(__cplusplus) 12 | #define static_assert _Static_assert 13 | #endif 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | _Noreturn void __assert_fail (const char *, const char *, int, const char *); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /src/kernel/include/socket.h: -------------------------------------------------------------------------------- 1 | #include "spinlock.h" 2 | #include "types.h" 3 | #include "vfs.h" 4 | 5 | #ifndef SOCKET_H 6 | #define SOCKET_H 7 | 8 | // socket.c 9 | typedef struct UserSocket { 10 | Spinlock LOCK_INSTANCE; 11 | 12 | int socketInstances; 13 | int lwipFd; 14 | } UserSocket; 15 | 16 | VfsHandlers socketHandlers; 17 | 18 | uint16_t sockaddrLinuxToLwip(void *dest_addr, uint32_t addrlen); 19 | void sockaddrLwipToLinux(void *dest_addr, uint16_t initialFamily); 20 | 21 | // socket_v6.c 22 | VfsHandlers socketv6Handlers; 23 | 24 | #endif -------------------------------------------------------------------------------- /target/usr/include/bits/stat.h: -------------------------------------------------------------------------------- 1 | /* copied from kernel definition, but with padding replaced 2 | * by the corresponding correctly-sized userspace types. */ 3 | 4 | struct stat { 5 | dev_t st_dev; 6 | ino_t st_ino; 7 | nlink_t st_nlink; 8 | 9 | mode_t st_mode; 10 | uid_t st_uid; 11 | gid_t st_gid; 12 | unsigned int __pad0; 13 | dev_t st_rdev; 14 | off_t st_size; 15 | blksize_t st_blksize; 16 | blkcnt_t st_blocks; 17 | 18 | struct timespec st_atim; 19 | struct timespec st_mtim; 20 | struct timespec st_ctim; 21 | long __unused[3]; 22 | }; 23 | -------------------------------------------------------------------------------- /src/kernel/include/serial.h: -------------------------------------------------------------------------------- 1 | #include "system.h" 2 | #include "types.h" 3 | 4 | #define COM1 0x3F8 5 | #define COM2 0x2F8 6 | #define COM3 0x3E8 7 | #define COM4 0x2E8 8 | 9 | // 4 -> COM1, 3 -> COM2 10 | #define SERIAL_IRQ 4 11 | 12 | #ifndef SERIAL_H 13 | #define SERIAL_H 14 | 15 | Spinlock LOCK_DEBUGF; 16 | 17 | void serial_send(int device, char out); 18 | char serial_recv_async(int device); 19 | char serial_recv(int device); 20 | int serial_rcvd(int device); 21 | void initiateSerial(); 22 | void debug(char c, void *arg); 23 | int debugf(const char *format, ...); 24 | 25 | #endif -------------------------------------------------------------------------------- /target/usr/include/fenv.h: -------------------------------------------------------------------------------- 1 | #ifndef _FENV_H 2 | #define _FENV_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | int feclearexcept(int); 11 | int fegetexceptflag(fexcept_t *, int); 12 | int feraiseexcept(int); 13 | int fesetexceptflag(const fexcept_t *, int); 14 | int fetestexcept(int); 15 | 16 | int fegetround(void); 17 | int fesetround(int); 18 | 19 | int fegetenv(fenv_t *); 20 | int feholdexcept(fenv_t *); 21 | int fesetenv(const fenv_t *); 22 | int feupdateenv(const fenv_t *); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /target/usr/include/bits/shm.h: -------------------------------------------------------------------------------- 1 | #define SHMLBA 4096 2 | 3 | struct shmid_ds { 4 | struct ipc_perm shm_perm; 5 | size_t shm_segsz; 6 | time_t shm_atime; 7 | time_t shm_dtime; 8 | time_t shm_ctime; 9 | pid_t shm_cpid; 10 | pid_t shm_lpid; 11 | unsigned long shm_nattch; 12 | unsigned long __pad1; 13 | unsigned long __pad2; 14 | }; 15 | 16 | struct shminfo { 17 | unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4]; 18 | }; 19 | 20 | struct shm_info { 21 | int __used_ids; 22 | unsigned long shm_tot, shm_rss, shm_swp; 23 | unsigned long __swap_attempts, __swap_successes; 24 | }; 25 | -------------------------------------------------------------------------------- /target/usr/include/err.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERR_H 2 | #define _ERR_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | void warn(const char *, ...); 12 | void vwarn(const char *, va_list); 13 | void warnx(const char *, ...); 14 | void vwarnx(const char *, va_list); 15 | 16 | _Noreturn void err(int, const char *, ...); 17 | _Noreturn void verr(int, const char *, va_list); 18 | _Noreturn void errx(int, const char *, ...); 19 | _Noreturn void verrx(int, const char *, va_list); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /target/usr/include/bits/float.h: -------------------------------------------------------------------------------- 1 | #ifdef __FLT_EVAL_METHOD__ 2 | #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ 3 | #else 4 | #define FLT_EVAL_METHOD 0 5 | #endif 6 | 7 | #define LDBL_TRUE_MIN 3.6451995318824746025e-4951L 8 | #define LDBL_MIN 3.3621031431120935063e-4932L 9 | #define LDBL_MAX 1.1897314953572317650e+4932L 10 | #define LDBL_EPSILON 1.0842021724855044340e-19L 11 | 12 | #define LDBL_MANT_DIG 64 13 | #define LDBL_MIN_EXP (-16381) 14 | #define LDBL_MAX_EXP 16384 15 | 16 | #define LDBL_DIG 18 17 | #define LDBL_MIN_10_EXP (-4931) 18 | #define LDBL_MAX_10_EXP 4932 19 | 20 | #define DECIMAL_DIG 21 21 | -------------------------------------------------------------------------------- /patches/pkg-config.diff: -------------------------------------------------------------------------------- 1 | diff --git a/glib/glib/giounix.c b/glib/glib/giounix.c 2 | index 517e36b..794c4e5 100644 3 | --- a/glib/glib/giounix.c 4 | +++ b/glib/glib/giounix.c 5 | @@ -187,8 +187,8 @@ g_io_unix_read (GIOChannel *channel, 6 | GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel; 7 | gssize result; 8 | 9 | - if (count > SSIZE_MAX) /* At least according to the Debian manpage for read */ 10 | - count = SSIZE_MAX; 11 | + if (count > LONG_MAX) /* At least according to the Debian manpage for read */ 12 | + count = LONG_MAX; 13 | 14 | retry: 15 | result = read (unix_channel->fd, buf, count); -------------------------------------------------------------------------------- /src/bootloader/assert.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -x # show cmds 3 | set -e # fail globally 4 | 5 | # Know where we at :p 6 | SCRIPT=$(realpath "$0") 7 | SCRIPTPATH=$(dirname "$SCRIPT") 8 | cd "${SCRIPTPATH}" 9 | 10 | TARGET_VERSION="10.1.1" 11 | 12 | fetchLimine() { 13 | rm -rf limine/ 14 | git clone https://github.com/limine-bootloader/limine.git --branch=v10.x-binary --depth=1 15 | cd limine/ 16 | make 17 | cd ../ 18 | echo "$TARGET_VERSION" >.version 19 | } 20 | 21 | if [[ ! -f ".version" ]] || ! cat .version | grep -i "$TARGET_VERSION" || [[ ! -f "limine/limine" ]]; then 22 | fetchLimine 23 | fi 24 | -------------------------------------------------------------------------------- /src/kernel/include/kb.h: -------------------------------------------------------------------------------- 1 | #include "dev.h" 2 | #include "util.h" 3 | 4 | #ifndef KB_H 5 | #define KB_H 6 | 7 | #define SCANCODE_ENTER 28 8 | #define SCANCODE_BACK 14 9 | #define SCANCODE_SHIFT 42 10 | #define SCANCODE_CAPS 58 11 | #define SCANCODE_UP 0x48 12 | 13 | #define CHARACTER_ENTER '\n' 14 | #define CHARACTER_BACK '\b' 15 | 16 | uint32_t readStr(char *buffstr); 17 | void initiateKb(); 18 | void kbIrq(); 19 | bool kbTaskRead(uint32_t taskId, char *buff, uint32_t limit, 20 | bool changeTaskState); 21 | bool kbIsOccupied(); 22 | 23 | DevInputEvent *kbEvent; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/lwip/apps/snmp_snmpv2_usm.h: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by LwipMibCompiler 3 | */ 4 | 5 | #ifndef LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H 6 | #define LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H 7 | 8 | #include "lwip/apps/snmp_opts.h" 9 | #if LWIP_SNMP 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | #include "lwip/apps/snmp_core.h" 16 | 17 | extern const struct snmp_mib snmpusmmib; 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif /* __cplusplus */ 22 | 23 | #endif /* LWIP_SNMP */ 24 | #endif /* LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H */ 25 | -------------------------------------------------------------------------------- /target/etc/X11/xorg.conf.d/69-cavos.conf: -------------------------------------------------------------------------------- 1 | Section "ServerFlags" 2 | Option "AutoAddDevices" "false" 3 | EndSection 4 | 5 | Section "InputDevice" 6 | Identifier "PSKeyboard" 7 | Driver "evdev" 8 | Option "Device" "/dev/input/event0" 9 | Option "Ignore" "false" 10 | EndSection 11 | 12 | Section "InputDevice" 13 | Identifier "PSMouse" 14 | Driver "evdev" 15 | Option "Device" "/dev/input/event1" 16 | Option "Ignore" "false" 17 | EndSection 18 | 19 | Section "ServerLayout" 20 | Identifier "Default Layout" 21 | InputDevice "PSMouse" "CorePointer" 22 | InputDevice "PSKeyboard" "CoreKeyboard" 23 | EndSection 24 | 25 | -------------------------------------------------------------------------------- /target/etc/profile: -------------------------------------------------------------------------------- 1 | # Set the initial path 2 | export PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/bin 3 | export LANG=C.UTF-8 4 | export LIBGL_ALWAYS_SOFTWARE=1 5 | export SHELL=/bin/bash 6 | export HOME="/root" 7 | 8 | # for any sdl apps :p 9 | # (yes they use futex 6 or smth which we dont support) 10 | export SDL_AUDIODRIVER=dummy 11 | 12 | # if [ $EUID -eq 0 ]; then 13 | # export PATH=/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/bin 14 | # fi 15 | 16 | PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 17 | # PS1='\u@\h:\w\$ ' 18 | 19 | # End /etc/profile 20 | -------------------------------------------------------------------------------- /target/usr/include/ucontext.h: -------------------------------------------------------------------------------- 1 | #ifndef _UCONTEXT_H 2 | #define _UCONTEXT_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #include 10 | 11 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 12 | #define NGREG (sizeof(gregset_t)/sizeof(greg_t)) 13 | #endif 14 | 15 | struct __ucontext; 16 | 17 | int getcontext(struct __ucontext *); 18 | void makecontext(struct __ucontext *, void (*)(), int, ...); 19 | int setcontext(const struct __ucontext *); 20 | int swapcontext(struct __ucontext *, const struct __ucontext *); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /target/usr/include/sys/un.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_UN_H 2 | #define _SYS_UN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_sa_family_t 11 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 12 | #define __NEED_size_t 13 | #endif 14 | 15 | #include 16 | 17 | struct sockaddr_un { 18 | sa_family_t sun_family; 19 | char sun_path[108]; 20 | }; 21 | 22 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 23 | size_t strlen(const char *); 24 | #define SUN_LEN(s) (2+strlen((s)->sun_path)) 25 | #endif 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /target/usr/include/byteswap.h: -------------------------------------------------------------------------------- 1 | #ifndef _BYTESWAP_H 2 | #define _BYTESWAP_H 3 | 4 | #include 5 | #include 6 | 7 | static __inline uint16_t __bswap_16(uint16_t __x) 8 | { 9 | return __x<<8 | __x>>8; 10 | } 11 | 12 | static __inline uint32_t __bswap_32(uint32_t __x) 13 | { 14 | return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; 15 | } 16 | 17 | static __inline uint64_t __bswap_64(uint64_t __x) 18 | { 19 | return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32); 20 | } 21 | 22 | #define bswap_16(x) __bswap_16(x) 23 | #define bswap_32(x) __bswap_32(x) 24 | #define bswap_64(x) __bswap_64(x) 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/kernel/include/avl_tree.h: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #ifndef AVL_TREE_H 4 | #define AVL_TREE_H 5 | 6 | typedef uint64_t avlkey; 7 | typedef uint64_t avlval; 8 | 9 | typedef struct __attribute__((packed)) AVLheader { 10 | avlkey key; 11 | struct AVLheader *left; 12 | struct AVLheader *right; 13 | int height; 14 | avlval value; 15 | // ... 16 | } AVLheader; 17 | 18 | // global thing for all BSTs 19 | avlval AVLLookup(void *root, avlkey key); 20 | 21 | void *AVLAllocate(void **AVLfirstPtr, avlkey key, avlval value); 22 | bool AVLUnregister(void **AVLfirstPtr, avlkey key); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /target/usr/include/bits/stdint.h: -------------------------------------------------------------------------------- 1 | typedef int32_t int_fast16_t; 2 | typedef int32_t int_fast32_t; 3 | typedef uint32_t uint_fast16_t; 4 | typedef uint32_t uint_fast32_t; 5 | 6 | #define INT_FAST16_MIN INT32_MIN 7 | #define INT_FAST32_MIN INT32_MIN 8 | 9 | #define INT_FAST16_MAX INT32_MAX 10 | #define INT_FAST32_MAX INT32_MAX 11 | 12 | #define UINT_FAST16_MAX UINT32_MAX 13 | #define UINT_FAST32_MAX UINT32_MAX 14 | 15 | #define INTPTR_MIN INT64_MIN 16 | #define INTPTR_MAX INT64_MAX 17 | #define UINTPTR_MAX UINT64_MAX 18 | #define PTRDIFF_MIN INT64_MIN 19 | #define PTRDIFF_MAX INT64_MAX 20 | #define SIZE_MAX UINT64_MAX 21 | -------------------------------------------------------------------------------- /target/usr/include/sys/statfs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_STATFS_H 2 | #define _SYS_STATFS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #include 11 | 12 | typedef struct __fsid_t { 13 | int __val[2]; 14 | } fsid_t; 15 | 16 | #include 17 | 18 | int statfs (const char *, struct statfs *); 19 | int fstatfs (int, struct statfs *); 20 | 21 | #if defined(_LARGEFILE64_SOURCE) 22 | #define statfs64 statfs 23 | #define fstatfs64 fstatfs 24 | #define fsblkcnt64_t fsblkcnt_t 25 | #define fsfilcnt64_t fsfilcnt_t 26 | #endif 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/kernel/include/netports.h: -------------------------------------------------------------------------------- 1 | #include "linked_list.h" 2 | #include "util.h" 3 | 4 | #ifndef NET_PORTS_H 5 | #define NET_PORTS_H 6 | 7 | #define NETPORTS_AVAILABLE_PORTS 65536 8 | #define NETPORTS_EPH_START 49152 9 | 10 | typedef struct NetPorts { 11 | uint8_t ports[NETPORTS_AVAILABLE_PORTS / 8]; // bitmap 12 | uint16_t lastEphPort; 13 | Spinlock LOCK_MAP_PORTS; 14 | } NetPorts; 15 | 16 | bool netPortsIsAllocated(NetPorts *netports, uint16_t port); 17 | uint16_t netPortsGen(NetPorts *netports); 18 | bool netPortsMarkSafe(NetPorts *netports, uint16_t localPort); 19 | void netPortsFree(NetPorts *netports, uint16_t localPort); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/kernel/include/psf.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef PSF_H 4 | #define PSF_H 5 | 6 | #define PSF1_MAGIC 0x0436 7 | 8 | typedef struct PSF1Header { 9 | uint16_t magic; 10 | uint8_t mode; 11 | uint8_t height; // width is always 8px 12 | } PSF1Header; 13 | 14 | typedef enum PSF1_MODES { 15 | PSF1_MODE512 = 0x01, 16 | PSF1_MODEHASTAB = 0x02, 17 | PSF1_MODESEQ = 0x04, 18 | } PSF1_MODES; 19 | 20 | PSF1Header *psf; 21 | 22 | bool psfLoadDefaults(); 23 | bool psfLoadFromFile(char *path); 24 | bool psfLoad(void *buffer); 25 | 26 | void psfPutC(char c, uint32_t x, uint32_t y, uint32_t r, uint32_t g, 27 | uint32_t b); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /target/usr/include/netinet/ether.h: -------------------------------------------------------------------------------- 1 | #ifndef _NETINET_ETHER_H 2 | #define _NETINET_ETHER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | char *ether_ntoa (const struct ether_addr *); 11 | struct ether_addr *ether_aton (const char *); 12 | char *ether_ntoa_r (const struct ether_addr *, char *); 13 | struct ether_addr *ether_aton_r (const char *, struct ether_addr *); 14 | int ether_line(const char *, struct ether_addr *, char *); 15 | int ether_ntohost(char *, const struct ether_addr *); 16 | int ether_hostton(const char *, struct ether_addr *); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/FILES: -------------------------------------------------------------------------------- 1 | api/ - The code for the high-level wrapper API. Not needed if 2 | you use the lowel-level call-back/raw API. 3 | 4 | apps/ - Higher layer applications that are specifically programmed 5 | with the lwIP low-level raw API. 6 | 7 | core/ - The core of the TPC/IP stack; protocol implementations, 8 | memory and buffer management, and the low-level raw API. 9 | 10 | include/ - lwIP include files. 11 | 12 | netif/ - Generic network interface device drivers are kept here. 13 | 14 | For more information on the various subdirectories, check the FILES 15 | file in each directory. 16 | -------------------------------------------------------------------------------- /target/usr/include/bits/reg.h: -------------------------------------------------------------------------------- 1 | #undef __WORDSIZE 2 | #define __WORDSIZE 64 3 | #define R15 0 4 | #define R14 1 5 | #define R13 2 6 | #define R12 3 7 | #define RBP 4 8 | #define RBX 5 9 | #define R11 6 10 | #define R10 7 11 | #define R9 8 12 | #define R8 9 13 | #define RAX 10 14 | #define RCX 11 15 | #define RDX 12 16 | #define RSI 13 17 | #define RDI 14 18 | #define ORIG_RAX 15 19 | #define RIP 16 20 | #define CS 17 21 | #define EFLAGS 18 22 | #define RSP 19 23 | #define SS 20 24 | #define FS_BASE 21 25 | #define GS_BASE 22 26 | #define DS 23 27 | #define ES 24 28 | #define FS 25 29 | #define GS 26 30 | -------------------------------------------------------------------------------- /target/usr/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | #if __cplusplus >= 201103L 5 | #define NULL nullptr 6 | #elif defined(__cplusplus) 7 | #define NULL 0L 8 | #else 9 | #define NULL ((void*)0) 10 | #endif 11 | 12 | #define __NEED_ptrdiff_t 13 | #define __NEED_size_t 14 | #define __NEED_wchar_t 15 | #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L 16 | #define __NEED_max_align_t 17 | #endif 18 | 19 | #include 20 | 21 | #if __GNUC__ > 3 22 | #define offsetof(type, member) __builtin_offsetof(type, member) 23 | #else 24 | #define offsetof(type, member) ((size_t)( (char *)&(((type *)0)->member) - (char *)0 )) 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /target/usr/include/cpio.h: -------------------------------------------------------------------------------- 1 | #ifndef _CPIO_H 2 | #define _CPIO_H 3 | 4 | #define MAGIC "070707" 5 | 6 | #define C_IRUSR 000400 7 | #define C_IWUSR 000200 8 | #define C_IXUSR 000100 9 | #define C_IRGRP 000040 10 | #define C_IWGRP 000020 11 | #define C_IXGRP 000010 12 | #define C_IROTH 000004 13 | #define C_IWOTH 000002 14 | #define C_IXOTH 000001 15 | 16 | #define C_ISUID 004000 17 | #define C_ISGID 002000 18 | #define C_ISVTX 001000 19 | 20 | #define C_ISBLK 060000 21 | #define C_ISCHR 020000 22 | #define C_ISDIR 040000 23 | #define C_ISFIFO 010000 24 | #define C_ISSOCK 0140000 25 | #define C_ISLNK 0120000 26 | #define C_ISCTG 0110000 27 | #define C_ISREG 0100000 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /target/usr/include/arpa/tftp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARPA_TFTP_H 2 | #define _ARPA_TFTP_H 3 | #define SEGSIZE 512 4 | #define RRQ 01 5 | #define WRQ 02 6 | #define DATA 03 7 | #define ACK 04 8 | #define ERROR 05 9 | struct tftphdr { 10 | short th_opcode; 11 | union { 12 | unsigned short tu_block; 13 | short tu_code; 14 | char tu_stuff[1]; 15 | } th_u; 16 | char th_data[1]; 17 | }; 18 | #define th_block th_u.tu_block 19 | #define th_code th_u.tu_code 20 | #define th_stuff th_u.tu_stuff 21 | #define th_msg th_data 22 | #define EUNDEF 0 23 | #define ENOTFOUND 1 24 | #define EACCESS 2 25 | #define ENOSPACE 3 26 | #define EBADOP 4 27 | #define EBADID 5 28 | #define EEXISTS 6 29 | #define ENOUSER 7 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /src/kernel/filesystems/vfs/vfs_poll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // VFS-sided implementation of generic *poll() functions 15 | // Copyright (C) 2025 Panagiotis 16 | 17 | // todo: think this through as pairs span across more than one fd (think of 18 | // pipes with read/write ends, etc) 19 | void fsInformReady(OpenFile *fd, int epollEvents) { 20 | // spinlockAcquire(&fd->LOCK_POLL); 21 | // do nothing 22 | // spinlockRelease(&fd->LOCK_POLL); 23 | } 24 | -------------------------------------------------------------------------------- /target/usr/include/getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef _GETOPT_H 2 | #define _GETOPT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int getopt(int, char * const [], const char *); 9 | extern char *optarg; 10 | extern int optind, opterr, optopt, optreset; 11 | 12 | struct option { 13 | const char *name; 14 | int has_arg; 15 | int *flag; 16 | int val; 17 | }; 18 | 19 | int getopt_long(int, char *const *, const char *, const struct option *, int *); 20 | int getopt_long_only(int, char *const *, const char *, const struct option *, int *); 21 | 22 | #define no_argument 0 23 | #define required_argument 1 24 | #define optional_argument 2 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /tools/kernel/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -x # show cmds 3 | 4 | is_mounted() { 5 | mountpoint -q "$1" 6 | } 7 | 8 | unmount_with_retry() { 9 | local target="$1" 10 | while is_mounted "$target"; do 11 | if sudo umount "$target" 2>/dev/null; then 12 | echo "Successfully unmounted: $target" 13 | return 0 14 | else 15 | echo "Failed to unmount $target (possibly busy). Retrying in 2 seconds..." 16 | sleep 2 17 | fi 18 | done 19 | echo "$target is not mounted." 20 | } 21 | 22 | # $1 -> mounted volume 23 | if [ -z "$1" ]; then 24 | echo "Please supply the correct arguments!" 25 | exit 1 26 | fi 27 | 28 | unmount_with_retry "${1}/boot" 29 | unmount_with_retry "${1}" 30 | sudo losetup -d /dev/loop101 31 | -------------------------------------------------------------------------------- /target/usr/include/tar.h: -------------------------------------------------------------------------------- 1 | #ifndef _TAR_H 2 | #define _TAR_H 3 | 4 | #define TSUID 04000 5 | #define TSGID 02000 6 | #define TSVTX 01000 7 | #define TUREAD 00400 8 | #define TUWRITE 00200 9 | #define TUEXEC 00100 10 | #define TGREAD 00040 11 | #define TGWRITE 00020 12 | #define TGEXEC 00010 13 | #define TOREAD 00004 14 | #define TOWRITE 00002 15 | #define TOEXEC 00001 16 | 17 | #define REGTYPE '0' 18 | #define AREGTYPE '\0' 19 | #define LNKTYPE '1' 20 | #define SYMTYPE '2' 21 | #define CHRTYPE '3' 22 | #define BLKTYPE '4' 23 | #define DIRTYPE '5' 24 | #define FIFOTYPE '6' 25 | #define CONTTYPE '7' 26 | 27 | #define TMAGIC "ustar" 28 | #define TMAGLEN 6 29 | 30 | #define TVERSION "00" 31 | #define TVERSLEN 2 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /patches/patch.diff: -------------------------------------------------------------------------------- 1 | diff --git a/build-aux/config.sub b/build-aux/config.sub 2 | index 3e95176..0f939fa 100755 3 | --- a/build-aux/config.sub 4 | +++ b/build-aux/config.sub 5 | @@ -1363,7 +1363,7 @@ case $os in 6 | # The portable systems comes first. 7 | # Each alternative MUST end in a * to match a version number. 8 | # -sysv* is not here because it comes later, after sysvr4. 9 | - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ 10 | + -gnu* | -cavos* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ 11 | | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ 12 | | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ 13 | | -sym* | -kopensolaris* | -plan9* \ 14 | -------------------------------------------------------------------------------- /tools/toolchain/get_formatter.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # set -x # show cmds 3 | set -e # fail globally 4 | mkdir -p ~/opt/ 5 | 6 | # Embedded clang-format-19 (verified sha512sum from GitHub actions) 7 | CLANG_FORMAT_URI="https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-46b8640/clang-format-19_linux-amd64" 8 | CLANG_FORMAT_SHA512="7fbbc586949d7dda7488b42a8fe2bd9cbe31e4eed9b57adf857f62a61d29c86d51372d01561d1be6a4288ee62dc888acb9477a15ff8c2dacc7da4b1b705c2aa1" 9 | CLANG_FORMAT_TARGET="$HOME/opt/clang-format-cavos" 10 | 11 | chmod +x "tools/shared/pass_acq.sh" 12 | tools/shared/pass_acq.sh "$CLANG_FORMAT_URI" "$CLANG_FORMAT_SHA512" "$CLANG_FORMAT_TARGET" 13 | 14 | # Just in case 15 | chmod +x "$CLANG_FORMAT_TARGET" 16 | -------------------------------------------------------------------------------- /target/usr/include/sys/timerfd.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TIMERFD_H 2 | #define _SYS_TIMERFD_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #define TFD_NONBLOCK O_NONBLOCK 12 | #define TFD_CLOEXEC O_CLOEXEC 13 | 14 | #define TFD_TIMER_ABSTIME 1 15 | #define TFD_TIMER_CANCEL_ON_SET (1 << 1) 16 | 17 | struct itimerspec; 18 | 19 | int timerfd_create(int, int); 20 | int timerfd_settime(int, int, const struct itimerspec *, struct itimerspec *); 21 | int timerfd_gettime(int, struct itimerspec *); 22 | 23 | #if _REDIR_TIME64 24 | __REDIR(timerfd_settime, __timerfd_settime64); 25 | __REDIR(timerfd_gettime, __timerfd_gettime64); 26 | #endif 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/kernel/include/netqueue.h: -------------------------------------------------------------------------------- 1 | #include "linked_list.h" 2 | #include "util.h" 3 | 4 | #ifndef NET_QUEUE_H 5 | #define NET_QUEUE_H 6 | 7 | typedef void (*QueueItemCallback)(void *item); 8 | typedef enum { NET_QUEUE_ARP } netQueueComp; 9 | 10 | typedef struct netQueueItem { 11 | LLheader _ll; 12 | 13 | void *nic; 14 | void *task; 15 | size_t unixTime; 16 | 17 | // size_t pollWakeupKey; 18 | // size_t pollWakeupEvent; 19 | 20 | netQueueComp component; 21 | QueueItemCallback callback; 22 | 23 | void *dir; 24 | } netQueueItem; 25 | 26 | LLcontrol dsNetQueue; // struct netQueueItem 27 | Spinlock LOCK_LL_NET_QUEUE; 28 | 29 | netQueueItem *netQueueAllocateM(netQueueComp component, void *nic); 30 | 31 | void helperNetQueue(); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/kernel/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H 2 | #define STRING_H 3 | 4 | #include "types.h" 5 | 6 | bool strEql(char *ch1, char *ch2); 7 | char *strtok(char *str, const char *delimiters, char **context); 8 | char *strpbrk(const char *str, const char *delimiters); 9 | int atoi(const char *str); 10 | size_t strlength(const char *ch); 11 | size_t strlen(const char *ch); 12 | int strncmp(const char *str1, const char *str2, size_t n); 13 | bool check_string(char *str); 14 | long strtol(const char *s, char **endptr, int base); 15 | void strncpy(char *dest, const char *src, size_t n); 16 | char *strdup(char *source); 17 | char *strrchr(const char *str, int c); 18 | 19 | uint64_t numAtEnd(const char *str); 20 | 21 | int isdigit(char c); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /target/usr/include/ifaddrs.h: -------------------------------------------------------------------------------- 1 | #ifndef _IFADDRS_H 2 | #define _IFADDRS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | struct ifaddrs { 13 | struct ifaddrs *ifa_next; 14 | char *ifa_name; 15 | unsigned ifa_flags; 16 | struct sockaddr *ifa_addr; 17 | struct sockaddr *ifa_netmask; 18 | union { 19 | struct sockaddr *ifu_broadaddr; 20 | struct sockaddr *ifu_dstaddr; 21 | } ifa_ifu; 22 | void *ifa_data; 23 | }; 24 | #define ifa_broadaddr ifa_ifu.ifu_broadaddr 25 | #define ifa_dstaddr ifa_ifu.ifu_dstaddr 26 | 27 | void freeifaddrs(struct ifaddrs *); 28 | int getifaddrs(struct ifaddrs **); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /target/usr/include/sys/membarrier.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_MEMBARRIER_H 2 | #define _SYS_MEMBARRIER_H 3 | 4 | #define MEMBARRIER_CMD_QUERY 0 5 | #define MEMBARRIER_CMD_GLOBAL 1 6 | #define MEMBARRIER_CMD_GLOBAL_EXPEDITED 2 7 | #define MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED 4 8 | #define MEMBARRIER_CMD_PRIVATE_EXPEDITED 8 9 | #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED 16 10 | #define MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 32 11 | #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE 64 12 | #define MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ 128 13 | #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ 256 14 | 15 | #define MEMBARRIER_CMD_SHARED MEMBARRIER_CMD_GLOBAL 16 | 17 | #define MEMBARRIER_CMD_FLAG_CPU 1 18 | 19 | int membarrier(int, int); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /target/usr/include/uchar.h: -------------------------------------------------------------------------------- 1 | #ifndef _UCHAR_H 2 | #define _UCHAR_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #if __cplusplus < 201103L 9 | typedef unsigned short char16_t; 10 | typedef unsigned char32_t; 11 | #endif 12 | 13 | #define __NEED_mbstate_t 14 | #define __NEED_size_t 15 | 16 | #include 17 | #include 18 | 19 | size_t c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict); 20 | size_t mbrtoc16(char16_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); 21 | 22 | size_t c32rtomb(char *__restrict, char32_t, mbstate_t *__restrict); 23 | size_t mbrtoc32(char32_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /target/usr/include/stdio_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDIO_EXT_H 2 | #define _STDIO_EXT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define FSETLOCKING_QUERY 0 11 | #define FSETLOCKING_INTERNAL 1 12 | #define FSETLOCKING_BYCALLER 2 13 | 14 | void _flushlbf(void); 15 | int __fsetlocking(FILE *, int); 16 | int __fwriting(FILE *); 17 | int __freading(FILE *); 18 | int __freadable(FILE *); 19 | int __fwritable(FILE *); 20 | int __flbf(FILE *); 21 | size_t __fbufsize(FILE *); 22 | size_t __fpending(FILE *); 23 | int __fpurge(FILE *); 24 | 25 | size_t __freadahead(FILE *); 26 | const char *__freadptr(FILE *, size_t *); 27 | void __freadptrinc(FILE *, size_t); 28 | void __fseterr(FILE *); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/kernel/cpu/idt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // IDT Entry configurator 6 | // Copyright (C) 2024 Panagiotis 7 | 8 | #define IDT_ENTRIES 256 9 | static idt_gate_t idt[IDT_ENTRIES] = {0}; 10 | static idt_register_t idt_reg; 11 | 12 | void set_idt_gate(int n, uint64_t handler, uint8_t flags) { 13 | idt[n].isr_low = (uint16_t)handler; 14 | idt[n].kernel_cs = GDT_KERNEL_CODE; 15 | idt[n].ist = 0; 16 | idt[n].reserved = 0; 17 | idt[n].attributes = flags; 18 | idt[n].isr_mid = (uint16_t)(handler >> 16); 19 | idt[n].isr_high = (uint32_t)(handler >> 32); 20 | } 21 | 22 | void set_idt() { 23 | idt_reg.base = (size_t)&idt; 24 | idt_reg.limit = IDT_ENTRIES * sizeof(idt_gate_t) - 1; 25 | asm volatile("lidt %0" ::"m"(idt_reg) : "memory"); 26 | } 27 | -------------------------------------------------------------------------------- /target/usr/include/sys/sysinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SYSINFO_H 2 | #define _SYS_SYSINFO_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define SI_LOAD_SHIFT 16 9 | 10 | struct sysinfo { 11 | unsigned long uptime; 12 | unsigned long loads[3]; 13 | unsigned long totalram; 14 | unsigned long freeram; 15 | unsigned long sharedram; 16 | unsigned long bufferram; 17 | unsigned long totalswap; 18 | unsigned long freeswap; 19 | unsigned short procs, pad; 20 | unsigned long totalhigh; 21 | unsigned long freehigh; 22 | unsigned mem_unit; 23 | char __reserved[256]; 24 | }; 25 | 26 | int sysinfo (struct sysinfo *); 27 | int get_nprocs_conf (void); 28 | int get_nprocs (void); 29 | long get_phys_pages (void); 30 | long get_avphys_pages (void); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/kernel/include/types.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifndef TYPES_H 6 | #define TYPES_H 7 | 8 | #define ERR_INDIRECT(errno) (errno##UL) 9 | #define ERR(errno) (-ERR_INDIRECT(errno)) 10 | 11 | // typedef long ssize_t; 12 | #define INT_MAX 2147483647 // 2^31 - 1 13 | 14 | #define low_16(address) (uint16_t)((address) & 0xFFFF) 15 | #define high_16(address) (uint16_t)(((address) >> 16) & 0xFFFF) 16 | 17 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 18 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 19 | 20 | #define force_inline inline __attribute__((always_inline)) 21 | 22 | #define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT 1 23 | #define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES 1 24 | #include "limine.h" 25 | #include "pmm.h" 26 | #include "printf.h" 27 | #include "serial.h" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/kernel/networking/socket_v6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | // Dumb IPv6 socket to return errors (fuck IPv6) 10 | // Copyright (C) 2025 Panagiotis 11 | 12 | size_t socketv6Connect(OpenFile *fd, sockaddr_linux *addr, uint32_t len) { 13 | // network unreachable 14 | return ERR(ENETUNREACH); 15 | } 16 | 17 | size_t socketv6Bind(OpenFile *fd, sockaddr_linux *addr, size_t len) { 18 | // cannot assign addr 19 | return ERR(EADDRNOTAVAIL); 20 | } 21 | 22 | size_t socketv6Listen(OpenFile *fd, int backlog) { 23 | // wasn't yet bound 24 | return ERR(EADDRINUSE); 25 | } 26 | 27 | VfsHandlers socketv6Handlers = { 28 | .connect = socketv6Connect, .bind = socketv6Bind, .listen = socketv6Listen}; 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries 2 | target/boot/*.bin 3 | target/usr/bin/* 4 | target/usr/sbin 5 | target/usr/lib 6 | target/lib 7 | disk.img 8 | disk.vmdk 9 | temporarydir 10 | 11 | # Libraries 12 | target/usr/include/ncursesw 13 | target/usr/etc/profile.d 14 | target/usr/libexec 15 | target/usr/x86_64-cavos 16 | target/usr/x86_64-linux-musl 17 | 18 | # Chroot stuff 19 | target/dev/shm 20 | target/run 21 | target/sys 22 | target/proc 23 | target/dev/pts 24 | target/dev 25 | target/bin 26 | target/etc/ssl 27 | 28 | # Limine repository 29 | src/bootloader/limine 30 | src/bootloader/.version 31 | 32 | # Misc (on the target system) 33 | target/etc/localtime 34 | target/usr/share 35 | 36 | pci.ids 37 | 38 | # Wireshark network dumps 39 | *.pcapng 40 | 41 | # Could obviously contain sensitive data 42 | .idea/ 43 | Session.vim 44 | 45 | # uACPI 46 | .version_uacpi 47 | -------------------------------------------------------------------------------- /target/usr/include/ftw.h: -------------------------------------------------------------------------------- 1 | #ifndef _FTW_H 2 | #define _FTW_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #define FTW_F 1 12 | #define FTW_D 2 13 | #define FTW_DNR 3 14 | #define FTW_NS 4 15 | #define FTW_SL 5 16 | #define FTW_DP 6 17 | #define FTW_SLN 7 18 | 19 | #define FTW_PHYS 1 20 | #define FTW_MOUNT 2 21 | #define FTW_CHDIR 4 22 | #define FTW_DEPTH 8 23 | 24 | struct FTW { 25 | int base; 26 | int level; 27 | }; 28 | 29 | int ftw(const char *, int (*)(const char *, const struct stat *, int), int); 30 | int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int); 31 | 32 | #if defined(_LARGEFILE64_SOURCE) 33 | #define ftw64 ftw 34 | #define nftw64 nftw 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /target/usr/include/wordexp.h: -------------------------------------------------------------------------------- 1 | #ifndef _WORDEXP_H 2 | #define _WORDEXP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | 12 | #include 13 | 14 | #define WRDE_DOOFFS 1 15 | #define WRDE_APPEND 2 16 | #define WRDE_NOCMD 4 17 | #define WRDE_REUSE 8 18 | #define WRDE_SHOWERR 16 19 | #define WRDE_UNDEF 32 20 | 21 | typedef struct { 22 | size_t we_wordc; 23 | char **we_wordv; 24 | size_t we_offs; 25 | } wordexp_t; 26 | 27 | #define WRDE_NOSYS -1 28 | #define WRDE_NOSPACE 1 29 | #define WRDE_BADCHAR 2 30 | #define WRDE_BADVAL 3 31 | #define WRDE_CMDSUB 4 32 | #define WRDE_SYNTAX 5 33 | 34 | int wordexp (const char *__restrict, wordexp_t *__restrict, int); 35 | void wordfree (wordexp_t *); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /target/usr/include/arpa/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARPA_INET_H 2 | #define _ARPA_INET_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | uint32_t htonl(uint32_t); 12 | uint16_t htons(uint16_t); 13 | uint32_t ntohl(uint32_t); 14 | uint16_t ntohs(uint16_t); 15 | 16 | in_addr_t inet_addr (const char *); 17 | in_addr_t inet_network (const char *); 18 | char *inet_ntoa (struct in_addr); 19 | int inet_pton (int, const char *__restrict, void *__restrict); 20 | const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); 21 | 22 | int inet_aton (const char *, struct in_addr *); 23 | struct in_addr inet_makeaddr(in_addr_t, in_addr_t); 24 | in_addr_t inet_lnaof(struct in_addr); 25 | in_addr_t inet_netof(struct in_addr); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /target/usr/include/sys/ipc.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_IPC_H 2 | #define _SYS_IPC_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #define __NEED_uid_t 10 | #define __NEED_gid_t 11 | #define __NEED_mode_t 12 | #define __NEED_key_t 13 | 14 | #include 15 | 16 | #define __ipc_perm_key __key 17 | #define __ipc_perm_seq __seq 18 | 19 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 20 | #define __key key 21 | #define __seq seq 22 | #endif 23 | 24 | #include 25 | #include 26 | 27 | #define IPC_CREAT 01000 28 | #define IPC_EXCL 02000 29 | #define IPC_NOWAIT 04000 30 | 31 | #define IPC_RMID 0 32 | #define IPC_SET 1 33 | #define IPC_INFO 3 34 | 35 | #define IPC_PRIVATE ((key_t) 0) 36 | 37 | key_t ftok (const char *, int); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /tools/shared/pass_acq.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # set -x # show cmds 3 | set -e # fail globally 4 | 5 | PASS_ACQ_URI=$1 6 | PASS_ACQ_SHA512=$2 7 | PASS_ACQ_TARGET=$3 8 | 9 | # Initial download (if needed) 10 | if [ ! -f "$PASS_ACQ_TARGET" ]; then 11 | wget -nc -O "$PASS_ACQ_TARGET" "$PASS_ACQ_URI" 12 | fi 13 | 14 | # Pass 1. If this fails, just redownload and re-check 15 | if [ "$(sha512sum "$PASS_ACQ_TARGET" | sed 's/ .*//g')" != "$PASS_ACQ_SHA512" ]; then 16 | # Pass 2. Re-download, re-check. might be just an update 17 | rm -f "$PASS_ACQ_TARGET" 18 | wget -nc -O "$PASS_ACQ_TARGET" "$PASS_ACQ_URI" 19 | if [ "$(sha512sum "$PASS_ACQ_TARGET" | sed 's/ .*//g')" != "$PASS_ACQ_SHA512" ]; then 20 | # Now it's actually malicious. Discard binary and exit 21 | rm -f "$PASS_ACQ_TARGET" 22 | echo "Binary failed sha256 validation! Report immidiately." 23 | exit 1 24 | fi 25 | fi 26 | -------------------------------------------------------------------------------- /src/libs/system/system.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SYSCALL_TEST 0 4 | #define SYSCALL_EXIT_TASK 1 5 | #define SYSCALL_FORK 2 6 | #define SYSCALL_READ 3 7 | #define SYSCALL_WRITE 4 8 | 9 | #define SYSCALL_GETPID 20 10 | 11 | #define SYSCALL_GETARGC 400 12 | #define SYSCALL_GETARGV 401 13 | #define SYSCALL_GET_HEAP_START 402 14 | #define SYSCALL_GET_HEAP_END 403 15 | #define SYSCALL_ADJUST_HEAP_END 404 16 | 17 | void syscallTest(char *msg); 18 | void syscallExitTask(int return_code); 19 | uint32_t syscallFork(); 20 | void syscallRead(int file, char *str, uint32_t count); 21 | void syscallWrite(int file, char *str, uint32_t count); 22 | 23 | uint32_t syscallGetPid(); 24 | 25 | int syscallGetArgc(); 26 | char *syscallGetArgv(int curr); 27 | uint32_t syscallGetHeapStart(); 28 | uint32_t syscallGetHeapEnd(); 29 | void syscallAdjustHeapEnd(uint32_t heap_end); 30 | -------------------------------------------------------------------------------- /target/etc/inputrc: -------------------------------------------------------------------------------- 1 | # Begin /etc/inputrc 2 | 3 | # Make sure we don't output everything on the 1 line 4 | set horizontal-scroll-mode Off 5 | 6 | # Enable 8bit input 7 | set meta-flag On 8 | set input-meta On 9 | 10 | # Turns off 8th bit stripping 11 | set convert-meta Off 12 | 13 | # Keep the 8th bit for display 14 | set output-meta On 15 | 16 | # none, visible or audible 17 | set bell-style none 18 | 19 | # All of the following map the escape sequence of the 20 | # value contained inside the 1st argument to the 21 | # readline specific functions 22 | 23 | "\eOd": backward-word 24 | "\eOc": forward-word 25 | 26 | # for linux console 27 | "\e[1~": beginning-of-line 28 | "\e[4~": end-of-line 29 | "\e[5~": beginning-of-history 30 | "\e[6~": end-of-history 31 | "\e[3~": delete-char 32 | "\e[2~": quoted-insert 33 | 34 | # for xterm 35 | "\eOH": beginning-of-line 36 | "\eOF": end-of-line 37 | 38 | # End /etc/inputrc 39 | -------------------------------------------------------------------------------- /target/usr/include/sys/param.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_PARAM_H 2 | #define _SYS_PARAM_H 3 | 4 | #define MAXSYMLINKS 20 5 | #define MAXHOSTNAMELEN 64 6 | #define MAXNAMLEN 255 7 | #define MAXPATHLEN 4096 8 | #define NBBY 8 9 | #define NGROUPS 32 10 | #define CANBSIZ 255 11 | #define NOFILE 256 12 | #define NCARGS 131072 13 | #define DEV_BSIZE 512 14 | #define NOGROUP (-1) 15 | 16 | #undef MIN 17 | #undef MAX 18 | #define MIN(a,b) (((a)<(b))?(a):(b)) 19 | #define MAX(a,b) (((a)>(b))?(a):(b)) 20 | 21 | #define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8)) 22 | #define setbit(x,i) __bitop(x,i,|=) 23 | #define clrbit(x,i) __bitop(x,i,&=~) 24 | #define isset(x,i) __bitop(x,i,&) 25 | #define isclr(x,i) !isset(x,i) 26 | 27 | #define howmany(n,d) (((n)+((d)-1))/(d)) 28 | #define roundup(n,d) (howmany(n,d)*(d)) 29 | #define powerof2(n) !(((n)-1) & (n)) 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /tools/toolchain/get_autotools.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -x # show cmds 3 | set -e # fail globally 4 | 5 | if [ "$#" -ne 3 ]; then 6 | echo "Usage: $0 " 7 | exit 1 8 | fi 9 | 10 | automake_version=$1 11 | autoconf_version=$2 12 | install_prefix=$3 13 | 14 | mkdir -p "$install_prefix" 15 | 16 | mkdir -p tmp_get_autotools 17 | cd tmp_get_autotools 18 | 19 | build_package() { 20 | package_name=$1 21 | version=$2 22 | install_dir=$3 23 | 24 | wget -nc "https://ftp.gnu.org/gnu/$package_name/$package_name-$version.tar.gz" 25 | tar -xf "$package_name-$version.tar.gz" 26 | cd "$package_name-$version" 27 | ./configure --prefix="$install_dir" 28 | make 29 | make install 30 | cd .. 31 | } 32 | 33 | build_package "automake" "$automake_version" "$install_prefix" 34 | build_package "autoconf" "$autoconf_version" "$install_prefix" 35 | 36 | cd .. 37 | rm -rf tmp_get_autotools 38 | -------------------------------------------------------------------------------- /src/kernel/include/console.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef CONSOLE_H 4 | #define CONSOLE_H 5 | 6 | uint32_t width; 7 | uint32_t height; 8 | 9 | extern int bg_color[]; 10 | extern int textcolor[]; 11 | 12 | atomic_bool consoleDisabled; 13 | 14 | #define TTY_CHARACTER_WIDTH 8 15 | #define TTY_CHARACTER_HEIGHT 16 16 | 17 | #define DEFAULT_FONT_PATH "/fonts/u_custom.psf" 18 | 19 | void initiateConsole(); 20 | void drawCharacter(int charnum); 21 | 22 | bool cursorHidden; 23 | 24 | // Internal variables 25 | void changeBg(int r, int g, int b); 26 | void changeTextColor(int r, int g, int b); 27 | uint32_t getConsoleX(); 28 | uint32_t getConsoleY(); 29 | void setConsoleX(uint32_t x); 30 | void setConsoleY(uint32_t y); 31 | 32 | // Control the console's pointer 33 | void eraseBull(); 34 | void updateBull(); 35 | 36 | void clearScreen(); 37 | 38 | void printfch(char character); 39 | void putchar_(char c); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/kernel/include/disk.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #define SECTOR_SIZE 512 4 | #define LBA_TO_OFFSET(a) ((a) * SECTOR_SIZE) 5 | 6 | #ifndef DISK_H 7 | #define DISK_H 8 | 9 | #define MBR_PARTITION_1 0x01BE 10 | #define MBR_PARTITION_2 0x01CE 11 | #define MBR_PARTITION_3 0x01DE 12 | #define MBR_PARTITION_4 0x01EE 13 | 14 | #define MBR_BOOTABLE 0x80 15 | #define MBR_REGULAR 0x00 16 | 17 | typedef struct { 18 | uint8_t status; 19 | uint8_t chs_first_sector[3]; 20 | uint8_t type; 21 | uint8_t chs_last_sector[3]; 22 | uint32_t lba_first_sector; 23 | uint32_t sector_count; 24 | } mbr_partition; 25 | 26 | bool openDisk(uint32_t disk, uint8_t partition, mbr_partition *out); 27 | bool validateMbr(uint8_t *mbrSector); 28 | 29 | void getDiskBytes(uint8_t *target_address, uint32_t LBA, size_t sector_count); 30 | void setDiskBytes(const uint8_t *target_address, uint32_t LBA, 31 | size_t sector_count); 32 | 33 | #endif -------------------------------------------------------------------------------- /target/usr/include/shadow.h: -------------------------------------------------------------------------------- 1 | #ifndef _SHADOW_H 2 | #define _SHADOW_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __NEED_FILE 9 | #define __NEED_size_t 10 | 11 | #include 12 | 13 | #define SHADOW "/etc/shadow" 14 | 15 | struct spwd { 16 | char *sp_namp; 17 | char *sp_pwdp; 18 | long sp_lstchg; 19 | long sp_min; 20 | long sp_max; 21 | long sp_warn; 22 | long sp_inact; 23 | long sp_expire; 24 | unsigned long sp_flag; 25 | }; 26 | 27 | void setspent(void); 28 | void endspent(void); 29 | struct spwd *getspent(void); 30 | struct spwd *fgetspent(FILE *); 31 | struct spwd *sgetspent(const char *); 32 | int putspent(const struct spwd *, FILE *); 33 | 34 | struct spwd *getspnam(const char *); 35 | int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **); 36 | 37 | int lckpwdf(void); 38 | int ulckpwdf(void); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /target/usr/include/bits/fenv.h: -------------------------------------------------------------------------------- 1 | #define FE_INVALID 1 2 | #define __FE_DENORM 2 3 | #define FE_DIVBYZERO 4 4 | #define FE_OVERFLOW 8 5 | #define FE_UNDERFLOW 16 6 | #define FE_INEXACT 32 7 | 8 | #define FE_ALL_EXCEPT 63 9 | 10 | #define FE_TONEAREST 0 11 | #define FE_DOWNWARD 0x400 12 | #define FE_UPWARD 0x800 13 | #define FE_TOWARDZERO 0xc00 14 | 15 | typedef unsigned short fexcept_t; 16 | 17 | typedef struct { 18 | unsigned short __control_word; 19 | unsigned short __unused1; 20 | unsigned short __status_word; 21 | unsigned short __unused2; 22 | unsigned short __tags; 23 | unsigned short __unused3; 24 | unsigned int __eip; 25 | unsigned short __cs_selector; 26 | unsigned int __opcode:11; 27 | unsigned int __unused4:5; 28 | unsigned int __data_offset; 29 | unsigned short __data_selector; 30 | unsigned short __unused5; 31 | unsigned int __mxcsr; 32 | } fenv_t; 33 | 34 | #define FE_DFL_ENV ((const fenv_t *) -1) 35 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/netif/ppp/polarssl/README: -------------------------------------------------------------------------------- 1 | About PolarSSL files into lwIP PPP support 2 | ------------------------------------------ 3 | 4 | This folder contains some files fetched from the latest BSD release of 5 | the PolarSSL project (PolarSSL 0.10.1-bsd) for ciphers and encryption 6 | methods we need for lwIP PPP support. 7 | 8 | The PolarSSL files were cleaned to contain only the necessary struct 9 | fields and functions needed for lwIP. 10 | 11 | The PolarSSL API was not changed at all, so if you are already using 12 | PolarSSL you can choose to skip the compilation of the included PolarSSL 13 | library into lwIP. 14 | 15 | If you are not using the embedded copy you must include external 16 | libraries into your arch/cc.h port file. 17 | 18 | Beware of the stack requirements which can be a lot larger if you are not 19 | using our cleaned PolarSSL library. 20 | 21 | 22 | PolarSSL project website: http://polarssl.org/ 23 | -------------------------------------------------------------------------------- /tools/kernel/uacpi.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -x # show cmds 3 | set -e # fail globally 4 | 5 | # Know where we at :p 6 | SCRIPT=$(realpath "$0") 7 | SCRIPTPATH=$(dirname "$SCRIPT") 8 | PROJECT_ROOT="${SCRIPTPATH}/../../" 9 | cd "${PROJECT_ROOT}/src/kernel/acpi/" 10 | 11 | VERSION_FILE="$PROJECT_ROOT/.version_uacpi" 12 | TARGET_VERSION="3.1.0" 13 | 14 | fetchUACPI() { 15 | rm -rf uACPI/ repo/ uacpi/ ../include/uacpi/ 16 | mkdir -p uacpi/ 17 | wget "https://github.com/uACPI/uACPI/archive/refs/tags/$TARGET_VERSION.tar.gz" -O "$TARGET_VERSION.tar.gz" 18 | tar xpf "$TARGET_VERSION.tar.gz" 19 | rm -f "$TARGET_VERSION.tar.gz" 20 | mv "uACPI-$TARGET_VERSION" repo/ 21 | mv "repo/source/"* uacpi/ 22 | mv "repo/include/"* ../include/ 23 | rm -rf uACPI/ repo/ 24 | echo "$TARGET_VERSION" >"$VERSION_FILE" 25 | } 26 | 27 | if [[ ! -f "$VERSION_FILE" ]] || ! cat "$VERSION_FILE" | grep -i "$TARGET_VERSION" || [[ ! -d "uacpi" ]]; then 28 | fetchUACPI 29 | fi 30 | -------------------------------------------------------------------------------- /target/usr/include/fmtmsg.h: -------------------------------------------------------------------------------- 1 | #ifndef _FMTMSG_H 2 | #define _FMTMSG_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define MM_HARD 1 9 | #define MM_SOFT 2 10 | #define MM_FIRM 4 11 | 12 | #define MM_APPL 8 13 | #define MM_UTIL 16 14 | #define MM_OPSYS 32 15 | 16 | #define MM_RECOVER 64 17 | #define MM_NRECOV 128 18 | 19 | #define MM_PRINT 256 20 | #define MM_CONSOLE 512 21 | 22 | #define MM_NULLMC 0L 23 | 24 | #define MM_HALT 1 25 | #define MM_ERROR 2 26 | #define MM_WARNING 3 27 | #define MM_INFO 4 28 | #define MM_NOSEV 0 29 | 30 | #define MM_OK 0 31 | #define MM_NOTOK (-1) 32 | #define MM_NOMSG 1 33 | #define MM_NOCON 4 34 | 35 | #define MM_NULLLBL ((char*)0) 36 | #define MM_NULLTXT ((char*)0) 37 | #define MM_NULLACT ((char*)0) 38 | #define MM_NULLTAG ((char*)0) 39 | #define MM_NULLSEV 0 40 | 41 | int fmtmsg(long, const char *, int, const char *, const char *, const char *); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/kernel/include/spinlock.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "types.h" 4 | 5 | #ifndef SPINLOCK_H 6 | #define SPINLOCK_H 7 | 8 | // typedef struct SpinLock { 9 | // bool locked; 10 | // } SpinLock; 11 | // #define __SPINLOCK(name) static SpinLock name = {.locked = false} 12 | 13 | typedef atomic_flag Spinlock; 14 | 15 | void spinlockAcquire(Spinlock *lock); 16 | void spinlockRelease(Spinlock *lock); 17 | 18 | typedef struct SpinlockCnt { 19 | Spinlock LOCK; 20 | int64_t cnt; 21 | } SpinlockCnt; 22 | 23 | typedef struct Semaphore { 24 | Spinlock LOCK; 25 | uint32_t cnt; 26 | uint8_t invalid; 27 | } Semaphore; 28 | 29 | void spinlockCntReadAcquire(SpinlockCnt *lock); 30 | void spinlockCntReadRelease(SpinlockCnt *lock); 31 | 32 | void spinlockCntWriteAcquire(SpinlockCnt *lock); 33 | void spinlockCntWriteRelease(SpinlockCnt *lock); 34 | 35 | bool semaphoreWait(Semaphore *sem, uint32_t timeout); 36 | void semaphorePost(Semaphore *sem); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/lwip/apps/snmp_snmpv2_framework.h: -------------------------------------------------------------------------------- 1 | /* 2 | Generated by LwipMibCompiler 3 | */ 4 | 5 | #ifndef LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H 6 | #define LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H 7 | 8 | #include "lwip/apps/snmp_opts.h" 9 | #if LWIP_SNMP 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | #include "lwip/apps/snmp_core.h" 16 | 17 | extern const struct snmp_obj_id usmNoAuthProtocol; 18 | extern const struct snmp_obj_id usmHMACMD5AuthProtocol; 19 | extern const struct snmp_obj_id usmHMACSHAAuthProtocol; 20 | 21 | extern const struct snmp_obj_id usmNoPrivProtocol; 22 | extern const struct snmp_obj_id usmDESPrivProtocol; 23 | extern const struct snmp_obj_id usmAESPrivProtocol; 24 | 25 | extern const struct snmp_mib snmpframeworkmib; 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif /* __cplusplus */ 30 | 31 | #endif /* LWIP_SNMP */ 32 | #endif /* LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H */ 33 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/netif/FILES: -------------------------------------------------------------------------------- 1 | This directory contains generic network interface device drivers that 2 | do not contain any hardware or architecture specific code. The files 3 | are: 4 | 5 | ethernet.c 6 | Shared code for Ethernet based interfaces. 7 | 8 | lowpan6.c 9 | A 6LoWPAN implementation as a netif. 10 | 11 | lowpan6_ble.c 12 | A 6LoWPAN over Bluetooth Low Energy (BLE) implementation as netif, 13 | according to RFC-7668. 14 | 15 | slipif.c 16 | A generic implementation of the SLIP (Serial Line IP) 17 | protocol. It requires a sio (serial I/O) module to work. 18 | 19 | ppp/ Point-to-Point Protocol stack 20 | The lwIP PPP support is based from pppd (http://ppp.samba.org) with 21 | huge changes to match code size and memory requirements for embedded 22 | devices. Please read /doc/ppp.txt and ppp/PPPD_FOLLOWUP for a detailed 23 | explanation. 24 | -------------------------------------------------------------------------------- /target/usr/include/netinet/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef _NETINET_UDP_H 2 | #define _NETINET_UDP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #ifdef _GNU_SOURCE 12 | #define uh_sport source 13 | #define uh_dport dest 14 | #define uh_ulen len 15 | #define uh_sum check 16 | #endif 17 | 18 | struct udphdr { 19 | uint16_t uh_sport; 20 | uint16_t uh_dport; 21 | uint16_t uh_ulen; 22 | uint16_t uh_sum; 23 | }; 24 | 25 | #define UDP_CORK 1 26 | #define UDP_ENCAP 100 27 | #define UDP_NO_CHECK6_TX 101 28 | #define UDP_NO_CHECK6_RX 102 29 | #define UDP_SEGMENT 103 30 | #define UDP_GRO 104 31 | 32 | #define UDP_ENCAP_ESPINUDP_NON_IKE 1 33 | #define UDP_ENCAP_ESPINUDP 2 34 | #define UDP_ENCAP_L2TPINUDP 3 35 | #define UDP_ENCAP_GTP0 4 36 | #define UDP_ENCAP_GTP1U 5 37 | #define UDP_ENCAP_RXRPC 6 38 | #define TCP_ENCAP_ESPINTCP 7 39 | 40 | #define SOL_UDP 17 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /target/usr/include/arpa/ftp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARPA_FTP_H 2 | #define _ARPA_FTP_H 3 | #define PRELIM 1 4 | #define COMPLETE 2 5 | #define CONTINUE 3 6 | #define TRANSIENT 4 7 | #define ERROR 5 8 | #define TYPE_A 1 9 | #define TYPE_E 2 10 | #define TYPE_I 3 11 | #define TYPE_L 4 12 | #define FORM_N 1 13 | #define FORM_T 2 14 | #define FORM_C 3 15 | #define STRU_F 1 16 | #define STRU_R 2 17 | #define STRU_P 3 18 | #define MODE_S 1 19 | #define MODE_B 2 20 | #define MODE_C 3 21 | #define REC_ESC '\377' 22 | #define REC_EOR '\001' 23 | #define REC_EOF '\002' 24 | #define BLK_EOR 0x80 25 | #define BLK_EOF 0x40 26 | #define BLK_ERRORS 0x20 27 | #define BLK_RESTART 0x10 28 | #define BLK_BYTECOUNT 2 29 | #ifdef FTP_NAMES 30 | char *modenames[] = {"0", "Stream", "Block", "Compressed" }; 31 | char *strunames[] = {"0", "File", "Record", "Page" }; 32 | char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; 33 | char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; 34 | #endif 35 | #endif 36 | -------------------------------------------------------------------------------- /target/usr/include/semaphore.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEMAPHORE_H 2 | #define _SEMAPHORE_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #define __NEED_time_t 10 | #define __NEED_struct_timespec 11 | #include 12 | 13 | #include 14 | 15 | #define SEM_FAILED ((sem_t *)0) 16 | 17 | typedef struct { 18 | volatile int __val[4*sizeof(long)/sizeof(int)]; 19 | } sem_t; 20 | 21 | int sem_close(sem_t *); 22 | int sem_destroy(sem_t *); 23 | int sem_getvalue(sem_t *__restrict, int *__restrict); 24 | int sem_init(sem_t *, int, unsigned); 25 | sem_t *sem_open(const char *, int, ...); 26 | int sem_post(sem_t *); 27 | int sem_timedwait(sem_t *__restrict, const struct timespec *__restrict); 28 | int sem_trywait(sem_t *); 29 | int sem_unlink(const char *); 30 | int sem_wait(sem_t *); 31 | 32 | #if _REDIR_TIME64 33 | __REDIR(sem_timedwait, __sem_timedwait_time64); 34 | #endif 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /target/usr/include/sys/ttydefaults.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TTYDEFAULTS_H 2 | #define _SYS_TTYDEFAULTS_H 3 | 4 | #define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY) 5 | #define TTYDEF_OFLAG (OPOST | ONLCR | XTABS) 6 | #define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) 7 | #define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL) 8 | #define TTYDEF_SPEED (B9600) 9 | #define CTRL(x) ((x)&037) 10 | #define CEOF CTRL('d') 11 | 12 | #define CEOL '\0' 13 | #define CSTATUS '\0' 14 | 15 | #define CERASE 0177 16 | #define CINTR CTRL('c') 17 | #define CKILL CTRL('u') 18 | #define CMIN 1 19 | #define CQUIT 034 20 | #define CSUSP CTRL('z') 21 | #define CTIME 0 22 | #define CDSUSP CTRL('y') 23 | #define CSTART CTRL('q') 24 | #define CSTOP CTRL('s') 25 | #define CLNEXT CTRL('v') 26 | #define CDISCARD CTRL('o') 27 | #define CWERASE CTRL('w') 28 | #define CREPRINT CTRL('r') 29 | #define CEOT CEOF 30 | #define CBRK CEOL 31 | #define CRPRNT CREPRINT 32 | #define CFLUSH CDISCARD 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /target/root/.bashrc: -------------------------------------------------------------------------------- 1 | # System wide environment variables and startup programs should go into 2 | # /etc/profile. Personal environment variables and startup programs 3 | # should go into ~/.bash_profile. Personal aliases and functions should 4 | # go into ~/.bashrc 5 | 6 | # Provides colored /bin/ls and /bin/grep commands. Used in conjunction 7 | # with code in /etc/profile. 8 | source /etc/profile 9 | 10 | # Only if nothing has already set it (like a terminal emulator) 11 | if [ -z "${TERM}" ] || [ "${TERM}" == "dumb" ]; then 12 | export TERM=linux 13 | fi 14 | 15 | alias ls='ls --color=auto' 16 | alias grep='grep --color=auto' 17 | alias dir="dir --color=auto" 18 | alias mpv="mpv -no-audio" 19 | 20 | # some helpful aliases 21 | alias a="rm -f /var/log/Xorg.0.log && echo d > /sys/cavosConsole && xinit && echo e > /sys/cavosConsole" 22 | alias b="wget -O /dev/null https://ash-speed.hetzner.com/1GB.bin" 23 | alias c="/usr/libexec/webkit2gtk-4.1/MiniBrowser" 24 | alias d="mpv -no-audio --player-operation-mode=pseudo-gui" 25 | -------------------------------------------------------------------------------- /target/usr/include/dlfcn.h: -------------------------------------------------------------------------------- 1 | #ifndef _DLFCN_H 2 | #define _DLFCN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define RTLD_LAZY 1 11 | #define RTLD_NOW 2 12 | #define RTLD_NOLOAD 4 13 | #define RTLD_NODELETE 4096 14 | #define RTLD_GLOBAL 256 15 | #define RTLD_LOCAL 0 16 | 17 | #define RTLD_NEXT ((void *)-1) 18 | #define RTLD_DEFAULT ((void *)0) 19 | 20 | #define RTLD_DI_LINKMAP 2 21 | 22 | int dlclose(void *); 23 | char *dlerror(void); 24 | void *dlopen(const char *, int); 25 | void *dlsym(void *__restrict, const char *__restrict); 26 | 27 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 28 | typedef struct { 29 | const char *dli_fname; 30 | void *dli_fbase; 31 | const char *dli_sname; 32 | void *dli_saddr; 33 | } Dl_info; 34 | int dladdr(const void *, Dl_info *); 35 | int dlinfo(void *, int, void *); 36 | #endif 37 | 38 | #if _REDIR_TIME64 39 | __REDIR(dlsym, __dlsym_time64); 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/kernel/networking/stack/netqueue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Internal queue driven mechanism to avoid thread complications 6 | // Copyright (C) 2025 Panagiotis 7 | 8 | void netQueueMainCb(void *data, void *ctx) { 9 | netQueueItem *item = data; 10 | if (item->callback) 11 | item->callback(item); 12 | } 13 | 14 | // every once in a while have this be ran to check various states, maintain 15 | // timeouts, re-send stuff, etc 16 | void helperNetQueue() { 17 | spinlockAcquire(&LOCK_LL_NET_QUEUE); 18 | LinkedListTraverse(&dsNetQueue, netQueueMainCb, 0); 19 | spinlockRelease(&LOCK_LL_NET_QUEUE); 20 | } 21 | 22 | // MAKE SURE YOU LOCK BEFORE USING THIS! 23 | netQueueItem *netQueueAllocateM(netQueueComp component, void *nic) { 24 | netQueueItem *item = LinkedListAllocate(&dsNetQueue, sizeof(netQueueItem)); 25 | item->component = component; 26 | item->unixTime = timerTicks; 27 | item->task = currentTask; 28 | item->nic = nic; 29 | return item; 30 | } 31 | -------------------------------------------------------------------------------- /target/usr/include/values.h: -------------------------------------------------------------------------------- 1 | #ifndef _VALUES_H 2 | #define _VALUES_H 3 | 4 | #include 5 | 6 | #define CHARBITS (sizeof(char) * 8) 7 | #define SHORTBITS (sizeof(short) * 8) 8 | #define INTBITS (sizeof(int) * 8) 9 | #define LONGBITS (sizeof(long) * 8) 10 | #define PTRBITS (sizeof(char *) * 8) 11 | #define DOUBLEBITS (sizeof(double) * 8) 12 | #define FLOATBITS (sizeof(float) * 8) 13 | 14 | #define MINSHORT SHRT_MIN 15 | #define MININT INT_MIN 16 | #define MINLONG LONG_MIN 17 | 18 | #define MAXSHORT SHRT_MAX 19 | #define MAXINT INT_MAX 20 | #define MAXLONG LONG_MAX 21 | 22 | #define HIBITS MINSHORT 23 | #define HIBITL MINLONG 24 | 25 | #include 26 | 27 | #define MAXDOUBLE DBL_MAX 28 | #undef MAXFLOAT 29 | #define MAXFLOAT FLT_MAX 30 | #define MINDOUBLE DBL_MIN 31 | #define MINFLOAT FLT_MIN 32 | #define DMINEXP DBL_MIN_EXP 33 | #define FMINEXP FLT_MIN_EXP 34 | #define DMAXEXP DBL_MAX_EXP 35 | #define FMAXEXP FLT_MAX_EXP 36 | 37 | #define BITSPERBYTE CHAR_BIT 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /target/usr/include/libintl.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBINTL_H 2 | #define _LIBINTL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __USE_GNU_GETTEXT 1 9 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 1 : -1) 10 | 11 | #if __GNUC__ >= 3 12 | #define __fa(n) __attribute__ ((__format_arg__ (n))) 13 | #else 14 | #define __fa(n) 15 | #endif 16 | 17 | char *gettext(const char *) __fa(1); 18 | char *dgettext(const char *, const char *) __fa(2); 19 | char *dcgettext(const char *, const char *, int) __fa(2); 20 | char *ngettext(const char *, const char *, unsigned long) __fa(1) __fa(2); 21 | char *dngettext(const char *, const char *, const char *, unsigned long) __fa(2) __fa(3); 22 | char *dcngettext(const char *, const char *, const char *, unsigned long, int) __fa(2) __fa(3); 23 | char *textdomain(const char *); 24 | char *bindtextdomain (const char *, const char *); 25 | char *bind_textdomain_codeset(const char *, const char *); 26 | 27 | #undef __fa 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/kernel/utilities/dents.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // getdents64() directory entry helper 5 | // Copyright (C) 2024 Panagiotis 6 | 7 | DENTS_RES dentsAdd(void *buffStart, struct linux_dirent64 **dirp, 8 | size_t *allocatedlimit, unsigned int hardlimit, 9 | char *filename, size_t filenameLength, size_t inode, 10 | unsigned char type) { 11 | size_t reclen = 23 + filenameLength + 1; 12 | if ((*allocatedlimit + reclen + 2) > hardlimit) { 13 | if (*allocatedlimit) 14 | return DENTS_RETURN; 15 | else 16 | return DENTS_NO_SPACE; 17 | } 18 | 19 | (*dirp)->d_reclen = reclen; 20 | (*dirp)->d_ino = inode; 21 | (*dirp)->d_off = rand(); // xd 22 | (*dirp)->d_type = type; 23 | 24 | memcpy((*dirp)->d_name, filename, filenameLength); 25 | (*dirp)->d_name[filenameLength] = '\0'; 26 | 27 | *allocatedlimit = *allocatedlimit + reclen; 28 | *dirp = (struct linux_dirent64 *)((size_t)(*dirp) + reclen); 29 | 30 | return DENTS_SUCCESS; 31 | } 32 | -------------------------------------------------------------------------------- /target/usr/include/mntent.h: -------------------------------------------------------------------------------- 1 | #ifndef _MNTENT_H 2 | #define _MNTENT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define __NEED_FILE 9 | #include 10 | 11 | #define MOUNTED "/etc/mtab" 12 | 13 | #define MNTTYPE_IGNORE "ignore" 14 | #define MNTTYPE_NFS "nfs" 15 | #define MNTTYPE_SWAP "swap" 16 | #define MNTOPT_DEFAULTS "defaults" 17 | #define MNTOPT_RO "ro" 18 | #define MNTOPT_RW "rw" 19 | #define MNTOPT_SUID "suid" 20 | #define MNTOPT_NOSUID "nosuid" 21 | #define MNTOPT_NOAUTO "noauto" 22 | 23 | struct mntent { 24 | char *mnt_fsname; 25 | char *mnt_dir; 26 | char *mnt_type; 27 | char *mnt_opts; 28 | int mnt_freq; 29 | int mnt_passno; 30 | }; 31 | 32 | FILE *setmntent(const char *, const char *); 33 | int endmntent(FILE *); 34 | struct mntent *getmntent(FILE *); 35 | struct mntent *getmntent_r(FILE *, struct mntent *, char *, int); 36 | int addmntent(FILE *, const struct mntent *); 37 | char *hasmntopt(const struct mntent *, const char *); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/kernel/include/rtl8139.h: -------------------------------------------------------------------------------- 1 | #include "nic_controller.h" 2 | #include "pci.h" 3 | #include "types.h" 4 | 5 | #ifndef RTL8139_H 6 | #define RTL8139_H 7 | 8 | enum RTL8139Status { 9 | RTL8139_STATUS_TOK = (1 << 2), 10 | RTL8139_STATUS_ROK = (1 << 0) 11 | }; 12 | 13 | enum RTL8139Registers { 14 | RTL8139_REG_MAC0_5 = 0x00, 15 | RTL8139_REG_MAC5_6 = 0x04, 16 | RTL8139_REG_MAR0_7 = 0x08, 17 | RTL8139_REG_RBSTART = 0x30, 18 | RTL8139_REG_CMD = 0x37, 19 | RTL8139_REG_IMR = 0x3C, 20 | RTL8139_REG_ISR = 0x3E, 21 | 22 | RTL8139_REG_POWERUP = 0x52 23 | }; 24 | 25 | typedef struct rtl8139_interface { 26 | uint16_t iobase; 27 | uint8_t tx_curr; 28 | void *rx_buff_virtual; // physical can be computed if needed 29 | uint8_t tok; // bitmap for OK transfers 30 | uint32_t currentPacket; // track current packet (when receiving) 31 | } rtl8139_interface; 32 | 33 | bool initiateRTL8139(PCIdevice *device); 34 | void sendRTL8139(NIC *nic, void *packet, uint32_t packetSize); 35 | void receiveRTL8139(NIC *nic); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /target/usr/include/paths.h: -------------------------------------------------------------------------------- 1 | #ifndef _PATHS_H 2 | #define _PATHS_H 3 | 4 | #define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin" 5 | #define _PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin" 6 | 7 | #define _PATH_BSHELL "/bin/sh" 8 | #define _PATH_CONSOLE "/dev/console" 9 | #define _PATH_DEVNULL "/dev/null" 10 | #define _PATH_KLOG "/proc/kmsg" 11 | #define _PATH_LASTLOG "/var/log/lastlog" 12 | #define _PATH_MAILDIR "/var/mail" 13 | #define _PATH_MAN "/usr/share/man" 14 | #define _PATH_MNTTAB "/etc/fstab" 15 | #define _PATH_MOUNTED "/etc/mtab" 16 | #define _PATH_NOLOGIN "/etc/nologin" 17 | #define _PATH_SENDMAIL "/usr/sbin/sendmail" 18 | #define _PATH_SHADOW "/etc/shadow" 19 | #define _PATH_SHELLS "/etc/shells" 20 | #define _PATH_TTY "/dev/tty" 21 | #define _PATH_UTMP "/dev/null/utmp" 22 | #define _PATH_VI "/usr/bin/vi" 23 | #define _PATH_WTMP "/dev/null/wtmp" 24 | 25 | #define _PATH_DEV "/dev/" 26 | #define _PATH_TMP "/tmp/" 27 | #define _PATH_VARDB "/var/lib/misc/" 28 | #define _PATH_VARRUN "/var/run/" 29 | #define _PATH_VARTMP "/var/tmp/" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /target/usr/include/features.h: -------------------------------------------------------------------------------- 1 | #ifndef _FEATURES_H 2 | #define _FEATURES_H 3 | 4 | #if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) 5 | #define _GNU_SOURCE 1 6 | #endif 7 | 8 | #if defined(_DEFAULT_SOURCE) && !defined(_BSD_SOURCE) 9 | #define _BSD_SOURCE 1 10 | #endif 11 | 12 | #if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ 13 | && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \ 14 | && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__) 15 | #define _BSD_SOURCE 1 16 | #define _XOPEN_SOURCE 700 17 | #endif 18 | 19 | #if __STDC_VERSION__ >= 199901L 20 | #define __restrict restrict 21 | #elif !defined(__GNUC__) 22 | #define __restrict 23 | #endif 24 | 25 | #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) 26 | #define __inline inline 27 | #elif !defined(__GNUC__) 28 | #define __inline 29 | #endif 30 | 31 | #if __STDC_VERSION__ >= 201112L 32 | #elif defined(__GNUC__) 33 | #define _Noreturn __attribute__((__noreturn__)) 34 | #else 35 | #define _Noreturn 36 | #endif 37 | 38 | #define __REDIR(x,y) __typeof__(x) x __asm__(#y) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/kernel/include/bootloader.h: -------------------------------------------------------------------------------- 1 | #include "limine.h" 2 | #include "types.h" 3 | 4 | #ifndef BOOTLOADER_H 5 | #define BOOTLOADER_H 6 | 7 | // From the linker 8 | extern uint64_t kernel_text_start, kernel_text_end; 9 | extern uint64_t kernel_rodata_start, kernel_rodata_end; 10 | extern uint64_t kernel_data_start, kernel_data_end; 11 | extern uint64_t kernel_start, kernel_end; 12 | 13 | typedef struct Bootloader { 14 | size_t hhdmOffset; 15 | size_t kernelVirtBase; 16 | size_t kernelPhysBase; 17 | 18 | size_t rsdp; 19 | 20 | size_t mmTotal; 21 | uint64_t mmEntryCnt; 22 | LIMINE_PTR(struct limine_memmap_entry **) mmEntries; 23 | LIMINE_PTR(struct limine_smp_response *) smp; 24 | uint64_t smpBspIndex; 25 | } Bootloader; 26 | 27 | Bootloader bootloader; 28 | 29 | #define IS_INSIDE_HHDM(a) \ 30 | ((size_t)a >= bootloader.hhdmOffset && \ 31 | (size_t)a <= (bootloader.hhdmOffset + bootloader.mmTotal)) 32 | 33 | void initialiseBootloaderParser(); 34 | 35 | #endif -------------------------------------------------------------------------------- /src/software/test/utils.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | int main(int argc, char **argv); 4 | 5 | uint16_t strlength(char *ch) { 6 | uint16_t i = 0; // Changed counter to 0 7 | while (ch[i++]) 8 | ; 9 | return i - 1; // Changed counter to i instead of i-- 10 | } 11 | 12 | int atoi(char *str) { 13 | int res = 0; 14 | 15 | for (int i = 0; str[i] != '\0'; ++i) 16 | res = res * 10 + str[i] - '0'; 17 | 18 | return res; 19 | } 20 | 21 | void reverse(char s[]) { 22 | int i, j; 23 | char c; 24 | 25 | for (i = 0, j = strlength(s) - 1; i < j; i++, j--) { 26 | c = s[i]; 27 | s[i] = s[j]; 28 | s[j] = c; 29 | } 30 | } 31 | 32 | void itoa(int n, char s[]) { 33 | int i, sign; 34 | 35 | if ((sign = n) < 0) /* record sign */ 36 | n = -n; /* make n positive */ 37 | i = 0; 38 | do { /* generate digits in reverse order */ 39 | s[i++] = n % 10 + '0'; /* get next digit */ 40 | } while ((n /= 10) > 0); /* delete it */ 41 | if (sign < 0) 42 | s[i++] = '-'; 43 | s[i] = '\0'; 44 | reverse(s); 45 | } 46 | -------------------------------------------------------------------------------- /target/usr/include/sys/xattr.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_XATTR_H 2 | #define _SYS_XATTR_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define __NEED_ssize_t 8 | #define __NEED_size_t 9 | #include 10 | 11 | #define XATTR_CREATE 1 12 | #define XATTR_REPLACE 2 13 | 14 | ssize_t getxattr(const char *, const char *, void *, size_t); 15 | ssize_t lgetxattr(const char *, const char *, void *, size_t); 16 | ssize_t fgetxattr(int, const char *, void *, size_t); 17 | ssize_t listxattr(const char *, char *, size_t); 18 | ssize_t llistxattr(const char *, char *, size_t); 19 | ssize_t flistxattr(int, char *, size_t); 20 | int setxattr(const char *, const char *, const void *, size_t, int); 21 | int lsetxattr(const char *, const char *, const void *, size_t, int); 22 | int fsetxattr(int, const char *, const void *, size_t, int); 23 | int removexattr(const char *, const char *); 24 | int lremovexattr(const char *, const char *); 25 | int fremovexattr(int, const char *); 26 | 27 | #define __UAPI_DEF_XATTR 0 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif 33 | -------------------------------------------------------------------------------- /target/usr/include/sys/signalfd.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SIGNALFD_H 2 | #define _SYS_SIGNALFD_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #define __NEED_sigset_t 12 | 13 | #include 14 | 15 | #define SFD_CLOEXEC O_CLOEXEC 16 | #define SFD_NONBLOCK O_NONBLOCK 17 | 18 | int signalfd(int, const sigset_t *, int); 19 | 20 | struct signalfd_siginfo { 21 | uint32_t ssi_signo; 22 | int32_t ssi_errno; 23 | int32_t ssi_code; 24 | uint32_t ssi_pid; 25 | uint32_t ssi_uid; 26 | int32_t ssi_fd; 27 | uint32_t ssi_tid; 28 | uint32_t ssi_band; 29 | uint32_t ssi_overrun; 30 | uint32_t ssi_trapno; 31 | int32_t ssi_status; 32 | int32_t ssi_int; 33 | uint64_t ssi_ptr; 34 | uint64_t ssi_utime; 35 | uint64_t ssi_stime; 36 | uint64_t ssi_addr; 37 | uint16_t ssi_addr_lsb; 38 | uint16_t __pad2; 39 | int32_t ssi_syscall; 40 | uint64_t ssi_call_addr; 41 | uint32_t ssi_arch; 42 | uint8_t __pad[128-14*4-5*8-2*2]; 43 | }; 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/kernel/include/ne2k.h: -------------------------------------------------------------------------------- 1 | #include "nic_controller.h" 2 | #include "pci.h" 3 | #include "types.h" 4 | 5 | #ifndef NE2K_H 6 | #define NE2K_H 7 | 8 | enum NE2KRegisters { 9 | NE2K_REG_COMMAND = 0x00, 10 | NE2K_REG_CLDA0 = 0x01, 11 | NE2K_REG_CLDA1 = 0x02, 12 | NE2K_REG_BNRY = 0x03, 13 | NE2K_REG_TSR = 0x04, 14 | NE2K_REG_NCR = 0x05, 15 | NE2K_REG_FIFO = 0x06, 16 | NE2K_REG_ISR = 0x07, 17 | NE2K_REG_CRDA0 = 0x08, 18 | NE2K_REG_CRDA1 = 0x09, 19 | NE2K_REG_RSR = 0x0C, 20 | 21 | NE2K_REG_PSTART = 0x01, 22 | NE2K_REG_PSTOP = 0x02, 23 | NE2K_REG_TPSR = 0x04, 24 | NE2K_REG_TBCR0 = 0x05, 25 | NE2K_REG_TBCR1 = 0x06, 26 | 27 | NE2K_REG_RSAR0 = 0x08, 28 | NE2K_REG_RSAR1 = 0x09, 29 | NE2K_REG_RBCR0 = 0x0A, 30 | NE2K_REG_RBCR1 = 0x0B, 31 | NE2K_REG_RCR = 0x0C, 32 | NE2K_REG_TCR = 0x0D, 33 | NE2K_REG_DCR = 0x0E, 34 | NE2K_REG_IMR = 0x0F, 35 | 36 | NE2K_REG_DATA = 0x10, 37 | }; 38 | 39 | typedef struct ne2k_interface { 40 | uint16_t iobase; 41 | } ne2k_interface; 42 | 43 | bool initiateNe2000(PCIdevice *device); 44 | void sendNe2000(NIC *nic, void *packet, uint32_t packetSize); 45 | 46 | #endif -------------------------------------------------------------------------------- /target/usr/include/pwd.h: -------------------------------------------------------------------------------- 1 | #ifndef _PWD_H 2 | #define _PWD_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | #define __NEED_uid_t 12 | #define __NEED_gid_t 13 | 14 | #ifdef _GNU_SOURCE 15 | #define __NEED_FILE 16 | #endif 17 | 18 | #include 19 | 20 | struct passwd { 21 | char *pw_name; 22 | char *pw_passwd; 23 | uid_t pw_uid; 24 | gid_t pw_gid; 25 | char *pw_gecos; 26 | char *pw_dir; 27 | char *pw_shell; 28 | }; 29 | 30 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 31 | void setpwent (void); 32 | void endpwent (void); 33 | struct passwd *getpwent (void); 34 | #endif 35 | 36 | struct passwd *getpwuid (uid_t); 37 | struct passwd *getpwnam (const char *); 38 | int getpwuid_r (uid_t, struct passwd *, char *, size_t, struct passwd **); 39 | int getpwnam_r (const char *, struct passwd *, char *, size_t, struct passwd **); 40 | 41 | #ifdef _GNU_SOURCE 42 | struct passwd *fgetpwent(FILE *); 43 | int putpwent(const struct passwd *, FILE *); 44 | #endif 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /target/usr/include/glob.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLOB_H 2 | #define _GLOB_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | 12 | #include 13 | 14 | typedef struct { 15 | size_t gl_pathc; 16 | char **gl_pathv; 17 | size_t gl_offs; 18 | int __dummy1; 19 | void *__dummy2[5]; 20 | } glob_t; 21 | 22 | int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict); 23 | void globfree(glob_t *); 24 | 25 | #define GLOB_ERR 0x01 26 | #define GLOB_MARK 0x02 27 | #define GLOB_NOSORT 0x04 28 | #define GLOB_DOOFFS 0x08 29 | #define GLOB_NOCHECK 0x10 30 | #define GLOB_APPEND 0x20 31 | #define GLOB_NOESCAPE 0x40 32 | #define GLOB_PERIOD 0x80 33 | 34 | #define GLOB_TILDE 0x1000 35 | #define GLOB_TILDE_CHECK 0x4000 36 | 37 | #define GLOB_NOSPACE 1 38 | #define GLOB_ABORTED 2 39 | #define GLOB_NOMATCH 3 40 | #define GLOB_NOSYS 4 41 | 42 | #if defined(_LARGEFILE64_SOURCE) 43 | #define glob64 glob 44 | #define globfree64 globfree 45 | #define glob64_t glob_t 46 | #endif 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /target/usr/include/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRINGS_H 2 | #define _STRINGS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | #define __NEED_locale_t 12 | #include 13 | 14 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ 15 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ 16 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) 17 | int bcmp (const void *, const void *, size_t); 18 | void bcopy (const void *, void *, size_t); 19 | void bzero (void *, size_t); 20 | char *index (const char *, int); 21 | char *rindex (const char *, int); 22 | #endif 23 | 24 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 25 | int ffs (int); 26 | int ffsl (long); 27 | int ffsll (long long); 28 | #endif 29 | 30 | int strcasecmp (const char *, const char *); 31 | int strncasecmp (const char *, const char *, size_t); 32 | 33 | int strcasecmp_l (const char *, const char *, locale_t); 34 | int strncasecmp_l (const char *, const char *, size_t, locale_t); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /target/usr/include/bits/fcntl.h: -------------------------------------------------------------------------------- 1 | #define O_CREAT 0100 2 | #define O_EXCL 0200 3 | #define O_NOCTTY 0400 4 | #define O_TRUNC 01000 5 | #define O_APPEND 02000 6 | #define O_NONBLOCK 04000 7 | #define O_DSYNC 010000 8 | #define O_SYNC 04010000 9 | #define O_RSYNC 04010000 10 | #define O_DIRECTORY 0200000 11 | #define O_NOFOLLOW 0400000 12 | #define O_CLOEXEC 02000000 13 | 14 | #define O_ASYNC 020000 15 | #define O_DIRECT 040000 16 | #define O_LARGEFILE 0100000 17 | #define O_NOATIME 01000000 18 | #define O_PATH 010000000 19 | #define O_TMPFILE 020200000 20 | #define O_NDELAY O_NONBLOCK 21 | 22 | #define F_DUPFD 0 23 | #define F_GETFD 1 24 | #define F_SETFD 2 25 | #define F_GETFL 3 26 | #define F_SETFL 4 27 | 28 | #define F_SETOWN 8 29 | #define F_GETOWN 9 30 | #define F_SETSIG 10 31 | #define F_GETSIG 11 32 | 33 | #if __LONG_MAX == 0x7fffffffL 34 | #define F_GETLK 12 35 | #define F_SETLK 13 36 | #define F_SETLKW 14 37 | #else 38 | #define F_GETLK 5 39 | #define F_SETLK 6 40 | #define F_SETLKW 7 41 | #endif 42 | 43 | #define F_SETOWN_EX 15 44 | #define F_GETOWN_EX 16 45 | 46 | #define F_GETOWNER_UIDS 17 47 | -------------------------------------------------------------------------------- /target/usr/include/link.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINK_H 2 | #define _LINK_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #define __NEED_size_t 10 | #define __NEED_uint32_t 11 | #include 12 | 13 | #if UINTPTR_MAX > 0xffffffff 14 | #define ElfW(type) Elf64_ ## type 15 | #else 16 | #define ElfW(type) Elf32_ ## type 17 | #endif 18 | 19 | #include 20 | 21 | struct dl_phdr_info { 22 | ElfW(Addr) dlpi_addr; 23 | const char *dlpi_name; 24 | const ElfW(Phdr) *dlpi_phdr; 25 | ElfW(Half) dlpi_phnum; 26 | unsigned long long int dlpi_adds; 27 | unsigned long long int dlpi_subs; 28 | size_t dlpi_tls_modid; 29 | void *dlpi_tls_data; 30 | }; 31 | 32 | struct link_map { 33 | ElfW(Addr) l_addr; 34 | char *l_name; 35 | ElfW(Dyn) *l_ld; 36 | struct link_map *l_next, *l_prev; 37 | }; 38 | 39 | struct r_debug { 40 | int r_version; 41 | struct link_map *r_map; 42 | ElfW(Addr) r_brk; 43 | enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state; 44 | ElfW(Addr) r_ldbase; 45 | }; 46 | 47 | int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /target/usr/include/sys/msg.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_MSG_H 2 | #define _SYS_MSG_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_pid_t 11 | #define __NEED_key_t 12 | #define __NEED_time_t 13 | #define __NEED_size_t 14 | #define __NEED_ssize_t 15 | 16 | #include 17 | 18 | typedef unsigned long msgqnum_t; 19 | typedef unsigned long msglen_t; 20 | 21 | #include 22 | 23 | #define __msg_cbytes msg_cbytes 24 | 25 | #define MSG_NOERROR 010000 26 | #define MSG_EXCEPT 020000 27 | 28 | #define MSG_STAT (11 | (IPC_STAT & 0x100)) 29 | #define MSG_INFO 12 30 | #define MSG_STAT_ANY (13 | (IPC_STAT & 0x100)) 31 | 32 | struct msginfo { 33 | int msgpool, msgmap, msgmax, msgmnb, msgmni, msgssz, msgtql; 34 | unsigned short msgseg; 35 | }; 36 | 37 | int msgctl (int, int, struct msqid_ds *); 38 | int msgget (key_t, int); 39 | ssize_t msgrcv (int, void *, size_t, long, int); 40 | int msgsnd (int, const void *, size_t, int); 41 | 42 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 43 | struct msgbuf { 44 | long mtype; 45 | char mtext[1]; 46 | }; 47 | #endif 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /tools/toy/png_to_cavimg.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PIL import Image 3 | import numpy as np 4 | 5 | def resize_image(input_path, output_path, target_width, target_height): 6 | with Image.open(input_path) as img: 7 | original_width, original_height = img.size 8 | ratio = min(target_width / original_width, target_height / original_height) 9 | new_size = (int(original_width * ratio), int(original_height * ratio)) 10 | img_resized = img.resize(new_size, Image.Resampling.LANCZOS) 11 | new_img = Image.new("RGB", (target_width, target_height), (0, 0, 0)) 12 | new_img.paste(img_resized, ((target_width - new_size[0]) // 2, (target_height - new_size[1]) // 2)) 13 | rgb_values = np.array(new_img) 14 | hex_values = bytearray(rgb_values.flatten()) 15 | with open(output_path, 'wb') as file: 16 | file.write(hex_values) 17 | if __name__ == "__main__": 18 | if len(sys.argv) != 3: 19 | print("Usage: python png_to_cavimg ") 20 | sys.exit(1) 21 | input_file = sys.argv[1] 22 | output_file = sys.argv[2] 23 | 24 | resize_image(input_file, output_file, 800, 600) -------------------------------------------------------------------------------- /target/usr/include/termios.h: -------------------------------------------------------------------------------- 1 | #ifndef _TERMIOS_H 2 | #define _TERMIOS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_pid_t 11 | #define __NEED_struct_winsize 12 | 13 | #include 14 | 15 | typedef unsigned char cc_t; 16 | typedef unsigned int speed_t; 17 | typedef unsigned int tcflag_t; 18 | 19 | #define NCCS 32 20 | 21 | #include 22 | 23 | speed_t cfgetospeed (const struct termios *); 24 | speed_t cfgetispeed (const struct termios *); 25 | int cfsetospeed (struct termios *, speed_t); 26 | int cfsetispeed (struct termios *, speed_t); 27 | 28 | int tcgetattr (int, struct termios *); 29 | int tcsetattr (int, int, const struct termios *); 30 | 31 | int tcgetwinsize (int, struct winsize *); 32 | int tcsetwinsize (int, const struct winsize *); 33 | 34 | int tcsendbreak (int, int); 35 | int tcdrain (int); 36 | int tcflush (int, int); 37 | int tcflow (int, int); 38 | 39 | pid_t tcgetsid (int); 40 | 41 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 42 | void cfmakeraw(struct termios *); 43 | int cfsetspeed(struct termios *, speed_t); 44 | #endif 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /target/usr/include/setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _SETJMP_H 2 | #define _SETJMP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #include 11 | 12 | typedef struct __jmp_buf_tag { 13 | __jmp_buf __jb; 14 | unsigned long __fl; 15 | unsigned long __ss[128/sizeof(long)]; 16 | } jmp_buf[1]; 17 | 18 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) 19 | #define __setjmp_attr __attribute__((__returns_twice__)) 20 | #else 21 | #define __setjmp_attr 22 | #endif 23 | 24 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 25 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 26 | || defined(_BSD_SOURCE) 27 | typedef jmp_buf sigjmp_buf; 28 | int sigsetjmp (sigjmp_buf, int) __setjmp_attr; 29 | _Noreturn void siglongjmp (sigjmp_buf, int); 30 | #endif 31 | 32 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 33 | || defined(_BSD_SOURCE) 34 | int _setjmp (jmp_buf) __setjmp_attr; 35 | _Noreturn void _longjmp (jmp_buf, int); 36 | #endif 37 | 38 | int setjmp (jmp_buf) __setjmp_attr; 39 | _Noreturn void longjmp (jmp_buf, int); 40 | 41 | #define setjmp setjmp 42 | 43 | #undef __setjmp_attr 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/kernel/include/eth.h: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #ifndef NET_ETH_H 4 | #define NET_ETH_H 5 | 6 | #define ETHERTYPE_PUP 0x0200 7 | #define ETHERTYPE_SPRITE 0x0500 8 | #define ETHERTYPE_IP 0x0800 9 | #define ETHERTYPE_ARP 0x0806 10 | #define ETHERTYPE_REVARP 0x8035 11 | #define ETHERTYPE_AT 0x809B 12 | #define ETHERTYPE_AARP 0x80F3 13 | #define ETHERTYPE_VLAN 0x8100 14 | #define ETHERTYPE_IPX 0x8137 15 | #define ETHERTYPE_IPV6 0x86dd 16 | #define ETHERTYPE_LOOPBACK 0x9000 17 | 18 | #define MAC_BYTE_SIZE 6 // MAC addresses are always 6 bytes long 19 | #define IPv4_BYTE_SIZE 4 // IPv4 addresses are always 4 bytes long 20 | 21 | typedef struct ethHeader { 22 | uint8_t dest[MAC_BYTE_SIZE]; 23 | uint8_t src[MAC_BYTE_SIZE]; 24 | uint16_t type; // ethertype 25 | } __attribute__((packed)) ethHeader; 26 | 27 | void netEthHandle(void *_nic, void *packet, uint32_t size); 28 | void netEthSend(void *_nic, void *packet, uint32_t size, uint8_t *targetMac, 29 | uint16_t ethertype); 30 | 31 | uint8_t macBroadcast[MAC_BYTE_SIZE]; 32 | uint8_t macZero[MAC_BYTE_SIZE]; 33 | uint8_t addressNull[IPv4_BYTE_SIZE]; 34 | uint8_t addressBroadcast[IPv4_BYTE_SIZE]; 35 | 36 | void dbgMac(uint8_t *mac); 37 | void dbgIp(uint8_t *ip); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /target/usr/include/utmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTMP_H 2 | #define _UTMP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define ACCOUNTING 9 11 | #define UT_NAMESIZE 32 12 | #define UT_HOSTSIZE 256 13 | #define UT_LINESIZE 32 14 | 15 | struct lastlog { 16 | time_t ll_time; 17 | char ll_line[UT_LINESIZE]; 18 | char ll_host[UT_HOSTSIZE]; 19 | }; 20 | 21 | #define ut_time ut_tv.tv_sec 22 | #define ut_name ut_user 23 | #define ut_addr ut_addr_v6[0] 24 | #define utmp utmpx 25 | #define e_exit __e_exit 26 | #define e_termination __e_termination 27 | 28 | void endutent(void); 29 | struct utmp *getutent(void); 30 | struct utmp *getutid(const struct utmp *); 31 | struct utmp *getutline(const struct utmp *); 32 | struct utmp *pututline(const struct utmp *); 33 | void setutent(void); 34 | 35 | void updwtmp(const char *, const struct utmp *); 36 | int utmpname(const char *); 37 | 38 | int login_tty(int); 39 | 40 | #define _PATH_UTMP "/dev/null/utmp" 41 | #define _PATH_WTMP "/dev/null/wtmp" 42 | 43 | #define UTMP_FILE _PATH_UTMP 44 | #define WTMP_FILE _PATH_WTMP 45 | #define UTMP_FILENAME _PATH_UTMP 46 | #define WTMP_FILENAME _PATH_WTMP 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /target/usr/include/netinet/igmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _NETINET_IGMP_H 2 | #define _NETINET_IGMP_H 3 | 4 | #include 5 | #include 6 | 7 | struct igmp { 8 | uint8_t igmp_type; 9 | uint8_t igmp_code; 10 | uint16_t igmp_cksum; 11 | struct in_addr igmp_group; 12 | }; 13 | 14 | #define IGMP_MINLEN 8 15 | 16 | #define IGMP_MEMBERSHIP_QUERY 0x11 17 | #define IGMP_V1_MEMBERSHIP_REPORT 0x12 18 | #define IGMP_V2_MEMBERSHIP_REPORT 0x16 19 | #define IGMP_V2_LEAVE_GROUP 0x17 20 | 21 | #define IGMP_DVMRP 0x13 22 | #define IGMP_PIM 0x14 23 | #define IGMP_TRACE 0x15 24 | 25 | #define IGMP_MTRACE_RESP 0x1e 26 | #define IGMP_MTRACE 0x1f 27 | 28 | #define IGMP_MAX_HOST_REPORT_DELAY 10 29 | #define IGMP_TIMER_SCALE 10 30 | 31 | #define IGMP_DELAYING_MEMBER 1 32 | #define IGMP_IDLE_MEMBER 2 33 | #define IGMP_LAZY_MEMBER 3 34 | #define IGMP_SLEEPING_MEMBER 4 35 | #define IGMP_AWAKENING_MEMBER 5 36 | 37 | #define IGMP_v1_ROUTER 1 38 | #define IGMP_v2_ROUTER 2 39 | 40 | #define IGMP_HOST_MEMBERSHIP_QUERY IGMP_MEMBERSHIP_QUERY 41 | #define IGMP_HOST_MEMBERSHIP_REPORT IGMP_V1_MEMBERSHIP_REPORT 42 | #define IGMP_HOST_NEW_MEMBERSHIP_REPORT IGMP_V2_MEMBERSHIP_REPORT 43 | #define IGMP_HOST_LEAVE_MESSAGE IGMP_V2_LEAVE_GROUP 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/kernel/include/rtl8169.h: -------------------------------------------------------------------------------- 1 | #include "nic_controller.h" 2 | #include "pci.h" 3 | #include "types.h" 4 | 5 | #ifndef RTL8169_H 6 | #define RTL8169_H 7 | 8 | #define RTL8169_DESCRIPTORS 1024 9 | #define RTL8169_RX_DESCRIPTORS RTL8169_DESCRIPTORS 10 | #define RTL8169_TX_DESCRIPTORS RTL8169_DESCRIPTORS 11 | 12 | #define RTL8169_OWN 0x80000000 13 | #define RTL8169_EOR 0x40000000 14 | 15 | #define RTL8169_RECV 0x01 16 | #define RTL8169_SENT 0x04 17 | #define RTL8169_LINK_CHANGE 0x20 18 | 19 | typedef struct rtl8169_descriptor { 20 | uint32_t command; /* command/status uint32_t */ 21 | uint32_t vlan; /* currently unused */ 22 | uint32_t low_buf; /* low 32-bits of physical buffer address */ 23 | uint32_t high_buf; /* high 32-bits of physical buffer address */ 24 | } rtl8169_descriptor; 25 | 26 | typedef struct rtl8169_interface { 27 | uint16_t iobase; 28 | rtl8169_descriptor *RxDescriptors; /* 1MB Base Address of Rx Descriptors */ 29 | rtl8169_descriptor *TxDescriptors; /* 2MB Base Address of Tx Descriptors */ 30 | bool txSent; 31 | } rtl8169_interface; 32 | 33 | bool initiateRTL8169(PCIdevice *device); 34 | void sendRTL8169(NIC *nic, void *packet, uint32_t packetSize); 35 | void receiveRTL8169(NIC *nic); 36 | 37 | #endif -------------------------------------------------------------------------------- /target/usr/include/poll.h: -------------------------------------------------------------------------------- 1 | #ifndef _POLL_H 2 | #define _POLL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #include 11 | 12 | #define POLLIN 0x001 13 | #define POLLPRI 0x002 14 | #define POLLOUT 0x004 15 | #define POLLERR 0x008 16 | #define POLLHUP 0x010 17 | #define POLLNVAL 0x020 18 | #define POLLRDNORM 0x040 19 | #define POLLRDBAND 0x080 20 | #ifndef POLLWRNORM 21 | #define POLLWRNORM 0x100 22 | #define POLLWRBAND 0x200 23 | #endif 24 | #ifndef POLLMSG 25 | #define POLLMSG 0x400 26 | #define POLLRDHUP 0x2000 27 | #endif 28 | 29 | typedef unsigned long nfds_t; 30 | 31 | struct pollfd { 32 | int fd; 33 | short events; 34 | short revents; 35 | }; 36 | 37 | int poll (struct pollfd *, nfds_t, int); 38 | 39 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 40 | #define __NEED_time_t 41 | #define __NEED_struct_timespec 42 | #define __NEED_sigset_t 43 | #include 44 | int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); 45 | #endif 46 | 47 | #if _REDIR_TIME64 48 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 49 | __REDIR(ppoll, __ppoll_time64); 50 | #endif 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /target/usr/include/grp.h: -------------------------------------------------------------------------------- 1 | #ifndef _GRP_H 2 | #define _GRP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | #define __NEED_gid_t 12 | 13 | #ifdef _GNU_SOURCE 14 | #define __NEED_FILE 15 | #endif 16 | 17 | #include 18 | 19 | struct group { 20 | char *gr_name; 21 | char *gr_passwd; 22 | gid_t gr_gid; 23 | char **gr_mem; 24 | }; 25 | 26 | struct group *getgrgid(gid_t); 27 | struct group *getgrnam(const char *); 28 | 29 | int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); 30 | int getgrnam_r(const char *, struct group *, char *, size_t, struct group **); 31 | 32 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 33 | struct group *getgrent(void); 34 | void endgrent(void); 35 | void setgrent(void); 36 | #endif 37 | 38 | #ifdef _GNU_SOURCE 39 | struct group *fgetgrent(FILE *); 40 | int putgrent(const struct group *, FILE *); 41 | #endif 42 | 43 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 44 | int getgrouplist(const char *, gid_t, gid_t *, int *); 45 | int setgroups(size_t, const gid_t *); 46 | int initgroups(const char *, gid_t); 47 | #endif 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/kernel/include/circular.h: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #ifndef CIRCULAR_H 4 | #define CIRCULAR_H 5 | 6 | typedef struct Circular { 7 | uint8_t *buff; 8 | size_t buffSize; 9 | 10 | size_t readPtr; 11 | size_t writePtr; 12 | 13 | Spinlock LOCK_CIRC; 14 | } Circular; 15 | 16 | typedef struct CircularInt { 17 | uint8_t *buff; 18 | size_t buffSize; 19 | 20 | size_t readPtr; // atomic 21 | size_t writePtr; // atomic 22 | 23 | Spinlock LOCK_READ; // NOT supposed to be in int 24 | } CircularInt; 25 | 26 | #define CIRC_READABLE(wr, rd, sz) ((wr - rd + sz) % sz) 27 | #define CIRC_WRITABLE(wr, rd, sz) ((rd - wr - 1 + sz) % sz) 28 | 29 | void CircularAllocate(Circular *circ, size_t size); 30 | size_t CircularRead(Circular *circ, uint8_t *buff, size_t length); 31 | size_t CircularWrite(Circular *circ, const uint8_t *buff, size_t length); 32 | size_t CircularReadPoll(Circular *circ); 33 | size_t CircularWritePoll(Circular *circ); 34 | void CircularFree(Circular *circ); 35 | 36 | void CircularIntAllocate(CircularInt *circ, size_t size); 37 | size_t CircularIntRead(CircularInt *circ, uint8_t *buff, size_t length); 38 | size_t CircularIntWrite(CircularInt *circ, const uint8_t *buff, size_t length); 39 | size_t CircularIntReadPoll(CircularInt *circ); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /target/usr/include/mqueue.h: -------------------------------------------------------------------------------- 1 | #ifndef _MQUEUE_H 2 | #define _MQUEUE_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #define __NEED_size_t 10 | #define __NEED_ssize_t 11 | #define __NEED_pthread_attr_t 12 | #define __NEED_time_t 13 | #define __NEED_struct_timespec 14 | #include 15 | 16 | typedef int mqd_t; 17 | struct mq_attr { 18 | long mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs, __unused[4]; 19 | }; 20 | struct sigevent; 21 | 22 | int mq_close(mqd_t); 23 | int mq_getattr(mqd_t, struct mq_attr *); 24 | int mq_notify(mqd_t, const struct sigevent *); 25 | mqd_t mq_open(const char *, int, ...); 26 | ssize_t mq_receive(mqd_t, char *, size_t, unsigned *); 27 | int mq_send(mqd_t, const char *, size_t, unsigned); 28 | int mq_setattr(mqd_t, const struct mq_attr *__restrict, struct mq_attr *__restrict); 29 | ssize_t mq_timedreceive(mqd_t, char *__restrict, size_t, unsigned *__restrict, const struct timespec *__restrict); 30 | int mq_timedsend(mqd_t, const char *, size_t, unsigned, const struct timespec *); 31 | int mq_unlink(const char *); 32 | 33 | #if _REDIR_TIME64 34 | __REDIR(mq_timedreceive, __mq_timedreceive_time64); 35 | __REDIR(mq_timedsend, __mq_timedsend_time64); 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /target/usr/include/float.h: -------------------------------------------------------------------------------- 1 | #ifndef _FLOAT_H 2 | #define _FLOAT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int __flt_rounds(void); 9 | #define FLT_ROUNDS (__flt_rounds()) 10 | 11 | #define FLT_RADIX 2 12 | 13 | #define FLT_TRUE_MIN 1.40129846432481707092e-45F 14 | #define FLT_MIN 1.17549435082228750797e-38F 15 | #define FLT_MAX 3.40282346638528859812e+38F 16 | #define FLT_EPSILON 1.1920928955078125e-07F 17 | 18 | #define FLT_MANT_DIG 24 19 | #define FLT_MIN_EXP (-125) 20 | #define FLT_MAX_EXP 128 21 | #define FLT_HAS_SUBNORM 1 22 | 23 | #define FLT_DIG 6 24 | #define FLT_DECIMAL_DIG 9 25 | #define FLT_MIN_10_EXP (-37) 26 | #define FLT_MAX_10_EXP 38 27 | 28 | #define DBL_TRUE_MIN 4.94065645841246544177e-324 29 | #define DBL_MIN 2.22507385850720138309e-308 30 | #define DBL_MAX 1.79769313486231570815e+308 31 | #define DBL_EPSILON 2.22044604925031308085e-16 32 | 33 | #define DBL_MANT_DIG 53 34 | #define DBL_MIN_EXP (-1021) 35 | #define DBL_MAX_EXP 1024 36 | #define DBL_HAS_SUBNORM 1 37 | 38 | #define DBL_DIG 15 39 | #define DBL_DECIMAL_DIG 17 40 | #define DBL_MIN_10_EXP (-307) 41 | #define DBL_MAX_10_EXP 308 42 | 43 | #define LDBL_HAS_SUBNORM 1 44 | #define LDBL_DECIMAL_DIG DECIMAL_DIG 45 | 46 | #include 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/kernel/cpu/fastSyscall.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // Prepares the "syscall" instruction x86_64 provides 8 | // Copyright (C) 2024 Panagiotis 9 | 10 | bool checkSyscallInst() { 11 | uint32_t eax = 0x80000001, ebx = 0, ecx = 0, edx = 0; 12 | cpuid(&eax, &ebx, &ecx, &edx); 13 | return (edx >> 11) & 1; 14 | } 15 | 16 | void initiateSyscallInst() { 17 | if (!checkSyscallInst()) { 18 | debugf("[syscalls] FATAL! No support for the syscall instruction found!\n"); 19 | panic(); 20 | } 21 | 22 | // setup this core's thread info structure 23 | threadInfo.syscall_stack = 0; 24 | threadInfo.lapic_id = bootloader.smp[bootloader.smpBspIndex].bsp_lapic_id; 25 | wrmsr(MSRID_KERNEL_GSBASE, (size_t)&threadInfo); 26 | 27 | uint64_t star_reg = rdmsr(MSRID_STAR); 28 | star_reg &= 0x00000000ffffffff; 29 | 30 | star_reg |= ((uint64_t)GDT_USER_CODE - 16) << 48; 31 | star_reg |= ((uint64_t)GDT_KERNEL_CODE) << 32; 32 | wrmsr(MSRID_STAR, star_reg); 33 | 34 | // entry defined in isr.asm 35 | wrmsr(MSRID_LSTAR, (uint64_t)syscall_entry); 36 | 37 | uint64_t efer_reg = rdmsr(MSRID_EFER); 38 | efer_reg |= 1 << 0; 39 | wrmsr(MSRID_EFER, efer_reg); 40 | 41 | wrmsr(MSRID_FMASK, RFLAGS_IF | RFLAGS_DF); 42 | } 43 | -------------------------------------------------------------------------------- /target/usr/include/bits/user.h: -------------------------------------------------------------------------------- 1 | #undef __WORDSIZE 2 | #define __WORDSIZE 64 3 | 4 | typedef struct user_fpregs_struct { 5 | uint16_t cwd, swd, ftw, fop; 6 | uint64_t rip, rdp; 7 | uint32_t mxcsr, mxcr_mask; 8 | uint32_t st_space[32], xmm_space[64], padding[24]; 9 | } elf_fpregset_t; 10 | 11 | struct user_regs_struct { 12 | unsigned long r15, r14, r13, r12, rbp, rbx, r11, r10, r9, r8; 13 | unsigned long rax, rcx, rdx, rsi, rdi, orig_rax, rip; 14 | unsigned long cs, eflags, rsp, ss, fs_base, gs_base, ds, es, fs, gs; 15 | }; 16 | #define ELF_NGREG 27 17 | typedef unsigned long long elf_greg_t, elf_gregset_t[ELF_NGREG]; 18 | 19 | struct user { 20 | struct user_regs_struct regs; 21 | int u_fpvalid; 22 | struct user_fpregs_struct i387; 23 | unsigned long u_tsize; 24 | unsigned long u_dsize; 25 | unsigned long u_ssize; 26 | unsigned long start_code; 27 | unsigned long start_stack; 28 | long signal; 29 | int reserved; 30 | struct user_regs_struct *u_ar0; 31 | struct user_fpregs_struct *u_fpstate; 32 | unsigned long magic; 33 | char u_comm[32]; 34 | unsigned long u_debugreg[8]; 35 | }; 36 | 37 | #define PAGE_MASK (~(PAGESIZE-1)) 38 | #define NBPG PAGESIZE 39 | #define UPAGES 1 40 | #define HOST_TEXT_START_ADDR (u.start_code) 41 | #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) 42 | -------------------------------------------------------------------------------- /src/kernel/include/arp.h: -------------------------------------------------------------------------------- 1 | #include "eth.h" 2 | #include "linked_list.h" 3 | #include "util.h" 4 | 5 | #ifndef NET_ARP_H 6 | #define NET_ARP_H 7 | 8 | typedef struct arpPacket { 9 | uint16_t hardwareType; 10 | uint16_t protocolType; 11 | uint8_t hardwareSize; 12 | uint8_t protocolSize; 13 | uint16_t opcode; 14 | uint8_t senderMac[6]; 15 | uint8_t senderIp[4]; 16 | uint8_t targetMac[6]; 17 | uint8_t targetIp[4]; 18 | } __attribute__((packed)) arpPacket; 19 | 20 | #define ARP_OP_REQUEST 0x01 21 | #define ARP_OP_REPLY 0x02 22 | 23 | #define ARP_HARDWARE_TYPE 0x0001 24 | #define ARP_PROTOCOL_TYPE 0x0800 25 | 26 | #define ARP_TIMEOUT 500 27 | 28 | #define NET_ARP_CARRY (sizeof(ethHeader)) 29 | #define NET_ARP(packet) ((arpPacket *)((size_t)(packet) + NET_ARP_CARRY)) 30 | 31 | // todo: add a hashmap to improve performance 32 | typedef struct arpEntry { 33 | LLheader _ll; 34 | 35 | uint8_t mac[MAC_BYTE_SIZE]; 36 | uint8_t ip[IPv4_BYTE_SIZE]; 37 | } arpEntry; 38 | 39 | typedef struct arpRequest { 40 | uint8_t ip[IPv4_BYTE_SIZE]; 41 | } arpRequest; 42 | 43 | typedef struct arpStore { 44 | LLcontrol table; // struct arpEntry 45 | Spinlock LOCK_LL_TABLE; 46 | } arpStore; 47 | 48 | void netArpHandle(void *_nic, void *packet, uint32_t size); 49 | bool netArpTranslate(void *_nic, uint8_t *ip, uint8_t *res); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/kernel/drivers/vga.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // The BIOS/UEFI GOP provided framebuffer... pretty darn basic 9 | // Copyright (C) 2024 Panagiotis 10 | 11 | static volatile struct limine_framebuffer_request limineFBreq = { 12 | .id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0}; 13 | 14 | void initiateVGA() { 15 | struct limine_framebuffer *framebufferRes = 16 | limineFBreq.response->framebuffers[0]; 17 | fb.virt = (uint8_t *)framebufferRes->address; 18 | fb.phys = (size_t)fb.virt - bootloader.hhdmOffset; 19 | fb.height = framebufferRes->height; 20 | fb.width = framebufferRes->width; 21 | fb.pitch = framebufferRes->pitch; 22 | fb.bpp = framebufferRes->bpp; 23 | 24 | fb.red_shift = framebufferRes->red_mask_shift; 25 | fb.red_size = framebufferRes->red_mask_size; 26 | 27 | fb.green_shift = framebufferRes->green_mask_shift; 28 | fb.green_size = framebufferRes->green_mask_size; 29 | 30 | fb.blue_shift = framebufferRes->blue_mask_shift; 31 | fb.blue_size = framebufferRes->blue_mask_size; 32 | 33 | // memcpy(&framebufferLimine, framebufferRes, sizeof(struct 34 | // limine_framebuffer)); 35 | debugf("[graphics] Resolution fixed: fb{%lx} dim(xy){%dx%d} bpp{%d}\n", 36 | fb.virt, fb.width, fb.height, fb.bpp); 37 | } 38 | -------------------------------------------------------------------------------- /src/kernel/utilities/fakefs/null.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | size_t nullRead(OpenFile *fd, uint8_t *out, size_t limit) { return 0; } 6 | size_t nullWrite(OpenFile *fd, uint8_t *in, size_t limit) { return limit; } 7 | 8 | size_t nullStat(OpenFile *fd, stat *target) { 9 | target->st_dev = 70; 10 | target->st_ino = rand(); // todo! 11 | target->st_mode = S_IFCHR | S_IRUSR | S_IWUSR; 12 | target->st_nlink = 1; 13 | target->st_uid = 0; 14 | target->st_gid = 0; 15 | target->st_rdev = 0; 16 | target->st_blksize = 0x1000; 17 | target->st_size = 0; 18 | target->st_blocks = DivRoundUp(target->st_size, 512); 19 | target->st_atime = 69; 20 | target->st_mtime = 69; 21 | target->st_ctime = 69; 22 | 23 | return 0; 24 | } 25 | 26 | size_t nullIoctl(OpenFile *fd, uint64_t request, void *arg) { 27 | return ERR(ENOTTY); 28 | } 29 | bool nullDuplicate() { return true; } 30 | 31 | size_t nullMmap() { 32 | debugf("[/dev/null] Tried to mmap?\n"); 33 | return (size_t)-1; 34 | } 35 | 36 | VfsHandlers handleNull = {.read = nullRead, 37 | .write = nullWrite, 38 | .stat = nullStat, 39 | .duplicate = nullDuplicate, 40 | .ioctl = nullIoctl, 41 | .mmap = nullMmap, 42 | .getdents64 = 0}; 43 | -------------------------------------------------------------------------------- /src/kernel/include/linked_list.h: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #ifndef LINKED_LIST_H 4 | #define LINKED_LIST_H 5 | 6 | typedef struct LLheader { 7 | struct LLheader *next; 8 | // ... 9 | } __attribute__((packed)) LLheader; 10 | 11 | #define LL_SIGNATURE_1 0xa8ae0a9b148db421 12 | #define LL_SIGNATURE_2 0x7c9bfa1f171be6da 13 | 14 | typedef struct LLcontrol { 15 | uint64_t signature1; // LL_SIGNATURE_1 16 | uint64_t signature2; // LL_SIGNATURE_2 17 | 18 | uint32_t structSize; 19 | Spinlock LOCK_LL; 20 | 21 | LLheader *firstObject; 22 | } LLcontrol; 23 | 24 | void LinkedListInit(LLcontrol *ll, uint32_t structSize); 25 | void *LinkedListAllocate(LLcontrol *ll, uint32_t structSize); 26 | bool LinkedListUnregister(LLcontrol *ll, uint32_t structSize, 27 | const void *LLtarget); 28 | bool LinkedListRemove(LLcontrol *ll, uint32_t structSize, void *LLtarget); 29 | void LinkedListPushFrontUnsafe(LLcontrol *ll, void *LLtarget); 30 | void LinkedListDestroy(LLcontrol *ll, uint32_t structSize); 31 | 32 | void LinkedListTraverse(LLcontrol *ll, void(callback)(void *data, void *ctx), 33 | void *ctx); 34 | void *LinkedListSearch(LLcontrol *ll, bool(isCorrect)(void *data, void *ctx), 35 | void *ctx); 36 | void *LinkedListSearchFirst(LLcontrol *ll); 37 | void *LinkedListSearchPtr(LLcontrol *ll, void *targetPtr); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/kernel/include/ipv4.h: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #ifndef NET_IPV4_H 4 | #define NET_IPV4_H 5 | 6 | typedef struct IPv4header { 7 | uint8_t ihl : 4; 8 | uint8_t version : 4; // network endian switch, version should be first 9 | 10 | uint8_t tos; 11 | uint16_t length; 12 | uint16_t id; 13 | 14 | uint16_t flags; 15 | 16 | uint8_t ttl; 17 | uint8_t protocol; 18 | uint16_t checksum; 19 | uint8_t srcAddress[4]; 20 | uint8_t destAddress[4]; 21 | } __attribute__((packed)) IPv4header; 22 | 23 | #define IPV4_PROTOCOL_ICMP 1 24 | #define IPV4_PROTOCOL_TCP 6 25 | #define IPV4_PROTOCOL_UDP 17 26 | 27 | #define IPV4_FLAGS_MORE_FRAGMENTS (1 << 13) 28 | #define IPV4_FLAGS_DONT_FRAGMENT (1 << 14) 29 | #define IPV4_FLAGS_RESV (1 << 15) 30 | 31 | #define IPV4_FRAGMENT_OFFSET(a) \ 32 | (a & \ 33 | ~(IPV4_FLAGS_DONT_FRAGMENT | IPV4_FLAGS_MORE_FRAGMENTS | IPV4_FLAGS_RESV)) 34 | 35 | #define NET_IPv4_CARRY (sizeof(ethHeader)) 36 | #define NET_IPv4(packet) ((IPv4header *)((size_t)(packet) + NET_IPv4_CARRY)) 37 | 38 | void netIPv4Handle(void *_nic, void *packet, uint32_t size); 39 | 40 | void netIPv4InitBuffer(void *buffer, uint32_t size); 41 | void netIPv4Send(void *_nic, void *packet, uint32_t size, uint8_t protocol, 42 | uint8_t *destinationIp); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /target/usr/include/sys/acct.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_ACCT_H 2 | #define _SYS_ACCT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define ACCT_COMM 16 13 | 14 | typedef uint16_t comp_t; 15 | 16 | struct acct { 17 | char ac_flag; 18 | uint16_t ac_uid; 19 | uint16_t ac_gid; 20 | uint16_t ac_tty; 21 | uint32_t ac_btime; 22 | comp_t ac_utime; 23 | comp_t ac_stime; 24 | comp_t ac_etime; 25 | comp_t ac_mem; 26 | comp_t ac_io; 27 | comp_t ac_rw; 28 | comp_t ac_minflt; 29 | comp_t ac_majflt; 30 | comp_t ac_swaps; 31 | uint32_t ac_exitcode; 32 | char ac_comm[ACCT_COMM+1]; 33 | char ac_pad[10]; 34 | }; 35 | 36 | 37 | struct acct_v3 { 38 | char ac_flag; 39 | char ac_version; 40 | uint16_t ac_tty; 41 | uint32_t ac_exitcode; 42 | uint32_t ac_uid; 43 | uint32_t ac_gid; 44 | uint32_t ac_pid; 45 | uint32_t ac_ppid; 46 | uint32_t ac_btime; 47 | float ac_etime; 48 | comp_t ac_utime; 49 | comp_t ac_stime; 50 | comp_t ac_mem; 51 | comp_t ac_io; 52 | comp_t ac_rw; 53 | comp_t ac_minflt; 54 | comp_t ac_majflt; 55 | comp_t ac_swaps; 56 | char ac_comm[ACCT_COMM]; 57 | }; 58 | 59 | #define AFORK 1 60 | #define ASU 2 61 | #define ACORE 8 62 | #define AXSIG 16 63 | #define ACCT_BYTEORDER (128*(__BYTE_ORDER==__BIG_ENDIAN)) 64 | #define AHZ 100 65 | 66 | int acct(const char *); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /target/usr/include/net/ethernet.h: -------------------------------------------------------------------------------- 1 | #ifndef _NET_ETHERNET_H 2 | #define _NET_ETHERNET_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | struct ether_addr { 13 | uint8_t ether_addr_octet[ETH_ALEN]; 14 | }; 15 | 16 | struct ether_header { 17 | uint8_t ether_dhost[ETH_ALEN]; 18 | uint8_t ether_shost[ETH_ALEN]; 19 | uint16_t ether_type; 20 | }; 21 | 22 | #define ETHERTYPE_PUP 0x0200 23 | #define ETHERTYPE_SPRITE 0x0500 24 | #define ETHERTYPE_IP 0x0800 25 | #define ETHERTYPE_ARP 0x0806 26 | #define ETHERTYPE_REVARP 0x8035 27 | #define ETHERTYPE_AT 0x809B 28 | #define ETHERTYPE_AARP 0x80F3 29 | #define ETHERTYPE_VLAN 0x8100 30 | #define ETHERTYPE_IPX 0x8137 31 | #define ETHERTYPE_IPV6 0x86dd 32 | #define ETHERTYPE_LOOPBACK 0x9000 33 | 34 | 35 | #define ETHER_ADDR_LEN ETH_ALEN 36 | #define ETHER_TYPE_LEN 2 37 | #define ETHER_CRC_LEN 4 38 | #define ETHER_HDR_LEN ETH_HLEN 39 | #define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) 40 | #define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) 41 | 42 | #define ETHER_IS_VALID_LEN(foo) \ 43 | ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) 44 | 45 | #define ETHERTYPE_TRAIL 0x1000 46 | #define ETHERTYPE_NTRAILER 16 47 | 48 | #define ETHERMTU ETH_DATA_LEN 49 | #define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /target/usr/include/sys/procfs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_PROCFS_H 2 | #define _SYS_PROCFS_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | struct elf_siginfo { 12 | int si_signo; 13 | int si_code; 14 | int si_errno; 15 | }; 16 | 17 | struct elf_prstatus { 18 | struct elf_siginfo pr_info; 19 | short int pr_cursig; 20 | unsigned long int pr_sigpend; 21 | unsigned long int pr_sighold; 22 | pid_t pr_pid; 23 | pid_t pr_ppid; 24 | pid_t pr_pgrp; 25 | pid_t pr_sid; 26 | struct { 27 | long tv_sec, tv_usec; 28 | } pr_utime, pr_stime, pr_cutime, pr_cstime; 29 | elf_gregset_t pr_reg; 30 | int pr_fpvalid; 31 | }; 32 | 33 | #define ELF_PRARGSZ 80 34 | 35 | struct elf_prpsinfo { 36 | char pr_state; 37 | char pr_sname; 38 | char pr_zomb; 39 | char pr_nice; 40 | unsigned long int pr_flag; 41 | #if UINTPTR_MAX == 0xffffffff 42 | unsigned short int pr_uid; 43 | unsigned short int pr_gid; 44 | #else 45 | unsigned int pr_uid; 46 | unsigned int pr_gid; 47 | #endif 48 | int pr_pid, pr_ppid, pr_pgrp, pr_sid; 49 | char pr_fname[16]; 50 | char pr_psargs[ELF_PRARGSZ]; 51 | }; 52 | 53 | typedef void *psaddr_t; 54 | typedef elf_gregset_t prgregset_t; 55 | typedef elf_fpregset_t prfpregset_t; 56 | typedef pid_t lwpid_t; 57 | typedef struct elf_prstatus prstatus_t; 58 | typedef struct elf_prpsinfo prpsinfo_t; 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif 64 | -------------------------------------------------------------------------------- /target/usr/include/sys/statvfs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_STATVFS_H 2 | #define _SYS_STATVFS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_fsblkcnt_t 11 | #define __NEED_fsfilcnt_t 12 | #include 13 | 14 | struct statvfs { 15 | unsigned long f_bsize, f_frsize; 16 | fsblkcnt_t f_blocks, f_bfree, f_bavail; 17 | fsfilcnt_t f_files, f_ffree, f_favail; 18 | #if __BYTE_ORDER == __LITTLE_ENDIAN 19 | unsigned long f_fsid; 20 | unsigned :8*(2*sizeof(int)-sizeof(long)); 21 | #else 22 | unsigned :8*(2*sizeof(int)-sizeof(long)); 23 | unsigned long f_fsid; 24 | #endif 25 | unsigned long f_flag, f_namemax; 26 | unsigned int f_type; 27 | int __reserved[5]; 28 | }; 29 | 30 | int statvfs (const char *__restrict, struct statvfs *__restrict); 31 | int fstatvfs (int, struct statvfs *); 32 | 33 | #define ST_RDONLY 1 34 | #define ST_NOSUID 2 35 | #define ST_NODEV 4 36 | #define ST_NOEXEC 8 37 | #define ST_SYNCHRONOUS 16 38 | #define ST_MANDLOCK 64 39 | #define ST_WRITE 128 40 | #define ST_APPEND 256 41 | #define ST_IMMUTABLE 512 42 | #define ST_NOATIME 1024 43 | #define ST_NODIRATIME 2048 44 | #define ST_RELATIME 4096 45 | 46 | #if defined(_LARGEFILE64_SOURCE) 47 | #define statvfs64 statvfs 48 | #define fstatvfs64 fstatvfs 49 | #define fsblkcnt64_t fsblkcnt_t 50 | #define fsfilcnt64_t fsfilcnt_t 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "deepscan.enable": true, 3 | "files.associations": { 4 | "*.c": "c", 5 | "*.h": "c" 6 | }, 7 | "C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, AlignConsecutiveDeclarations: true, IndentWidth: 2 }", 8 | "C_Cpp.default.compilerArgs": [ 9 | "-I${workspaceRoot}/src/kernel/include", 10 | "-I${workspaceRoot}/src/kernel/networking/lwip/include/", 11 | "-m64", 12 | "-c", 13 | "-ffreestanding", 14 | "-Wall", 15 | "-fcommon", 16 | "-fPIE", 17 | "-mno-80387", 18 | "-mno-mmx", 19 | "-mno-sse", 20 | "-nostartfiles", 21 | "-nostdlib", 22 | "-mno-sse2", 23 | "-mno-red-zone", 24 | "-fno-stack-protector", 25 | "-fno-stack-check", 26 | "-fno-lto" 27 | ], 28 | "clang.cflags": [ 29 | "-I${workspaceRoot}/src/kernel/include", 30 | "-I${workspaceRoot}/src/kernel/networking/lwip/include/", 31 | "-m64", 32 | "-c", 33 | "-ffreestanding", 34 | "-Wall", 35 | "-fcommon", 36 | "-fPIE", 37 | "-mno-80387", 38 | "-mno-mmx", 39 | "-mno-sse", 40 | "-nostartfiles", 41 | "-nostdlib", 42 | "-mno-sse2", 43 | "-mno-red-zone", 44 | "-fno-stack-protector", 45 | "-fno-stack-check", 46 | "-fno-lto" 47 | ], 48 | "files.exclude": { 49 | "**/*.o": true 50 | }, 51 | "makefile.configureOnOpen": false, 52 | "C_Cpp.formatting": "clangFormat", 53 | "C_Cpp.clang_format_path": "~/opt/clang-format-cavos" 54 | } 55 | -------------------------------------------------------------------------------- /target/usr/include/sys/sem.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SEM_H 2 | #define _SYS_SEM_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #define __NEED_size_t 10 | #define __NEED_pid_t 11 | #define __NEED_time_t 12 | #ifdef _GNU_SOURCE 13 | #define __NEED_struct_timespec 14 | #endif 15 | #include 16 | 17 | #include 18 | 19 | #define SEM_UNDO 0x1000 20 | #define GETPID 11 21 | #define GETVAL 12 22 | #define GETALL 13 23 | #define GETNCNT 14 24 | #define GETZCNT 15 25 | #define SETVAL 16 26 | #define SETALL 17 27 | 28 | #include 29 | 30 | #define _SEM_SEMUN_UNDEFINED 1 31 | 32 | #define SEM_STAT (18 | (IPC_STAT & 0x100)) 33 | #define SEM_INFO 19 34 | #define SEM_STAT_ANY (20 | (IPC_STAT & 0x100)) 35 | 36 | struct seminfo { 37 | int semmap; 38 | int semmni; 39 | int semmns; 40 | int semmnu; 41 | int semmsl; 42 | int semopm; 43 | int semume; 44 | int semusz; 45 | int semvmx; 46 | int semaem; 47 | }; 48 | 49 | struct sembuf { 50 | unsigned short sem_num; 51 | short sem_op; 52 | short sem_flg; 53 | }; 54 | 55 | int semctl(int, int, int, ...); 56 | int semget(key_t, int, int); 57 | int semop(int, struct sembuf *, size_t); 58 | 59 | #ifdef _GNU_SOURCE 60 | int semtimedop(int, struct sembuf *, size_t, const struct timespec *); 61 | #endif 62 | 63 | #if _REDIR_TIME64 64 | #ifdef _GNU_SOURCE 65 | __REDIR(semtimedop, __semtimedop_time64); 66 | #endif 67 | #endif 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | #endif 73 | -------------------------------------------------------------------------------- /target/usr/include/regex.h: -------------------------------------------------------------------------------- 1 | #ifndef _REGEX_H 2 | #define _REGEX_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_regoff_t 11 | #define __NEED_size_t 12 | 13 | #include 14 | 15 | typedef struct re_pattern_buffer { 16 | size_t re_nsub; 17 | void *__opaque, *__padding[4]; 18 | size_t __nsub2; 19 | char __padding2; 20 | } regex_t; 21 | 22 | typedef struct { 23 | regoff_t rm_so; 24 | regoff_t rm_eo; 25 | } regmatch_t; 26 | 27 | #define REG_EXTENDED 1 28 | #define REG_ICASE 2 29 | #define REG_NEWLINE 4 30 | #define REG_NOSUB 8 31 | 32 | #define REG_NOTBOL 1 33 | #define REG_NOTEOL 2 34 | 35 | #define REG_OK 0 36 | #define REG_NOMATCH 1 37 | #define REG_BADPAT 2 38 | #define REG_ECOLLATE 3 39 | #define REG_ECTYPE 4 40 | #define REG_EESCAPE 5 41 | #define REG_ESUBREG 6 42 | #define REG_EBRACK 7 43 | #define REG_EPAREN 8 44 | #define REG_EBRACE 9 45 | #define REG_BADBR 10 46 | #define REG_ERANGE 11 47 | #define REG_ESPACE 12 48 | #define REG_BADRPT 13 49 | 50 | #define REG_ENOSYS -1 51 | 52 | int regcomp(regex_t *__restrict, const char *__restrict, int); 53 | int regexec(const regex_t *__restrict, const char *__restrict, size_t, regmatch_t *__restrict, int); 54 | void regfree(regex_t *); 55 | 56 | size_t regerror(int, const regex_t *__restrict, char *__restrict, size_t); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /target/usr/include/sys/select.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SELECT_H 2 | #define _SYS_SELECT_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #define __NEED_size_t 10 | #define __NEED_time_t 11 | #define __NEED_suseconds_t 12 | #define __NEED_struct_timeval 13 | #define __NEED_struct_timespec 14 | #define __NEED_sigset_t 15 | 16 | #include 17 | 18 | #define FD_SETSIZE 1024 19 | 20 | typedef unsigned long fd_mask; 21 | 22 | typedef struct { 23 | unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; 24 | } fd_set; 25 | 26 | #define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) 27 | #define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) 28 | #define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) 29 | #define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) 30 | 31 | int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); 32 | int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); 33 | 34 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 35 | #define NFDBITS (8*(int)sizeof(long)) 36 | #endif 37 | 38 | #if _REDIR_TIME64 39 | __REDIR(select, __select_time64); 40 | __REDIR(pselect, __pselect_time64); 41 | #endif 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif 47 | -------------------------------------------------------------------------------- /src/kernel/include/gdt.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef GDT_H 4 | #define GDT_H 5 | 6 | typedef struct GDTEntry { 7 | uint16_t limit; 8 | uint16_t base_low; 9 | uint8_t base_mid; 10 | uint8_t access; 11 | uint8_t granularity; 12 | uint8_t base_high; 13 | } __attribute__((packed)) GDTEntry; 14 | 15 | typedef struct GDTPointer { 16 | uint16_t limit; 17 | uint32_t base; 18 | } __attribute__((packed)) GDTPointer; 19 | 20 | typedef struct TSSEntry { 21 | uint16_t length; 22 | uint16_t base_low; 23 | uint8_t base_mid; 24 | uint8_t flags1; 25 | uint8_t flags2; 26 | uint8_t base_high; 27 | uint32_t base_upper32; 28 | uint32_t reserved; 29 | } __attribute__((packed)) TSSEntry; 30 | 31 | typedef struct TSSPtr { 32 | uint32_t unused0; 33 | uint64_t rsp0; 34 | uint64_t rsp1; 35 | uint64_t rsp2; 36 | uint64_t unused1; 37 | uint64_t ist1; 38 | uint64_t ist2; 39 | uint64_t ist3; 40 | uint64_t ist4; 41 | uint64_t ist5; 42 | uint64_t ist6; 43 | uint64_t ist7; 44 | uint64_t unused2; 45 | uint32_t iopb; 46 | } __attribute__((packed)) TSSPtr; 47 | 48 | typedef struct GDTEntries { 49 | GDTEntry descriptors[11]; 50 | TSSEntry tss; 51 | } __attribute__((packed)) GDTEntries; 52 | 53 | typedef struct GDTPtr { 54 | uint16_t limit; 55 | uint64_t base; 56 | } __attribute__((packed)) GDTPtr; 57 | 58 | #define NUM_GDT_ENTRIES 7 59 | #define GDT_KERNEL_CODE 40 60 | #define GDT_KERNEL_DATA 48 61 | #define GDT_USER_CODE 80 62 | #define GDT_USER_DATA 72 63 | #define GDT_TSS 80 64 | 65 | void initiateGDT(); 66 | 67 | #endif -------------------------------------------------------------------------------- /target/usr/include/sys/uio.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_UIO_H 2 | #define _SYS_UIO_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | #define __NEED_ssize_t 12 | #define __NEED_struct_iovec 13 | 14 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 15 | #define __NEED_off_t 16 | #endif 17 | 18 | #ifdef _GNU_SOURCE 19 | #define __NEED_pid_t 20 | #endif 21 | 22 | #include 23 | 24 | #define UIO_MAXIOV 1024 25 | 26 | ssize_t readv (int, const struct iovec *, int); 27 | ssize_t writev (int, const struct iovec *, int); 28 | 29 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 30 | ssize_t preadv (int, const struct iovec *, int, off_t); 31 | ssize_t pwritev (int, const struct iovec *, int, off_t); 32 | #if defined(_LARGEFILE64_SOURCE) 33 | #define preadv64 preadv 34 | #define pwritev64 pwritev 35 | #define off64_t off_t 36 | #endif 37 | #endif 38 | 39 | #ifdef _GNU_SOURCE 40 | ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); 41 | ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); 42 | ssize_t preadv2 (int, const struct iovec *, int, off_t, int); 43 | ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); 44 | #define RWF_HIPRI 0x00000001 45 | #define RWF_DSYNC 0x00000002 46 | #define RWF_SYNC 0x00000004 47 | #define RWF_NOWAIT 0x00000008 48 | #define RWF_APPEND 0x00000010 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/kernel/memory/malloc_glue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define DEBUG_DLMALLOC_GLUE 0 7 | 8 | void *last = 0; 9 | void *sbrk(long increment) { 10 | #if DEBUG_DLMALLOC_GLUE 11 | debugf("[dlmalloc::sbrk] size{%lx}\n", increment); 12 | #endif 13 | if (increment < 0) 14 | return 0; // supposed to release, whatever. 15 | if (!increment) 16 | return last; 17 | // return 0; 18 | 19 | uint64_t blocks = DivRoundUp(increment, BLOCK_SIZE); 20 | void *virt = VirtualAllocate(blocks); 21 | memset(virt, 0, blocks * BLOCK_SIZE); 22 | 23 | last = (void *)((size_t)virt + increment); 24 | 25 | #if DEBUG_DLMALLOC_GLUE 26 | debugf("[dlmalloc::sbrk] found{%lx}\n", virt); 27 | #endif 28 | return virt; 29 | } 30 | 31 | // below aren't needed anymore as MALLOC_FAILURE_ACTION is set to abort 32 | /*int __errnoF = 0; 33 | int *__errno_location = &__errnoF;*/ 34 | 35 | // void __errno() { return &__errnoF; } 36 | 37 | void abort() { 38 | debugf("[dlmalloc::abort] Either ran out of memory or there is a memory " 39 | "violation! (most likely the second)\n"); 40 | panic(); 41 | } 42 | 43 | // spinlocks/mutexes/whatever people call them; I truly don't care! 44 | MLOCK_T malloc_global_mutex = ATOMIC_FLAG_INIT; 45 | 46 | int ACQUIRE_LOCK(Spinlock *lock) { 47 | spinlockAcquire(lock); 48 | return 0; 49 | } 50 | 51 | int RELEASE_LOCK(Spinlock *lock) { 52 | spinlockRelease(lock); 53 | return 0; 54 | } 55 | 56 | int INITIAL_LOCK(Spinlock *lock) { 57 | RELEASE_LOCK(lock); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /target/usr/include/sys/epoll.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_EPOLL_H 2 | #define _SYS_EPOLL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define __NEED_sigset_t 13 | 14 | #include 15 | 16 | #define EPOLL_CLOEXEC O_CLOEXEC 17 | #define EPOLL_NONBLOCK O_NONBLOCK 18 | 19 | enum EPOLL_EVENTS { __EPOLL_DUMMY }; 20 | #define EPOLLIN 0x001 21 | #define EPOLLPRI 0x002 22 | #define EPOLLOUT 0x004 23 | #define EPOLLRDNORM 0x040 24 | #define EPOLLNVAL 0x020 25 | #define EPOLLRDBAND 0x080 26 | #define EPOLLWRNORM 0x100 27 | #define EPOLLWRBAND 0x200 28 | #define EPOLLMSG 0x400 29 | #define EPOLLERR 0x008 30 | #define EPOLLHUP 0x010 31 | #define EPOLLRDHUP 0x2000 32 | #define EPOLLEXCLUSIVE (1U<<28) 33 | #define EPOLLWAKEUP (1U<<29) 34 | #define EPOLLONESHOT (1U<<30) 35 | #define EPOLLET (1U<<31) 36 | 37 | #define EPOLL_CTL_ADD 1 38 | #define EPOLL_CTL_DEL 2 39 | #define EPOLL_CTL_MOD 3 40 | 41 | typedef union epoll_data { 42 | void *ptr; 43 | int fd; 44 | uint32_t u32; 45 | uint64_t u64; 46 | } epoll_data_t; 47 | 48 | struct epoll_event { 49 | uint32_t events; 50 | epoll_data_t data; 51 | } 52 | #ifdef __x86_64__ 53 | __attribute__ ((__packed__)) 54 | #endif 55 | ; 56 | 57 | 58 | int epoll_create(int); 59 | int epoll_create1(int); 60 | int epoll_ctl(int, int, int, struct epoll_event *); 61 | int epoll_wait(int, struct epoll_event *, int, int); 62 | int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *); 63 | 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* sys/epoll.h */ 70 | -------------------------------------------------------------------------------- /src/kernel/include/isr.h: -------------------------------------------------------------------------------- 1 | #include "linked_list.h" 2 | #include "types.h" 3 | 4 | #ifndef ISR_H 5 | #define ISR_H 6 | 7 | #define MSRID_FSBASE 0xC0000100 8 | #define MSRID_GSBASE 0xC0000101 9 | 10 | #define MSRID_KERNEL_GSBASE 0xC0000102 11 | 12 | #define MSRID_EFER 0xC0000080 13 | #define MSRID_STAR 0xC0000081 14 | #define MSRID_LSTAR 0xC0000082 15 | #define MSRID_FMASK 0xC0000084 16 | 17 | #define RFLAGS_IF (1 << 9) 18 | #define RFLAGS_DF (1 << 10) 19 | 20 | typedef struct { 21 | uint64_t ds; // & es 22 | 23 | uint64_t r15; 24 | uint64_t r14; 25 | uint64_t r13; 26 | uint64_t r12; 27 | uint64_t r11; 28 | uint64_t r10; 29 | uint64_t r9; 30 | uint64_t r8; 31 | uint64_t rbp; 32 | uint64_t rdi; 33 | uint64_t rsi; 34 | uint64_t rdx; 35 | uint64_t rcx; 36 | uint64_t rbx; 37 | uint64_t rax; 38 | 39 | uint64_t interrupt; 40 | uint64_t error; 41 | 42 | uint64_t rip; 43 | uint64_t cs; 44 | uint64_t rflags; 45 | uint64_t usermode_rsp; 46 | uint64_t usermode_ss; 47 | } AsmPassedInterrupt; 48 | 49 | typedef void (*FunctionPtr)(AsmPassedInterrupt *regs); 50 | // FunctionPtr irqHandlers[16]; // IRQs 0 - 15 51 | typedef struct irqHandler irqHandler; 52 | struct irqHandler { 53 | LLheader _ll; 54 | 55 | uint8_t id; 56 | FunctionPtr handler; 57 | 58 | uint64_t argument; // extra 59 | }; 60 | 61 | LLcontrol dsIrqHandler; // struct irqHandler 62 | 63 | void initiateISR(); 64 | irqHandler *registerIRQhandler(uint8_t id, void *handler); 65 | 66 | extern void asm_isr_exit(); 67 | extern void *asm_isr_redirect_table[]; 68 | extern void isr128(); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /target/usr/include/utmpx.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTMPX_H 2 | #define _UTMPX_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_pid_t 11 | #define __NEED_time_t 12 | #define __NEED_suseconds_t 13 | #define __NEED_struct_timeval 14 | 15 | #include 16 | 17 | struct utmpx { 18 | short ut_type; 19 | short __ut_pad1; 20 | pid_t ut_pid; 21 | char ut_line[32]; 22 | char ut_id[4]; 23 | char ut_user[32]; 24 | char ut_host[256]; 25 | struct { 26 | short __e_termination; 27 | short __e_exit; 28 | } ut_exit; 29 | #if __BYTE_ORDER == 1234 30 | int ut_session, __ut_pad2; 31 | #else 32 | int __ut_pad2, ut_session; 33 | #endif 34 | struct timeval ut_tv; 35 | unsigned ut_addr_v6[4]; 36 | char __unused[20]; 37 | }; 38 | 39 | void endutxent(void); 40 | struct utmpx *getutxent(void); 41 | struct utmpx *getutxid(const struct utmpx *); 42 | struct utmpx *getutxline(const struct utmpx *); 43 | struct utmpx *pututxline(const struct utmpx *); 44 | void setutxent(void); 45 | 46 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 47 | #define e_exit __e_exit 48 | #define e_termination __e_termination 49 | void updwtmpx(const char *, const struct utmpx *); 50 | int utmpxname(const char *); 51 | #endif 52 | 53 | #define EMPTY 0 54 | #define RUN_LVL 1 55 | #define BOOT_TIME 2 56 | #define NEW_TIME 3 57 | #define OLD_TIME 4 58 | #define INIT_PROCESS 5 59 | #define LOGIN_PROCESS 6 60 | #define USER_PROCESS 7 61 | #define DEAD_PROCESS 8 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /tools/shared/chroot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REMEMBER! 4 | # chroot /whatever/wherever/whenever /usr/bin/bash << "EOT" 5 | # # anything 6 | # EOT 7 | 8 | chroot_drop() { 9 | sudo umount -l "$1/dev/shm" || true 10 | sudo umount -l "$1/run" || true 11 | sudo umount -l "$1/sys" || true 12 | sudo umount -l "$1/proc" || true 13 | sudo umount -l "$1/dev/pts" || true 14 | sudo umount -l "$1/dev" || true 15 | sudo umount -l "$1/tmp/.X11-unix" || true 16 | } 17 | 18 | chroot_establish() { 19 | chroot_drop "$1" 20 | 21 | mkdir -p "$1/"{dev,proc,sys,run,tmp} 22 | sudo mount --bind /dev "$1/dev" 23 | sudo mount -t devpts devpts -o gid=5,mode=0620 "$1/dev/pts" 24 | sudo mount -t proc proc "$1/proc" 25 | sudo mount -t sysfs sysfs "$1/sys" 26 | sudo mount -t tmpfs tmpfs "$1/run" 27 | if [ -h "$1/dev/shm" ]; then 28 | sudo install -v -d -m 1777 "$1/$(realpath /dev/shm)" 29 | else 30 | sudo mount -t tmpfs -o nosuid,nodev tmpfs "$1/dev/shm" 31 | fi 32 | # mkdir -p "$1/tmp/.X11-unix" 33 | # sudo mount --bind /tmp/.X11-unix "$1/tmp/.X11-unix" 34 | 35 | # host$ xhost + local: 36 | # chroot$ export DISPLAY=:1 37 | # chroot$ export WEBKIT_DISABLE_COMPOSITING_MODE=1 38 | } 39 | 40 | # ! If you ever want to chroot into your target, uncomment the following lines and comment them out again before running make disk ! 41 | # if [[ -z "$1" || ! -d "$1" ]]; then 42 | # echo "Error: You must provide a valid directory as the first argument." >&2 43 | # exit 1 44 | # fi 45 | 46 | # chroot_establish "$1" 47 | # sudo chroot "$1/" /usr/bin/env -i HISTFILE=/dev/null /bin/bash 48 | # chroot_drop "$1" 49 | # ! End uncomment 50 | -------------------------------------------------------------------------------- /tools/shared/cross_compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -x # show cmds 3 | set -e # fail globally 4 | 5 | # Cross compile an autotools package for our custom target (x86_64-cavos) 6 | build_package_autotools() { 7 | # Ensure the cavOS toolchain's in PATH 8 | if [[ ":$PATH:" != *":$HOME/opt/cross/bin:"* ]]; then 9 | export PATH=$HOME/opt/cross/bin:$PATH 10 | fi 11 | 12 | # Arguments 13 | uri=$1 14 | filename=$(echo "$uri" | sed 's/.*\///g') 15 | foldername=$(echo "$filename" | sed 's/\.tar.*//g') 16 | install_dir=$2 17 | config_sub_path=$3 18 | 19 | # EXTRA arguments 20 | extra_parameters=$4 21 | optional_patchname=$5 22 | extra_install_parameters=$6 23 | before_build=$7 24 | 25 | # Download and extract the tarball 26 | wget -nc "$uri" 27 | tar xpvf "$filename" 28 | cd "$foldername" 29 | 30 | # Add our target 31 | sed -i 's/\# Now accept the basic system types\./cavos\*\);;/g' "$config_sub_path" 32 | 33 | # Do any optional patches 34 | if [ -n "$optional_patchname" ]; then 35 | patch -p1 <"$optional_patchname" 36 | fi 37 | 38 | # Just in case it's needed 39 | if [ -n "$before_build" ]; then 40 | eval "$before_build" 41 | fi 42 | 43 | # Use a separate directory for compiling (good practice) 44 | mkdir -p build 45 | cd build 46 | 47 | # Compilation itself 48 | ../configure --prefix="$install_dir" --host=x86_64-cavos $extra_parameters 49 | make -j$(nproc) 50 | if [ -n "$extra_install_parameters" ]; then 51 | make install $extra_install_parameters 52 | else 53 | make install 54 | fi 55 | 56 | # Cleanup 57 | cd ../../ 58 | rm -rf "$foldername" 59 | rm -f "$filename" 60 | } 61 | -------------------------------------------------------------------------------- /target/usr/include/sys/inotify.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_INOTIFY_H 2 | #define _SYS_INOTIFY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | struct inotify_event { 12 | int wd; 13 | uint32_t mask, cookie, len; 14 | char name[]; 15 | }; 16 | 17 | #define IN_CLOEXEC O_CLOEXEC 18 | #define IN_NONBLOCK O_NONBLOCK 19 | 20 | #define IN_ACCESS 0x00000001 21 | #define IN_MODIFY 0x00000002 22 | #define IN_ATTRIB 0x00000004 23 | #define IN_CLOSE_WRITE 0x00000008 24 | #define IN_CLOSE_NOWRITE 0x00000010 25 | #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) 26 | #define IN_OPEN 0x00000020 27 | #define IN_MOVED_FROM 0x00000040 28 | #define IN_MOVED_TO 0x00000080 29 | #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) 30 | #define IN_CREATE 0x00000100 31 | #define IN_DELETE 0x00000200 32 | #define IN_DELETE_SELF 0x00000400 33 | #define IN_MOVE_SELF 0x00000800 34 | #define IN_ALL_EVENTS 0x00000fff 35 | 36 | #define IN_UNMOUNT 0x00002000 37 | #define IN_Q_OVERFLOW 0x00004000 38 | #define IN_IGNORED 0x00008000 39 | 40 | #define IN_ONLYDIR 0x01000000 41 | #define IN_DONT_FOLLOW 0x02000000 42 | #define IN_EXCL_UNLINK 0x04000000 43 | #define IN_MASK_CREATE 0x10000000 44 | #define IN_MASK_ADD 0x20000000 45 | 46 | #define IN_ISDIR 0x40000000 47 | #define IN_ONESHOT 0x80000000 48 | 49 | int inotify_init(void); 50 | int inotify_init1(int); 51 | int inotify_add_watch(int, const char *, uint32_t); 52 | int inotify_rm_watch(int, int); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /target/usr/include/search.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEARCH_H 2 | #define _SEARCH_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_size_t 11 | #include 12 | 13 | typedef enum { FIND, ENTER } ACTION; 14 | typedef enum { preorder, postorder, endorder, leaf } VISIT; 15 | 16 | typedef struct entry { 17 | char *key; 18 | void *data; 19 | } ENTRY; 20 | 21 | int hcreate(size_t); 22 | void hdestroy(void); 23 | ENTRY *hsearch(ENTRY, ACTION); 24 | 25 | #ifdef _GNU_SOURCE 26 | struct hsearch_data { 27 | struct __tab *__tab; 28 | unsigned int __unused1; 29 | unsigned int __unused2; 30 | }; 31 | 32 | int hcreate_r(size_t, struct hsearch_data *); 33 | void hdestroy_r(struct hsearch_data *); 34 | int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); 35 | #endif 36 | 37 | void insque(void *, void *); 38 | void remque(void *); 39 | 40 | void *lsearch(const void *, void *, size_t *, size_t, 41 | int (*)(const void *, const void *)); 42 | void *lfind(const void *, const void *, size_t *, size_t, 43 | int (*)(const void *, const void *)); 44 | 45 | void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *)); 46 | void *tfind(const void *, void *const *, int(*)(const void *, const void *)); 47 | void *tsearch(const void *, void **, int (*)(const void *, const void *)); 48 | void twalk(const void *, void (*)(const void *, VISIT, int)); 49 | 50 | #ifdef _GNU_SOURCE 51 | struct qelem { 52 | struct qelem *q_forw, *q_back; 53 | char q_data[1]; 54 | }; 55 | 56 | void tdestroy(void *, void (*)(void *)); 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /target/usr/include/netpacket/packet.h: -------------------------------------------------------------------------------- 1 | #ifndef _NETPACKET_PACKET_H 2 | #define _NETPACKET_PACKET_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | struct sockaddr_ll { 9 | unsigned short sll_family, sll_protocol; 10 | int sll_ifindex; 11 | unsigned short sll_hatype; 12 | unsigned char sll_pkttype, sll_halen; 13 | unsigned char sll_addr[8]; 14 | }; 15 | 16 | struct packet_mreq { 17 | int mr_ifindex; 18 | unsigned short int mr_type, mr_alen; 19 | unsigned char mr_address[8]; 20 | }; 21 | 22 | #define PACKET_HOST 0 23 | #define PACKET_BROADCAST 1 24 | #define PACKET_MULTICAST 2 25 | #define PACKET_OTHERHOST 3 26 | #define PACKET_OUTGOING 4 27 | #define PACKET_LOOPBACK 5 28 | #define PACKET_FASTROUTE 6 29 | 30 | #define PACKET_ADD_MEMBERSHIP 1 31 | #define PACKET_DROP_MEMBERSHIP 2 32 | #define PACKET_RECV_OUTPUT 3 33 | #define PACKET_RX_RING 5 34 | #define PACKET_STATISTICS 6 35 | #define PACKET_COPY_THRESH 7 36 | #define PACKET_AUXDATA 8 37 | #define PACKET_ORIGDEV 9 38 | #define PACKET_VERSION 10 39 | #define PACKET_HDRLEN 11 40 | #define PACKET_RESERVE 12 41 | #define PACKET_TX_RING 13 42 | #define PACKET_LOSS 14 43 | #define PACKET_VNET_HDR 15 44 | #define PACKET_TX_TIMESTAMP 16 45 | #define PACKET_TIMESTAMP 17 46 | #define PACKET_FANOUT 18 47 | #define PACKET_TX_HAS_OFF 19 48 | #define PACKET_QDISC_BYPASS 20 49 | #define PACKET_ROLLOVER_STATS 21 50 | #define PACKET_FANOUT_DATA 22 51 | #define PACKET_IGNORE_OUTGOING 23 52 | 53 | #define PACKET_MR_MULTICAST 0 54 | #define PACKET_MR_PROMISC 1 55 | #define PACKET_MR_ALLMULTI 2 56 | #define PACKET_MR_UNICAST 3 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/kernel/include/bitmap.h: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | #ifndef BITMAP_H 4 | #define BITMAP_H 5 | 6 | typedef struct DS_Bitmap { 7 | uint8_t *Bitmap; 8 | size_t BitmapSizeInBlocks; // CEIL(x / BLOCK_SIZE) 9 | size_t BitmapSizeInBytes; // CEIL(blockSize / 8) 10 | 11 | size_t allocatedSizeInBlocks; 12 | 13 | // optimization(1): For (de/)allocations know to what extend our 14 | // bitmap is fully fragmented so it doesn't scan over it over and over and 15 | // over again.. This is especially useful for single-block allocations (such 16 | // as pageframes), typically done in a loop. 17 | size_t lastDeepFragmented; 18 | 19 | size_t mem_start; 20 | bool ready; // has been initiated 21 | } DS_Bitmap; 22 | 23 | #define BLOCKS_PER_BYTE 8 // using uint8_t 24 | #define BLOCK_SIZE 4096 25 | #define INVALID_BLOCK ((size_t)-1) 26 | 27 | void *ToPtr(DS_Bitmap *bitmap, size_t block); 28 | size_t ToBlock(DS_Bitmap *bitmap, void *ptr); 29 | size_t ToBlockRoundUp(DS_Bitmap *bitmap, void *ptr); 30 | 31 | size_t BitmapCalculateSize(size_t totalSize); 32 | int BitmapGet(DS_Bitmap *bitmap, size_t block); 33 | void BitmapSet(DS_Bitmap *bitmap, size_t block, bool value); 34 | 35 | void BitmapDump(DS_Bitmap *bitmap); 36 | void BitmapDumpBlocks(DS_Bitmap *bitmap); 37 | 38 | void MarkBlocks(DS_Bitmap *bitmap, size_t start, size_t size, bool val); 39 | void MarkRegion(DS_Bitmap *bitmap, void *basePtr, size_t sizeBytes, int isUsed); 40 | size_t FindFreeRegion(DS_Bitmap *bitmap, size_t blocks); 41 | void *BitmapAllocate(DS_Bitmap *bitmap, size_t blocks); 42 | 43 | size_t BitmapAllocatePageframe(DS_Bitmap *bitmap); 44 | void BitmapFreePageframe(DS_Bitmap *bitmap, void *addr); 45 | 46 | #endif -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/netif/ppp/chap-md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * chap-md5.h - New CHAP/MD5 implementation. 3 | * 4 | * Copyright (c) 2003 Paul Mackerras. All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. The name(s) of the authors of this software must not be used to 14 | * endorse or promote products derived from this software without 15 | * prior written permission. 16 | * 17 | * 3. Redistributions of any form whatsoever must retain the following 18 | * acknowledgment: 19 | * "This product includes software developed by Paul Mackerras 20 | * ". 21 | * 22 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 23 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 24 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 26 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 27 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 28 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 29 | */ 30 | 31 | #include "netif/ppp/ppp_opts.h" 32 | #if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 33 | 34 | extern const struct chap_digest_type md5_digest; 35 | 36 | #endif /* PPP_SUPPORT && CHAP_SUPPORT */ 37 | -------------------------------------------------------------------------------- /src/kernel/include/apic.h: -------------------------------------------------------------------------------- 1 | #include "linked_list.h" 2 | #include "pci.h" 3 | #include "types.h" 4 | 5 | #ifndef APIC_H 6 | #define APIC_H 7 | 8 | #define IA32_APIC_BASE_MSR 0x1B 9 | #define IA32_APIC_BASE_MSR_BSP 0x100 // Processor is a BSP 10 | #define IA32_APIC_BASE_MSR_ENABLE 0x800 11 | 12 | #define APIC_REGISTER_ID 0x20 13 | #define APIC_REGISTER_APICID 0x20 14 | #define APIC_REGISTER_EOI 0x0B0 15 | #define APIC_REGISTER_SPURIOUS 0x0F0 16 | #define APIC_REGISTER_LVT_TIMER 0x320 17 | #define APIC_REGISTER_TIMER_INITCNT 0x380 18 | #define APIC_REGISTER_TIMER_CURRCNT 0x390 19 | #define APIC_REGISTER_TIMER_DIV 0x3E0 20 | 21 | #define APIC_LVT_TIMER_MODE_PERIODIC (1 << 17) 22 | 23 | // APIC quick access 24 | // (same address for different cores) 25 | uint64_t apicPhys; 26 | uint64_t apicVirt; 27 | 28 | // I/O APIC quick access 29 | typedef struct IOAPIC { 30 | struct LLheader _ll; 31 | 32 | uint8_t id; 33 | 34 | uint64_t ioapicPhys; 35 | uint64_t ioapicVirt; 36 | 37 | int ioapicRedStart; 38 | int ioapicRedEnd; // NOT max! 39 | } IOAPIC; 40 | LLcontrol dsIoapic; // struct IOAPIC 41 | 42 | // no way to deallocate vectors, should be good enough 43 | #define MAX_IRQ 256 44 | uint8_t *irqPerCpu; 45 | uint8_t irqGenericArray[MAX_IRQ]; 46 | uint32_t lapicGenericArray[MAX_IRQ]; 47 | 48 | void initiateAPIC(); 49 | void smpInitiateAPIC(); 50 | 51 | uint8_t ioApicRedirect(uint8_t irq, bool ignored); 52 | uint8_t ioApicPciRegister(PCIdevice *device, PCIgeneralDevice *details); 53 | uint8_t irqPerCoreAllocate(uint8_t gsi, uint32_t *lapicId); 54 | 55 | uint32_t apicRead(uint32_t offset); 56 | void apicWrite(uint32_t offset, uint32_t value); 57 | 58 | uint32_t apicCurrentCore(); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/arch/sys_arch.h: -------------------------------------------------------------------------------- 1 | #include "cc.h" 2 | #include "lwip/err.h" 3 | 4 | void sys_init(void); 5 | 6 | uint32_t sys_now(void); 7 | sys_thread_t sys_thread_new(const char *pcName, 8 | void (*pxThread)(void *pvParameters), void *pvArg, 9 | int iStackSize, int iPriority); 10 | 11 | void sys_mutex_lock(Spinlock *spinlock); 12 | void sys_mutex_unlock(Spinlock *spinlock); 13 | err_t sys_mutex_new(Spinlock *spinlock); 14 | 15 | err_t sys_sem_new(sys_sem_t *sem, uint8_t cnt); 16 | void sys_sem_signal(sys_sem_t *sem); 17 | uint32_t sys_arch_sem_wait(sys_sem_t *sem, uint32_t timeout); 18 | void sys_sem_free(sys_sem_t *sem); 19 | void sys_sem_set_invalid(sys_sem_t *sem); 20 | int sys_sem_valid(sys_sem_t *sem); 21 | 22 | err_t LWIP_NETCONN_THREAD_SEM_ALLOC(); 23 | err_t LWIP_NETCONN_THREAD_SEM_FREE(); 24 | sys_sem_t *LWIP_NETCONN_THREAD_SEM_GET(); 25 | 26 | err_t sys_mbox_new(sys_mbox_t *mbox, int size); 27 | void sys_mbox_free(sys_mbox_t *mbox); 28 | void sys_mbox_set_invalid(sys_mbox_t *mbox); 29 | int sys_mbox_valid(sys_mbox_t *mbox); 30 | void sys_mbox_post(sys_mbox_t *q, void *msg); 31 | err_t sys_mbox_trypost(sys_mbox_t *q, void *msg); 32 | err_t sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg); 33 | u32_t sys_arch_mbox_fetch(sys_mbox_t *q, void **msg, u32_t timeout); 34 | u32_t sys_arch_mbox_tryfetch(sys_mbox_t *q, void **msg); 35 | 36 | void *sio_open(u8_t devnum); 37 | u32_t sio_write(void *fd, const u8_t *data, u32_t len); 38 | void sio_send(u8_t c, void *fd); 39 | u8_t sio_recv(void *fd); 40 | u32_t sio_read(void *fd, u8_t *data, u32_t len); 41 | u32_t sio_tryread(void *fd, u8_t *data, u32_t len); 42 | -------------------------------------------------------------------------------- /target/usr/include/sys/personality.h: -------------------------------------------------------------------------------- 1 | #ifndef _PERSONALITY_H 2 | #define _PERSONALITY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define UNAME26 0x0020000 9 | #define ADDR_NO_RANDOMIZE 0x0040000 10 | #define FDPIC_FUNCPTRS 0x0080000 11 | #define MMAP_PAGE_ZERO 0x0100000 12 | #define ADDR_COMPAT_LAYOUT 0x0200000 13 | #define READ_IMPLIES_EXEC 0x0400000 14 | #define ADDR_LIMIT_32BIT 0x0800000 15 | #define SHORT_INODE 0x1000000 16 | #define WHOLE_SECONDS 0x2000000 17 | #define STICKY_TIMEOUTS 0x4000000 18 | #define ADDR_LIMIT_3GB 0x8000000 19 | 20 | #define PER_LINUX 0 21 | #define PER_LINUX_32BIT ADDR_LIMIT_32BIT 22 | #define PER_LINUX_FDPIC FDPIC_FUNCPTRS 23 | #define PER_SVR4 (1 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO) 24 | #define PER_SVR3 (2 | STICKY_TIMEOUTS | SHORT_INODE) 25 | #define PER_SCOSVR3 (3 | STICKY_TIMEOUTS | WHOLE_SECONDS | SHORT_INODE) 26 | #define PER_OSR5 (3 | STICKY_TIMEOUTS | WHOLE_SECONDS) 27 | #define PER_WYSEV386 (4 | STICKY_TIMEOUTS | SHORT_INODE) 28 | #define PER_ISCR4 (5 | STICKY_TIMEOUTS) 29 | #define PER_BSD 6 30 | #define PER_SUNOS (6 | STICKY_TIMEOUTS) 31 | #define PER_XENIX (7 | STICKY_TIMEOUTS | SHORT_INODE) 32 | #define PER_LINUX32 8 33 | #define PER_LINUX32_3GB (8 | ADDR_LIMIT_3GB) 34 | #define PER_IRIX32 (9 | STICKY_TIMEOUTS) 35 | #define PER_IRIXN32 (0xa | STICKY_TIMEOUTS) 36 | #define PER_IRIX64 (0x0b | STICKY_TIMEOUTS) 37 | #define PER_RISCOS 0xc 38 | #define PER_SOLARIS (0xd | STICKY_TIMEOUTS) 39 | #define PER_UW7 (0xe | STICKY_TIMEOUTS | MMAP_PAGE_ZERO) 40 | #define PER_OSF4 0xf 41 | #define PER_HPUX 0x10 42 | #define PER_MASK 0xff 43 | 44 | int personality(unsigned long); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | #endif 50 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/compat/posix/netdb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix wrapper for lwip/netdb.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/netdb.h" 34 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/compat/stdc/errno.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix/stdc wrapper for lwip/errno.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/errno.h" 34 | -------------------------------------------------------------------------------- /target/usr/include/sys/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_WAIT_H 2 | #define _SYS_WAIT_H 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | #define __NEED_pid_t 10 | #define __NEED_id_t 11 | #include 12 | 13 | typedef enum { 14 | P_ALL = 0, 15 | P_PID = 1, 16 | P_PGID = 2, 17 | P_PIDFD = 3 18 | } idtype_t; 19 | 20 | pid_t wait (int *); 21 | pid_t waitpid (pid_t, int *, int ); 22 | 23 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 24 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 25 | || defined(_BSD_SOURCE) 26 | #include 27 | int waitid (idtype_t, id_t, siginfo_t *, int); 28 | #endif 29 | 30 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 31 | #include 32 | pid_t wait3 (int *, int, struct rusage *); 33 | pid_t wait4 (pid_t, int *, int, struct rusage *); 34 | #endif 35 | 36 | #define WNOHANG 1 37 | #define WUNTRACED 2 38 | 39 | #define WSTOPPED 2 40 | #define WEXITED 4 41 | #define WCONTINUED 8 42 | #define WNOWAIT 0x1000000 43 | 44 | #define __WNOTHREAD 0x20000000 45 | #define __WALL 0x40000000 46 | #define __WCLONE 0x80000000 47 | 48 | #define WEXITSTATUS(s) (((s) & 0xff00) >> 8) 49 | #define WTERMSIG(s) ((s) & 0x7f) 50 | #define WSTOPSIG(s) WEXITSTATUS(s) 51 | #define WCOREDUMP(s) ((s) & 0x80) 52 | #define WIFEXITED(s) (!WTERMSIG(s)) 53 | #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00) 54 | #define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) 55 | #define WIFCONTINUED(s) ((s) == 0xffff) 56 | 57 | #if _REDIR_TIME64 58 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 59 | __REDIR(wait3, __wait3_time64); 60 | __REDIR(wait4, __wait4_time64); 61 | #endif 62 | #endif 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #endif 68 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/compat/posix/arpa/inet.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix wrapper for lwip/sockets.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/sockets.h" 34 | -------------------------------------------------------------------------------- /src/kernel/networking/lwip/include/compat/posix/sys/socket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix wrapper for lwip/sockets.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/sockets.h" 34 | -------------------------------------------------------------------------------- /target/usr/include/sys/shm.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SHM_H 2 | #define _SYS_SHM_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define __NEED_time_t 11 | #define __NEED_size_t 12 | #define __NEED_pid_t 13 | 14 | #include 15 | 16 | #include 17 | 18 | #ifdef _GNU_SOURCE 19 | #define __used_ids used_ids 20 | #define __swap_attempts swap_attempts 21 | #define __swap_successes swap_successes 22 | #endif 23 | 24 | #include 25 | 26 | #define SHM_R 0400 27 | #define SHM_W 0200 28 | 29 | #define SHM_RDONLY 010000 30 | #define SHM_RND 020000 31 | #define SHM_REMAP 040000 32 | #define SHM_EXEC 0100000 33 | 34 | #define SHM_LOCK 11 35 | #define SHM_UNLOCK 12 36 | #define SHM_STAT (13 | (IPC_STAT & 0x100)) 37 | #define SHM_INFO 14 38 | #define SHM_STAT_ANY (15 | (IPC_STAT & 0x100)) 39 | #define SHM_DEST 01000 40 | #define SHM_LOCKED 02000 41 | #define SHM_HUGETLB 04000 42 | #define SHM_NORESERVE 010000 43 | 44 | #define SHM_HUGE_SHIFT 26 45 | #define SHM_HUGE_MASK 0x3f 46 | #define SHM_HUGE_64KB (16 << 26) 47 | #define SHM_HUGE_512KB (19 << 26) 48 | #define SHM_HUGE_1MB (20 << 26) 49 | #define SHM_HUGE_2MB (21 << 26) 50 | #define SHM_HUGE_8MB (23 << 26) 51 | #define SHM_HUGE_16MB (24 << 26) 52 | #define SHM_HUGE_32MB (25 << 26) 53 | #define SHM_HUGE_256MB (28 << 26) 54 | #define SHM_HUGE_512MB (29 << 26) 55 | #define SHM_HUGE_1GB (30 << 26) 56 | #define SHM_HUGE_2GB (31 << 26) 57 | #define SHM_HUGE_16GB (34U << 26) 58 | 59 | typedef unsigned long shmatt_t; 60 | 61 | void *shmat(int, const void *, int); 62 | int shmctl(int, int, struct shmid_ds *); 63 | int shmdt(const void *); 64 | int shmget(key_t, size_t, int); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/kernel/include/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | #ifdef HAVE_OPENSSL 27 | #include 28 | #elif !defined(_MD5_H) 29 | #define _MD5_H 30 | 31 | /* Any 32-bit or wider unsigned integer data type will do */ 32 | typedef unsigned int MD5_u32plus; 33 | 34 | typedef struct { 35 | MD5_u32plus lo, hi; 36 | MD5_u32plus a, b, c, d; 37 | unsigned char buffer[64]; 38 | MD5_u32plus block[16]; 39 | } MD5_CTX; 40 | 41 | typedef struct { 42 | MD5_u32plus a, b, c, d; 43 | } MD5_OUT; 44 | 45 | extern void MD5_Init(MD5_CTX *ctx); 46 | extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); 47 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); 48 | 49 | #define MD5_LEN (32 + 1) 50 | void MD5_Simple(uint8_t *buff, int length, char *md5sum_out); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /target/usr/include/aio.h: -------------------------------------------------------------------------------- 1 | #ifndef _AIO_H 2 | #define _AIO_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define __NEED_ssize_t 13 | #define __NEED_off_t 14 | 15 | #include 16 | 17 | struct aiocb { 18 | int aio_fildes, aio_lio_opcode, aio_reqprio; 19 | volatile void *aio_buf; 20 | size_t aio_nbytes; 21 | struct sigevent aio_sigevent; 22 | void *__td; 23 | int __lock[2]; 24 | volatile int __err; 25 | ssize_t __ret; 26 | off_t aio_offset; 27 | void *__next, *__prev; 28 | char __dummy4[32-2*sizeof(void *)]; 29 | }; 30 | 31 | #define AIO_CANCELED 0 32 | #define AIO_NOTCANCELED 1 33 | #define AIO_ALLDONE 2 34 | 35 | #define LIO_READ 0 36 | #define LIO_WRITE 1 37 | #define LIO_NOP 2 38 | 39 | #define LIO_WAIT 0 40 | #define LIO_NOWAIT 1 41 | 42 | int aio_read(struct aiocb *); 43 | int aio_write(struct aiocb *); 44 | int aio_error(const struct aiocb *); 45 | ssize_t aio_return(struct aiocb *); 46 | int aio_cancel(int, struct aiocb *); 47 | int aio_suspend(const struct aiocb *const [], int, const struct timespec *); 48 | int aio_fsync(int, struct aiocb *); 49 | 50 | int lio_listio(int, struct aiocb *__restrict const *__restrict, int, struct sigevent *__restrict); 51 | 52 | #if defined(_LARGEFILE64_SOURCE) 53 | #define aiocb64 aiocb 54 | #define aio_read64 aio_read 55 | #define aio_write64 aio_write 56 | #define aio_error64 aio_error 57 | #define aio_return64 aio_return 58 | #define aio_cancel64 aio_cancel 59 | #define aio_suspend64 aio_suspend 60 | #define aio_fsync64 aio_fsync 61 | #define lio_listio64 lio_listio 62 | #define off64_t off_t 63 | #endif 64 | 65 | #if _REDIR_TIME64 66 | __REDIR(aio_suspend, __aio_suspend_time64); 67 | #endif 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/kernel/drivers/serial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // Simple serial driver for debugging 7 | // Copyright (C) 2024 Panagiotis 8 | 9 | Spinlock LOCK_DEBUGF = {0}; 10 | 11 | void serial_enable(int device) { 12 | outportb(device + 1, 0x00); 13 | outportb(device + 3, 0x80); /* Enable divisor mode */ 14 | outportb(device + 0, 0x03); /* Div Low: 03 Set the port to 38400 bps */ 15 | outportb(device + 1, 0x00); /* Div High: 00 */ 16 | outportb(device + 3, 0x03); 17 | outportb(device + 2, 0xC7); 18 | outportb(device + 4, 0x0B); 19 | } 20 | 21 | void initiateSerial() { 22 | debugf("[serial] Installing serial...\n"); 23 | 24 | serial_enable(COM1); 25 | // serial_enable(COM2); 26 | 27 | outportb(COM1 + 1, 0x01); 28 | // outportb(COM2 + 1, 0x01); 29 | } 30 | 31 | int serial_rcvd(int device) { return inportb(device + 5) & 1; } 32 | 33 | char serial_recv(int device) { 34 | while (serial_rcvd(device) == 0) 35 | ; 36 | return inportb(device); 37 | } 38 | 39 | char serial_recv_async(int device) { return inportb(device); } 40 | 41 | int serial_transmit_empty(int device) { return inportb(device + 5) & 0x20; } 42 | 43 | void serial_send(int device, char out) { 44 | while (serial_transmit_empty(device) == 0) 45 | ; 46 | outportb(device, out); 47 | } 48 | 49 | void debug(char c, void *arg) { 50 | // outportb(0xE9, c); 51 | // if (psf) 52 | // printf("%c", c); 53 | serial_send(COM1, c); 54 | } 55 | 56 | int debugf(const char *format, ...) { 57 | bool ints = checkInterrupts(); 58 | if (ints) 59 | spinlockAcquire(&LOCK_DEBUGF); 60 | va_list va; 61 | va_start(va, format); 62 | int ret = vfctprintf(debug, 0, format, va); 63 | va_end(va); 64 | if (ints) 65 | spinlockRelease(&LOCK_DEBUGF); 66 | return ret; 67 | } 68 | -------------------------------------------------------------------------------- /src/libs/system/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "system.h" 4 | 5 | // asm volatile("int $0x80" : "=a"(ret) : "a"(0), "b"(str)); 6 | // -O2 is the devil for those istg 7 | 8 | void syscallTest(char *msg) { 9 | asm volatile("int $0x80" ::"a"(SYSCALL_TEST), "b"(msg)); 10 | } 11 | 12 | void syscallExitTask(int return_code) { 13 | asm volatile("int $0x80" ::"a"(SYSCALL_EXIT_TASK), "b"(return_code)); 14 | } 15 | 16 | uint32_t syscallFork() { 17 | uint32_t ret; 18 | asm volatile("int $0x80" : "=a"(ret) : "a"(SYSCALL_FORK)); 19 | return ret; 20 | } 21 | 22 | void syscallRead(int file, char *str, uint32_t count) { 23 | asm volatile("int $0x80" ::"a"(SYSCALL_READ), "b"(file), "c"(str), 24 | "d"(count)); 25 | } 26 | 27 | void syscallWrite(int file, char *str, uint32_t count) { 28 | asm volatile("int $0x80" ::"a"(SYSCALL_WRITE), "b"(file), "c"(str), 29 | "d"(count)); 30 | } 31 | 32 | uint32_t syscallGetPid() { 33 | uint32_t ret; 34 | asm volatile("int $0x80" : "=a"(ret) : "a"(SYSCALL_GETPID)); 35 | return ret; 36 | } 37 | 38 | int syscallGetArgc() { 39 | int ret; 40 | asm volatile("int $0x80" : "=a"(ret) : "a"(SYSCALL_GETARGC)); 41 | return ret; 42 | } 43 | 44 | char *syscallGetArgv(int curr) { 45 | char *ret; 46 | asm volatile("int $0x80" : "=a"(ret) : "a"(SYSCALL_GETARGV), "b"(curr)); 47 | return ret; 48 | } 49 | 50 | uint32_t syscallGetHeapStart() { 51 | uint32_t ret; 52 | asm volatile("int $0x80" : "=a"(ret) : "a"(SYSCALL_GET_HEAP_START)); 53 | return ret; 54 | } 55 | 56 | uint32_t syscallGetHeapEnd() { 57 | uint32_t ret; 58 | asm volatile("int $0x80" : "=a"(ret) : "a"(SYSCALL_GET_HEAP_END)); 59 | return ret; 60 | } 61 | 62 | void syscallAdjustHeapEnd(uint32_t heap_end) { 63 | asm volatile("int $0x80" ::"a"(SYSCALL_ADJUST_HEAP_END), "b"(heap_end)); 64 | } 65 | -------------------------------------------------------------------------------- /src/kernel/include/system.h: -------------------------------------------------------------------------------- 1 | #include "spinlock.h" 2 | #include "types.h" 3 | 4 | #ifndef SYSTEM_H 5 | #define SYSTEM_H 6 | 7 | void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); 8 | 9 | // Ports 10 | uint8_t inportb(uint16_t _port); 11 | void outportb(uint16_t _port, uint8_t _data); 12 | 13 | uint16_t inportw(uint16_t port); 14 | void outportw(unsigned short port, unsigned short data); 15 | 16 | uint32_t inportl(uint16_t portid); 17 | void outportl(uint16_t portid, uint32_t value); 18 | 19 | // Model Specific Registers (MSRs) 20 | uint64_t rdmsr(uint32_t msrid); 21 | uint64_t wrmsr(uint32_t msrid, uint64_t value); 22 | 23 | // Streaming SIMD Extensions 24 | void initiateSSE(); 25 | 26 | // Generic 27 | void panic(); 28 | bool checkInterrupts(); 29 | bool isProtectedMemory(uint64_t virt); 30 | 31 | // Assert system 32 | void _assert(bool expression, char *file, int line); 33 | #define NO_ASSERT 0 34 | #if NO_ASSERT 35 | // #define assert(...) 36 | #define assert(expression) _assert(expression, 0, 0) 37 | #else 38 | #define assert(expression) _assert(expression, __FILE__, __LINE__) 39 | #endif 40 | 41 | // Has root (system) drive been initialized? 42 | bool systemDiskInit; 43 | 44 | // Hand down control to the scheduler 45 | void handControl(); 46 | 47 | // Switch contexts 48 | extern void asm_finalize(uint64_t rsp, uint64_t cr3); 49 | 50 | // Endianness 51 | uint16_t switch_endian_16(uint16_t val); 52 | uint32_t switch_endian_32(uint32_t val); 53 | 54 | // From LD 55 | extern uint64_t kernel_start; 56 | extern uint64_t kernel_end; 57 | uint32_t stack_bottom; 58 | 59 | // Thread Info 60 | // todo: make all of this SMP-friendly (along with fastSyscall.c) 61 | typedef struct ThreadInfo { 62 | uint64_t syscall_stack; 63 | uint64_t lapic_id; 64 | // [...] 65 | } ThreadInfo; 66 | 67 | ThreadInfo threadInfo; 68 | 69 | #endif 70 | --------------------------------------------------------------------------------