├── tools ├── base │ ├── readme │ ├── etc │ │ ├── shells │ │ └── passwd │ ├── root │ │ ├── .bash_history │ │ └── .bashrc │ └── boot │ │ └── bg.jpg ├── initbase │ ├── var │ │ └── run │ │ │ └── utmp │ ├── etc │ │ ├── hostname │ │ ├── X11 │ │ │ ├── xinitrc │ │ │ ├── xorg.conf │ │ │ └── test.sh │ │ ├── shells │ │ ├── passwd │ │ ├── init.sh │ │ ├── bg.jpg │ │ ├── twmbg.png │ │ ├── python │ │ │ ├── input_test.py │ │ │ └── raw_input_test.py │ │ ├── localtime │ │ ├── orangesad │ │ └── gaster │ └── root │ │ ├── .bash_history │ │ ├── .bashrc │ │ └── .twmrc ├── pkg │ ├── 0 │ │ └── mlibc │ │ │ ├── info.txt │ │ │ └── pkg.sh │ ├── 1 │ │ ├── nop │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── src │ │ │ │ └── main.cpp │ │ ├── liborange │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── include │ │ │ │ ├── log.h │ │ │ │ └── io.h │ │ └── pkg-config │ │ │ ├── info.txt │ │ │ ├── diff │ │ │ └── pkg-config.diff │ │ │ └── pkg.sh │ ├── 2 │ │ ├── init │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ ├── ncurses │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── diff │ │ │ │ └── ncurses.diff │ │ ├── ps2_driver │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ └── xhci_driver │ │ │ ├── info.txt │ │ │ └── pkg.sh │ ├── 3 │ │ ├── lua │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ ├── nano │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── diff │ │ │ │ └── nano.diff │ │ ├── bash │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── diff │ │ │ │ └── gettext.diff │ │ ├── coreutils │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── diff │ │ │ │ └── coreutils.diff │ │ ├── doomgeneric │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ ├── fastfetch │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ ├── mouse_test │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ ├── poll_test │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── src │ │ │ │ └── main.c │ │ └── pthread_test │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── main.c │ ├── 4 │ │ └── xorg-server │ │ │ ├── info.txt │ │ │ └── diff │ │ │ ├── openssl.diff │ │ │ ├── xfbdev.diff │ │ │ └── libgpg-error.diff │ ├── 5 │ │ ├── orangeutils │ │ │ ├── info.txt │ │ │ ├── src │ │ │ │ ├── orangedebugenable.c │ │ │ │ ├── orangeprintinfo.c │ │ │ │ ├── orangedebug.c │ │ │ │ └── dmesg.c │ │ │ └── pkg.sh │ │ ├── twm │ │ │ ├── info.txt │ │ │ ├── diff │ │ │ │ ├── fontconfig.diff │ │ │ │ └── libxt.diff │ │ │ └── pkg.sh │ │ ├── xorg-modules │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── diff │ │ │ │ └── xfbdev.diff │ │ └── orangex │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── main.sh │ ├── 6 │ │ ├── terms │ │ │ ├── info.txt │ │ │ ├── diff │ │ │ │ └── xloadimage.diff │ │ │ └── pkg.sh │ │ └── xcb-stuff │ │ │ ├── info.txt │ │ │ └── pkg.sh │ ├── 7 │ │ ├── games │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ └── diff │ │ │ │ └── ace.diff │ │ ├── benchmark │ │ │ ├── info.txt │ │ │ ├── pkg.sh │ │ │ ├── a.out │ │ │ └── main.c │ │ ├── glib │ │ │ ├── info.txt │ │ │ ├── diff │ │ │ │ └── glib.diff │ │ │ └── pkg.sh │ │ ├── python │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ └── doomgeneric │ │ │ └── pkg.sh │ ├── 8 │ │ ├── gtk │ │ │ ├── info.txt │ │ │ ├── diff │ │ │ │ └── dbus.diff │ │ │ └── pkg.sh │ │ └── llvm │ │ │ ├── info.txt │ │ │ └── pkg.sh │ ├── 9 │ │ └── mesa │ │ │ ├── info.txt │ │ │ ├── glx.pc │ │ │ └── pkg.sh │ ├── 10 │ │ ├── gtk_final │ │ │ ├── info.txt │ │ │ └── pkg.sh │ │ └── mesa-demos │ │ │ ├── info.txt │ │ │ └── pkg.sh │ ├── 11 │ │ └── other-stuff │ │ │ ├── info.txt │ │ │ ├── settings.ini │ │ │ └── pkg.sh │ ├── 12 │ │ └── i3wm │ │ │ ├── info.txt │ │ │ ├── yajl.pc │ │ │ ├── yajl_version.h │ │ │ ├── xcb-xrm.pc.in │ │ │ └── pkg.sh │ ├── readme │ ├── toolchain.cmake │ ├── x86_64-orange.crossfile │ └── build-pkg.sh ├── img │ ├── qemu.png │ ├── work.png │ ├── oldwork2.png │ └── workold.png ├── limine.conf ├── linux-headers.sh ├── toolchain-build.sh └── diffs │ └── binutils.diff ├── CONTRIBUTING.md ├── kernel ├── src │ ├── lib │ │ └── Flanterm │ │ │ ├── .gitignore │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ └── src │ │ │ ├── flanterm_backends │ │ │ ├── fb.h │ │ │ └── fb_private.h │ │ │ └── flanterm.h │ ├── main.asm │ ├── arch │ │ └── x86_64 │ │ │ ├── cpu │ │ │ ├── asm │ │ │ │ └── gdt.asm │ │ │ ├── gdt.cpp │ │ │ ├── smp.cpp │ │ │ └── sse.cpp │ │ │ ├── interrupts │ │ │ ├── pit.cpp │ │ │ ├── idt.cpp │ │ │ ├── irq.cpp │ │ │ └── asm │ │ │ │ └── idt.asm │ │ │ ├── syscalls │ │ │ └── futex.cpp │ │ │ └── asm │ │ │ ├── syscall.asm │ │ │ └── scheduling.asm │ ├── etc │ │ ├── libc.cpp │ │ ├── etc.cpp │ │ └── bootloaderinfo.cpp │ ├── generic │ │ ├── time.cpp │ │ ├── vfs │ │ │ └── ustar.cpp │ │ └── mm │ │ │ └── heap.cpp │ ├── drivers │ │ ├── tsc.cpp │ │ ├── serial.cpp │ │ ├── kvmtimer.cpp │ │ └── hpet.cpp │ └── main.cpp ├── .gitignore ├── include │ ├── drivers │ │ ├── acpi.hpp │ │ ├── hpet.hpp │ │ ├── tsc.hpp │ │ ├── kvmtimer.hpp │ │ ├── ioapic.hpp │ │ ├── serial.hpp │ │ ├── cmos.hpp │ │ ├── io.hpp │ │ └── pci.hpp │ ├── config.hpp │ ├── arch │ │ └── x86_64 │ │ │ ├── cpu │ │ │ ├── smp.hpp │ │ │ ├── sse.hpp │ │ │ ├── data.hpp │ │ │ ├── gdt.hpp │ │ │ └── lapic.hpp │ │ │ └── interrupts │ │ │ ├── pit.hpp │ │ │ ├── irq.hpp │ │ │ ├── idt.hpp │ │ │ └── pic.hpp │ ├── generic │ │ ├── time.hpp │ │ ├── mm │ │ │ ├── heap.hpp │ │ │ ├── paging.hpp │ │ │ └── pmm.hpp │ │ ├── vfs │ │ │ ├── ustar.hpp │ │ │ ├── tmpfs.hpp │ │ │ └── fd.hpp │ │ └── locks │ │ │ └── spinlock.hpp │ └── etc │ │ ├── bootloaderinfo.hpp │ │ ├── etc.hpp │ │ ├── assembly.hpp │ │ ├── logging.hpp │ │ ├── libc.hpp │ │ └── errno.hpp └── linker.ld ├── clone-submodules.sh ├── code_of_conduct.md ├── refresh-initrd.sh ├── .gitignore ├── LICENSE ├── tar-initrd.sh ├── readme.md └── GNUmakefile /tools/base/readme: -------------------------------------------------------------------------------- 1 | hi -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /tools/initbase/var/run/utmp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/pkg/2/init/info.txt: -------------------------------------------------------------------------------- 1 | tty -------------------------------------------------------------------------------- /tools/pkg/3/lua/info.txt : -------------------------------------------------------------------------------- 1 | lua -------------------------------------------------------------------------------- /tools/pkg/7/games/info.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/pkg/8/gtk/info.txt: -------------------------------------------------------------------------------- 1 | gtk3 -------------------------------------------------------------------------------- /tools/pkg/readme: -------------------------------------------------------------------------------- 1 | in future... -------------------------------------------------------------------------------- /tools/base/etc/shells: -------------------------------------------------------------------------------- 1 | /bin/bash -------------------------------------------------------------------------------- /tools/base/root/.bash_history: -------------------------------------------------------------------------------- 1 | exit -------------------------------------------------------------------------------- /tools/initbase/etc/hostname: -------------------------------------------------------------------------------- 1 | orange -------------------------------------------------------------------------------- /tools/pkg/0/mlibc/info.txt: -------------------------------------------------------------------------------- 1 | mlibc -------------------------------------------------------------------------------- /tools/pkg/12/i3wm/info.txt: -------------------------------------------------------------------------------- 1 | i3wm -------------------------------------------------------------------------------- /tools/pkg/3/nano/info.txt: -------------------------------------------------------------------------------- 1 | nano -------------------------------------------------------------------------------- /tools/pkg/5/orangeutils/info.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/pkg/6/terms/info.txt: -------------------------------------------------------------------------------- 1 | xterms -------------------------------------------------------------------------------- /tools/pkg/7/benchmark/info.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/pkg/7/glib/info.txt: -------------------------------------------------------------------------------- 1 | glib -------------------------------------------------------------------------------- /tools/pkg/7/python/info.txt: -------------------------------------------------------------------------------- 1 | python -------------------------------------------------------------------------------- /tools/pkg/8/llvm/info.txt: -------------------------------------------------------------------------------- 1 | llvm -------------------------------------------------------------------------------- /tools/pkg/9/mesa/info.txt: -------------------------------------------------------------------------------- 1 | mesa -------------------------------------------------------------------------------- /tools/initbase/root/.bash_history: -------------------------------------------------------------------------------- 1 | exit -------------------------------------------------------------------------------- /tools/pkg/1/nop/info.txt: -------------------------------------------------------------------------------- 1 | nop-process -------------------------------------------------------------------------------- /tools/pkg/10/gtk_final/info.txt: -------------------------------------------------------------------------------- 1 | gtk :) -------------------------------------------------------------------------------- /tools/pkg/2/ncurses/info.txt: -------------------------------------------------------------------------------- 1 | ncurses -------------------------------------------------------------------------------- /tools/pkg/3/bash/info.txt: -------------------------------------------------------------------------------- 1 | bash-5.2.21 -------------------------------------------------------------------------------- /tools/pkg/5/twm/info.txt: -------------------------------------------------------------------------------- 1 | twm and xapps -------------------------------------------------------------------------------- /tools/initbase/etc/X11/xinitrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | i3 -------------------------------------------------------------------------------- /tools/pkg/1/liborange/info.txt: -------------------------------------------------------------------------------- 1 | liborange -------------------------------------------------------------------------------- /tools/pkg/10/mesa-demos/info.txt: -------------------------------------------------------------------------------- 1 | mesa-demos -------------------------------------------------------------------------------- /tools/pkg/2/ps2_driver/info.txt: -------------------------------------------------------------------------------- 1 | ps2 driver -------------------------------------------------------------------------------- /tools/pkg/2/xhci_driver/info.txt: -------------------------------------------------------------------------------- 1 | xhci_driver -------------------------------------------------------------------------------- /tools/pkg/3/coreutils/info.txt: -------------------------------------------------------------------------------- 1 | coreutils -------------------------------------------------------------------------------- /tools/pkg/3/doomgeneric/info.txt: -------------------------------------------------------------------------------- 1 | doomgeneric -------------------------------------------------------------------------------- /tools/pkg/3/fastfetch/info.txt: -------------------------------------------------------------------------------- 1 | fastfetch -------------------------------------------------------------------------------- /tools/pkg/3/mouse_test/info.txt: -------------------------------------------------------------------------------- 1 | mousetest -------------------------------------------------------------------------------- /tools/pkg/3/poll_test/info.txt: -------------------------------------------------------------------------------- 1 | poll_test -------------------------------------------------------------------------------- /tools/pkg/4/xorg-server/info.txt: -------------------------------------------------------------------------------- 1 | xorg-server -------------------------------------------------------------------------------- /tools/pkg/6/xcb-stuff/info.txt: -------------------------------------------------------------------------------- 1 | xcb-stuff -------------------------------------------------------------------------------- /kernel/src/lib/Flanterm/.gitignore: -------------------------------------------------------------------------------- 1 | *.d 2 | *.o -------------------------------------------------------------------------------- /tools/base/etc/passwd: -------------------------------------------------------------------------------- 1 | root:x:0:0::/root:/bin/bash -------------------------------------------------------------------------------- /tools/initbase/etc/shells: -------------------------------------------------------------------------------- 1 | /bin/sh 2 | /bin/bash -------------------------------------------------------------------------------- /tools/pkg/1/pkg-config/info.txt: -------------------------------------------------------------------------------- 1 | pkg-config 2 | -------------------------------------------------------------------------------- /tools/pkg/11/other-stuff/info.txt: -------------------------------------------------------------------------------- 1 | other-stuff -------------------------------------------------------------------------------- /tools/pkg/3/pthread_test/info.txt: -------------------------------------------------------------------------------- 1 | ptherad_test -------------------------------------------------------------------------------- /tools/pkg/5/xorg-modules/info.txt: -------------------------------------------------------------------------------- 1 | xorg-modules -------------------------------------------------------------------------------- /tools/initbase/etc/passwd: -------------------------------------------------------------------------------- 1 | root:x:0:0::/root:/bin/bash -------------------------------------------------------------------------------- /tools/initbase/etc/init.sh: -------------------------------------------------------------------------------- 1 | cat /etc/orangesad 2 | orangeX -------------------------------------------------------------------------------- /tools/pkg/5/orangex/info.txt: -------------------------------------------------------------------------------- 1 | orangeX - x start script for orange -------------------------------------------------------------------------------- /tools/pkg/11/other-stuff/settings.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | gtk-font-name = DejaVu Sans 6 -------------------------------------------------------------------------------- /tools/img/qemu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/img/qemu.png -------------------------------------------------------------------------------- /tools/img/work.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/img/work.png -------------------------------------------------------------------------------- /tools/pkg/1/nop/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | x86_64-orange-mlibc-gcc src/main.cpp -o "$1/usr/bin/nop" -------------------------------------------------------------------------------- /tools/pkg/3/mouse_test/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | x86_64-orange-mlibc-gcc main.c -o "$1/usr/bin/mouse_test" -------------------------------------------------------------------------------- /tools/pkg/3/poll_test/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | x86_64-orange-mlibc-g++ -o "$1/usr/bin/poll_test" src/main.c -------------------------------------------------------------------------------- /tools/pkg/7/benchmark/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | x86_64-orange-mlibc-gcc main.c -o "$1/usr/bin/benchmark" -------------------------------------------------------------------------------- /clone-submodules.sh: -------------------------------------------------------------------------------- 1 | cd kernel/src/lib 2 | git clone https://github.com/uACPI/uACPI.git --depth=1 -------------------------------------------------------------------------------- /tools/base/boot/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/base/boot/bg.jpg -------------------------------------------------------------------------------- /tools/img/oldwork2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/img/oldwork2.png -------------------------------------------------------------------------------- /tools/img/workold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/img/workold.png -------------------------------------------------------------------------------- /tools/pkg/3/pthread_test/pkg.sh: -------------------------------------------------------------------------------- 1 | x86_64-orange-mlibc-g++ -o "$1/usr/bin/pthread_test" main.c -fPIC -------------------------------------------------------------------------------- /code_of_conduct.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | why not to add it to add repo health 4 | dont be dumb 5 | -------------------------------------------------------------------------------- /tools/initbase/etc/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/initbase/etc/bg.jpg -------------------------------------------------------------------------------- /tools/pkg/5/orangex/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | cp -rf main.sh "$1/usr/bin/orangeX" 3 | chmod +x "$1/usr/bin/orangeX" -------------------------------------------------------------------------------- /tools/initbase/etc/twmbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/initbase/etc/twmbg.png -------------------------------------------------------------------------------- /tools/pkg/7/benchmark/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppLover0/Orange/HEAD/tools/pkg/7/benchmark/a.out -------------------------------------------------------------------------------- /tools/pkg/5/orangex/main.sh: -------------------------------------------------------------------------------- 1 | 2 | stty -echo 3 | xinit /etc/X11/xinitrc > /dev/null 2> /dev/null 4 | stty +echo -------------------------------------------------------------------------------- /tools/initbase/etc/python/input_test.py: -------------------------------------------------------------------------------- 1 | user_input = input("Print something: ") 2 | print("You wrote:", user_input) -------------------------------------------------------------------------------- /tools/pkg/1/nop/src/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | while(1) { 4 | asm volatile("nop"); 5 | } 6 | } -------------------------------------------------------------------------------- /tools/pkg/1/liborange/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | mkdir -p "$1/usr/include/orange" 3 | 4 | cp -rf include/* "$1/usr/include/orange/" 5 | -------------------------------------------------------------------------------- /refresh-initrd.sh: -------------------------------------------------------------------------------- 1 | cp -rf tools/initbase/* initrd 2 | 3 | mkdir -p tools/base/boot 4 | tar -cf tools/base/boot/initrd.tar -C initrd . 5 | -------------------------------------------------------------------------------- /tools/pkg/2/ps2_driver/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | mkdir -p "$1/etc/drivers/" 3 | 4 | x86_64-orange-mlibc-gcc -o "$1/etc/drivers/i8042controller.sys" src/main.c -------------------------------------------------------------------------------- /kernel/.gitignore: -------------------------------------------------------------------------------- 1 | /compile_commands.json 2 | /.cache 3 | /freestnd-c-hdrs 4 | /freestnd-cxx-hdrs 5 | /cc-runtime 6 | /src/limine.h 7 | /bin 8 | /obj 9 | -------------------------------------------------------------------------------- /tools/initbase/etc/localtime: -------------------------------------------------------------------------------- 1 | TZif2UTCTZif2UTC 2 | UTC0 3 | -------------------------------------------------------------------------------- /tools/pkg/2/xhci_driver/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | mkdir -p "$1/etc/drivers/" 3 | 4 | x86_64-orange-mlibc-g++ -o "$1/etc/drivers/xhcidriver.sys" src/main.cpp -Iinclude -std=c++17 -------------------------------------------------------------------------------- /kernel/include/drivers/acpi.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | namespace drivers { 4 | class acpi { 5 | public: 6 | static void init(); 7 | }; 8 | }; -------------------------------------------------------------------------------- /tools/limine.conf: -------------------------------------------------------------------------------- 1 | 2 | wallpaper: boot():/boot/bg.jpg 3 | wallpaper_style: stretched 4 | 5 | timeout: 3 6 | /Orange 7 | protocol: limine 8 | path: boot():/boot/kernel 9 | module_path: boot():/boot/initrd.tar -------------------------------------------------------------------------------- /tools/pkg/9/mesa/glx.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr 2 | includedir=${prefix}/include 3 | libdir=${prefix}/lib 4 | 5 | Name: GLX 6 | Description: GLX library and headers. 7 | Version: 1.4 8 | Libs: -L${libdir} -lGL 9 | Cflags: -I${includedir} -------------------------------------------------------------------------------- /kernel/src/main.asm: -------------------------------------------------------------------------------- 1 | 2 | section .text 3 | 4 | extern main 5 | global kmain 6 | kmain: 7 | mov rsp,stack_top 8 | call main 9 | hlt 10 | 11 | section .data 12 | stack_bottom: 13 | resb 1024*128 14 | stack_top: -------------------------------------------------------------------------------- /tools/pkg/12/i3wm/yajl.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr 2 | libdir=/usr/lib 3 | includedir=/usr/include 4 | 5 | Name: Yet Another JSON Library 6 | Description: A Portable JSON parsing and serialization library in ANSI C 7 | Version: old asf 8 | Cflags: 9 | Libs: -L/usr/lib -lyajl -------------------------------------------------------------------------------- /tools/base/root/.bashrc: -------------------------------------------------------------------------------- 1 | PS1='\e[92m\u\e[0m@\e[38;5;214morange\e[0m-# ' 2 | export TERM="linux" 3 | export SHELL="/bin/bash" 4 | export PATH="/usr/bin" 5 | 6 | # gcc defaults to /usr/local/include so i'll set include to /usr 7 | export C_INCLUDE_PATH="/usr/include" 8 | -------------------------------------------------------------------------------- /tools/initbase/root/.bashrc: -------------------------------------------------------------------------------- 1 | PS1='\e[92m\u\e[0m@\e[38;5;214morange\e[0m-# ' 2 | export TERM="linux" 3 | export SHELL="/bin/bash" 4 | export PATH="/usr/bin" 5 | 6 | # gcc defaults to /usr/local/include so i'll set include to /usr 7 | export C_INCLUDE_PATH="/usr/include" 8 | -------------------------------------------------------------------------------- /kernel/include/config.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define KHEAP_SIZE (1024*1024*16) 5 | #define KERNEL_STACK_SIZE (1024*256) 6 | #define SYSCALL_STACK_SIZE (1024*64) 7 | #define USERSPACE_PIPE_SIZE (1024*64) 8 | #define DIRECTORY_LIST_SIZE (1024*8) 9 | #define USERSPACE_STACK_SIZE (1024*1024*8) -------------------------------------------------------------------------------- /kernel/include/drivers/hpet.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | namespace drivers { 7 | class hpet { 8 | public: 9 | static void init(); 10 | static void sleep(std::uint64_t us); 11 | static std::uint64_t nanocurrent(); 12 | }; 13 | } -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/cpu/smp.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | namespace arch { 5 | namespace x86_64 { 6 | namespace cpu { 7 | class mp { 8 | public: 9 | static void init(); 10 | static void sync(std::uint8_t id); 11 | }; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /tools/initbase/etc/X11/xorg.conf: -------------------------------------------------------------------------------- 1 | Section "Module" 2 | Load "fbdev" 3 | EndSection 4 | 5 | Section "Device" 6 | Identifier "Card0" 7 | Driver "fbdev" 8 | EndSection 9 | 10 | Section "InputDevice" 11 | Identifier "Keyboard" 12 | Driver "kbd" 13 | Option "Device" "/dev/ps2keyboard" 14 | Option "Protocol" "Standard" 15 | EndSection -------------------------------------------------------------------------------- /tools/pkg/7/games/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | rm -rf pack 4 | 5 | mkdir -p pack 6 | 7 | cd pack 8 | 9 | export CFLAGS="-Wno-incompatible-pointer-types -Wno-error -fPIC -Wno-implicit-function-declaration" 10 | 11 | fast_install "$1" https://www.delorie.com/store/ace/ace-1.4.tar.gz "--enable-shared" "../../diff/ace.diff" 12 | 13 | cd ../ -------------------------------------------------------------------------------- /kernel/include/generic/time.hpp: -------------------------------------------------------------------------------- 1 | 2 | /* It will connect all timers together */ 3 | 4 | #include 5 | 6 | #pragma once 7 | 8 | #define TSC_TIMER 0 9 | #define KVM_TIMER 1 10 | #define HPET_TIMER 2 11 | 12 | class time { 13 | public: 14 | 15 | static std::uint64_t counter(); 16 | 17 | static void sleep(std::uint64_t us); 18 | }; -------------------------------------------------------------------------------- /tools/pkg/12/i3wm/yajl_version.h: -------------------------------------------------------------------------------- 1 | #ifndef YAJL_VERSION_H_ 2 | #define YAJL_VERSION_H_ 3 | 4 | #include 5 | 6 | #define YAJL_VERSION 211 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | extern int YAJL_API yajl_version(void); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* YAJL_VERSION_H_ */ 18 | 19 | -------------------------------------------------------------------------------- /tools/pkg/12/i3wm/xcb-xrm.pc.in: -------------------------------------------------------------------------------- 1 | 2 | prefix=/usr 3 | exec_prefix=${prefix} 4 | libdir=${exec_prefix}/lib 5 | includedir=${prefix}/include 6 | 7 | Name: XCB XRM library 8 | Description: XCB X resource manager utility functions 9 | Version: 52 10 | Requires: xcb 11 | Requires.private: xcb-aux 12 | Libs: -L${libdir} -lxcb-xrm 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/cpu/asm/gdt.asm: -------------------------------------------------------------------------------- 1 | global loadgdt 2 | loadgdt: 3 | lgdt [rdi] 4 | mov ax,0 5 | mov ds,ax 6 | mov es,ax 7 | mov fs,ax 8 | mov gs,ax 9 | mov ss,ax 10 | pop rdi 11 | mov rax,0x08 12 | push rax 13 | push rdi 14 | retfq 15 | 16 | global loadtss 17 | loadtss: 18 | mov ax,0x28 19 | ltr ax 20 | ret -------------------------------------------------------------------------------- /tools/pkg/toolchain.cmake: -------------------------------------------------------------------------------- 1 | 2 | set(CMAKE_SYSTEM_NAME Orange) 3 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 4 | 5 | set(CMAKE_C_COMPILER x86_64-orange-mlibc-gcc) 6 | set(CMAKE_CXX_COMPILER x86_64-orange-mlibc-g++) 7 | set(CMAKE_LINKER x86_64-orange-mlibc-ld) 8 | 9 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 10 | 11 | set(CMAKE_CXX_EXTENSIONS ON) 12 | set(CMAKE_C_EXTENSIONS ON) -------------------------------------------------------------------------------- /tools/pkg/3/lua/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | rm -rf pack 4 | mkdir -p pack 5 | 6 | cd pack 7 | 8 | wget https://www.lua.org/ftp/lua-5.4.7.tar.gz 9 | 10 | tar -xvf lua-5.4.7.tar.gz 11 | cd lua-5.4.7 12 | 13 | make CC=x86_64-orange-mlibc-gcc LD=x86_64-orange-mlibc-ld generic -j$(nproc) 14 | cp -rf src/lua "$1/usr/bin" 15 | cp -rf src/luac "$1/usr/bin" 16 | 17 | cd .. -------------------------------------------------------------------------------- /tools/pkg/x86_64-orange.crossfile: -------------------------------------------------------------------------------- 1 | [binaries] 2 | c = 'x86_64-orange-mlibc-gcc' 3 | cpp = 'x86_64-orange-mlibc-g++' 4 | ar = 'x86_64-orange-mlibc-ar' 5 | nm = 'x86_64-orange-mlibc-nm' 6 | ld = 'x86_64-orange-mlibc-ld' 7 | pkg-config = 'x86_64-orange-mlibc-pkg-config' 8 | 9 | [host_machine] 10 | system = 'orange' 11 | cpu_family = 'x86_64' 12 | cpu = 'x86_64' 13 | endian = 'little' -------------------------------------------------------------------------------- /tools/pkg/5/orangeutils/src/orangedebugenable.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | if (argc < 2) { 6 | printf("Usage: %s \n", argv[0]); 7 | return 1; 8 | } 9 | 10 | int pid = atoi(argv[1]); 11 | 12 | asm volatile("syscall" : : "a"(65), "D"(pid) : "rcx","r11"); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /tools/pkg/5/orangeutils/src/orangeprintinfo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | if (argc < 2) { 6 | printf("Usage: %s \n", argv[0]); 7 | return 1; 8 | } 9 | 10 | int pid = atoi(argv[1]); 11 | 12 | asm volatile("syscall" : : "a"(63), "D"(pid) : "rcx","r11"); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /tools/pkg/5/orangeutils/src/orangedebug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | if (argc < 2) { 6 | printf("Usage: %s [args...]\n", argv[0]); 7 | return 1; 8 | } 9 | 10 | asm volatile("syscall" : : "a"(53) : "rcx","r11"); 11 | 12 | execvp(argv[1], &argv[1]); 13 | perror("execvp"); 14 | return 1; 15 | } -------------------------------------------------------------------------------- /tools/initbase/etc/X11/test.sh: -------------------------------------------------------------------------------- 1 | xeyes & 2 | xeyes & 3 | xeyes & 4 | xeyes & 5 | xeyes & 6 | xeyes & 7 | xeyes & 8 | xeyes & 9 | xeyes & 10 | xeyes & 11 | xeyes & 12 | xeyes & 13 | xeyes & 14 | xeyes & 15 | xeyes & 16 | xeyes & 17 | xeyes & 18 | xeyes & 19 | xeyes & 20 | xeyes & 21 | xeyes & 22 | xeyes & 23 | xeyes & 24 | xeyes & 25 | xeyes & 26 | xeyes & 27 | xeyes & 28 | xeyes & 29 | xeyes & 30 | xeyes & 31 | -------------------------------------------------------------------------------- /kernel/include/drivers/tsc.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #pragma once 6 | 7 | namespace drivers { 8 | class tsc { 9 | public: 10 | static void init(); 11 | static void cpuinit(); 12 | static void sleep(std::uint64_t us); 13 | static std::uint64_t currentnano(); 14 | static std::uint64_t currentus(); 15 | }; 16 | }; -------------------------------------------------------------------------------- /tools/pkg/7/doomgeneric/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | rm -rf pack 4 | 5 | mkdir -p pack 6 | 7 | cd pack 8 | 9 | echo $1 10 | 11 | git clone https://github.com/ozkl/doomgeneric.git --depth=1 12 | cd doomgeneric 13 | 14 | diff_patch ../../diff/doomgeneric.diff 15 | cd doomgeneric 16 | make -j$(nproc) 17 | 18 | rm -rf "$1/usr/bin/doomgeneric" 19 | cp -rf doomgeneric "$1/usr/bin/doomgeneric-x11" 20 | 21 | cd ../ -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/interrupts/pit.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | #define PIT_FREQUENCY 1193182 7 | 8 | namespace arch { 9 | namespace x86_64 { 10 | namespace interrupts { 11 | class pit { 12 | public: 13 | static void init(); 14 | static void sleep(std::uint32_t ms); 15 | }; 16 | }; 17 | }; 18 | }; -------------------------------------------------------------------------------- /tools/pkg/5/orangeutils/pkg.sh: -------------------------------------------------------------------------------- 1 | x86_64-orange-mlibc-gcc src/orangedebugenable.c -o "$1/usr/bin/orangedebugenable" -Wno-implicit-function-declaration 2 | x86_64-orange-mlibc-gcc src/orangeprintinfo.c -o "$1/usr/bin/orangeprintinfo" -Wno-implicit-function-declaration 3 | x86_64-orange-mlibc-gcc src/orangedebug.c -o "$1/usr/bin/orangedebug" -Wno-implicit-function-declaration 4 | x86_64-orange-mlibc-gcc src/dmesg.c -o "$1/usr/bin/dmesg" -Wno-implicit-function-declaration -------------------------------------------------------------------------------- /tools/pkg/3/coreutils/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | mkdir -p cached 4 | 5 | rm -rf pack 6 | 7 | mkdir -p pack 8 | 9 | cd pack 10 | 11 | installgnu coreutils coreutils 9.7 12 | mkdir -p coreutils-build 13 | 14 | cd coreutils-9.7 15 | diff_patch ../../diff/coreutils.diff 16 | patch_config_sub "$(realpath $1/..)" 17 | cd .. 18 | 19 | cd coreutils-build 20 | ../coreutils-9.7/configure --host=x86_64-orange-mlibc --prefix="/usr" 21 | make install-strip -j$(nproc) DESTDIR="$1" 22 | 23 | cd .. 24 | -------------------------------------------------------------------------------- /tools/pkg/3/nano/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | mkdir -p cached 4 | 5 | rm -rf pack 6 | 7 | mkdir -p pack 8 | 9 | cd pack 10 | 11 | installgnu nano nano 8.4 12 | mkdir -p nano-build 13 | 14 | cd nano-8.4 15 | diff_patch ../../diff/nano.diff 16 | patch_config_sub "$(realpath $1/..)" 17 | cd .. 18 | 19 | cd nano-build 20 | ../nano-8.4/configure --host=x86_64-orange-mlibc --prefix="/usr" gl_cv_func_strcasecmp_works=yes CFLAGS="-std=gnu17" 21 | make install -j$(nproc) DESTDIR="$1" 22 | 23 | cd .. -------------------------------------------------------------------------------- /tools/linux-headers.sh: -------------------------------------------------------------------------------- 1 | if [ ! -d "./linux-headers" ]; then 2 | mkdir -p temp 3 | mkdir -p linux-headers 4 | git clone https://github.com/torvalds/linux.git --depth=1 5 | cd linux 6 | make headers_install ARCH=x86_64 INSTALL_HDR_PATH="$(realpath ../temp)" 7 | cd .. 8 | cp -rf temp/include/* linux-headers 9 | rm -rf temp 10 | rm -rf linux 11 | fi 12 | 13 | echo Copying linux-headers... 14 | mkdir -p "$1/initrd/usr/include" 15 | cp -rf linux-headers/* "$1/initrd/usr/include" -------------------------------------------------------------------------------- /tools/pkg/5/twm/diff/fontconfig.diff: -------------------------------------------------------------------------------- 1 | diff -Naur fontconfig-2.13.94/src/fcstat.c fontconfig-patched/src/fcstat.c 2 | --- fontconfig-2.13.94/src/fcstat.c 2020-12-03 14:45:00.000000000 +0300 3 | +++ fontconfig-patched/src/fcstat.c 2025-10-26 08:27:40.889979729 +0300 4 | @@ -386,7 +386,7 @@ 5 | # endif 6 | # if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) 7 | p = buf.f_fstypename; 8 | -# elif defined(__linux__) 9 | +# elif defined(__linux__) || defined(__orange__) 10 | switch (buf.f_type) 11 | { 12 | case 0x6969: /* nfs */ 13 | -------------------------------------------------------------------------------- /tools/pkg/7/glib/diff/glib.diff: -------------------------------------------------------------------------------- 1 | diff --git glib2-clean/gio/gcredentialsprivate.h glib2-workdir/gio/gcredentialsprivate.h 2 | index 0310a75..dba61e6 100644 3 | --- glib2-clean/gio/gcredentialsprivate.h 4 | +++ glib2-workdir/gio/gcredentialsprivate.h 5 | @@ -104,7 +104,7 @@ 6 | */ 7 | #undef G_CREDENTIALS_HAS_PID 8 | 9 | -#ifdef __linux__ 10 | +#if defined(__linux__) || defined(__orange__) 11 | #define G_CREDENTIALS_SUPPORTED 1 12 | #define G_CREDENTIALS_USE_LINUX_UCRED 1 13 | #define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_LINUX_UCRED -------------------------------------------------------------------------------- /tools/pkg/6/xcb-stuff/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | mkdir pack 6 | 7 | cd pack 8 | 9 | fast_install "$1" https://www.x.org/releases/individual/xcb/xcb-util-0.4.1.tar.gz 10 | fast_install "$1" https://www.x.org/releases/individual/xcb/xcb-util-image-0.4.1.tar.gz 11 | 12 | git clone https://github.com/stoeckmann/xwallpaper.git 13 | 14 | cd xwallpaper 15 | 16 | ./autogen.sh 17 | autotools_recursive_regen 18 | ./configure --host=x86_64-orange-mlibc --prefix="/usr" 19 | make -j$(nproc) 20 | make install DESTDIR="$1" 21 | 22 | cd .. -------------------------------------------------------------------------------- /kernel/include/etc/bootloaderinfo.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | class BootloaderInfo { 8 | public: 9 | static struct limine_framebuffer* AccessFramebuffer(); 10 | static std::uint64_t AccessHHDM(); 11 | static std::uint64_t AccessRSDP(); 12 | static struct limine_memmap_response* AccessMemoryMap(); 13 | static struct limine_executable_address_response* AccessKernel(); 14 | static struct LIMINE_MP(response)* AccessMP(); 15 | static struct limine_module_response* AccessInitrd(); 16 | }; -------------------------------------------------------------------------------- /kernel/include/generic/mm/heap.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #pragma once 6 | 7 | typedef struct heap_block { 8 | std::uint32_t size; 9 | std::uint8_t is_free; 10 | struct heap_block* next; 11 | } heap_block_t; 12 | 13 | namespace memory { 14 | class heap { 15 | public: 16 | static void init(); 17 | static void free(void* ptr); 18 | static void* malloc(std::uint32_t size); 19 | 20 | static void lock(); 21 | static void unlock(); 22 | }; 23 | }; -------------------------------------------------------------------------------- /tools/initbase/etc/python/raw_input_test.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import tty 3 | import termios 4 | 5 | def get_char(): 6 | fd = sys.stdin.fileno() 7 | old_settings = termios.tcgetattr(fd) 8 | try: 9 | tty.setraw(fd) 10 | ch = sys.stdin.read(1) 11 | finally: 12 | termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 13 | return ch 14 | 15 | print("Write something (q - quit):") 16 | while True: 17 | char = get_char() 18 | print(f"You pressed: {repr(char)}") 19 | if char == 'q': 20 | print("Exiting") 21 | break -------------------------------------------------------------------------------- /tools/pkg/10/mesa-demos/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | 6 | mkdir -p pack 7 | 8 | cd pack 9 | 10 | wget https://archive.mesa3d.org/demos/mesa-demos-9.0.0.tar.xz 11 | tar -xvf mesa-demos-9.0.0.tar.xz 12 | 13 | cd mesa-demos-9.0.0 14 | 15 | mkdir build 16 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dgles1=disabled -Dosmesa=disabled -Dlibdrm=disabled -Dx11=enabled -Dwith-system-data-files=true build 17 | 18 | cd build 19 | 20 | meson compile -j$(nproc) 21 | DESTDIR="$1" meson install --no-rebuild 22 | 23 | cd ../.. 24 | 25 | cd .. -------------------------------------------------------------------------------- /tools/pkg/2/init/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | rm -rf pack 3 | mkdir -p pack/lib 4 | 5 | cd pack/lib/ 6 | git clone https://codeberg.org/Mintsuki/Flanterm.git 7 | cd ../../ 8 | 9 | x86_64-orange-mlibc-g++ -c src/main.cpp -o "pack/init.o" -Ipack/lib/Flanterm/src -Isrc/include 10 | x86_64-orange-mlibc-gcc -c pack/lib/Flanterm/src/flanterm.c -o pack/flanterm.o -Ipack/lib/Flanterm/src 11 | x86_64-orange-mlibc-gcc -c pack/lib/Flanterm/src/flanterm_backends/fb.c -o pack/flanterm_backends.o -Ipack/lib/Flanterm/src 12 | 13 | x86_64-orange-mlibc-g++ -o "$1/usr/bin/init" pack/init.o pack/flanterm.o pack/flanterm_backends.o 14 | -------------------------------------------------------------------------------- /tools/pkg/3/fastfetch/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | rm -rf pack 4 | 5 | mkdir -p pack 6 | 7 | cd pack 8 | 9 | echo $1 10 | 11 | wget https://github.com/fastfetch-cli/fastfetch/archive/refs/tags/2.44.0.tar.gz 12 | 13 | tar -xvf 2.44.0.tar.gz 14 | 15 | cd fastfetch-2.44.0 16 | diff_patch ../../diff/fastfetch.diff 17 | patch_config_sub "$(realpath $1/..)" 18 | cd .. 19 | 20 | mkdir -p fastfetch-build 21 | cd fastfetch-build 22 | cmake ../fastfetch-2.44.0 -DCMAKE_TOOLCHAIN_FILE=$(realpath ../../../../toolchain.cmake) -DCMAKE_INSTALL_PREFIX="$1/usr" 23 | 24 | make -j$(nproc) 25 | make install 26 | 27 | cd .. -------------------------------------------------------------------------------- /kernel/include/drivers/kvmtimer.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | struct pvclock_vcpu_time_info { 7 | std::uint32_t version; 8 | std::uint32_t pad0; 9 | std::uint64_t tsc_timestamp; 10 | std::uint64_t system_time; 11 | std::uint32_t tsc_to_system_mul; 12 | std::int8_t tsc_shift; 13 | std::uint8_t flags; 14 | std::uint8_t pad[2]; 15 | }; 16 | 17 | namespace drivers { 18 | class kvmclock { 19 | public: 20 | static void init(); 21 | static void sleep(std::uint64_t us); 22 | 23 | static std::uint64_t currentnano(); 24 | }; 25 | }; -------------------------------------------------------------------------------- /tools/pkg/3/doomgeneric/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | rm -rf pack 4 | 5 | mkdir -p pack 6 | 7 | cd pack 8 | 9 | echo $1 10 | 11 | git clone https://github.com/ozkl/doomgeneric.git --depth=1 12 | cd doomgeneric 13 | 14 | diff_patch ../../diff/doomgeneric.diff 15 | cd doomgeneric 16 | make -j$(nproc) 17 | 18 | rm -rf "$1/usr/bin/doomgeneric" 19 | cp -rf doomgeneric "$1/usr/bin/doomgeneric-fbdev" 20 | 21 | old="$(pwd)" 22 | cd "$1/usr/share" 23 | curl -O https://ia804501.us.archive.org/24/items/theultimatedoom_doom2_doom.wad/DOOM.WAD%20%28For%20GZDoom%29/DOOM.WAD 24 | cd "$old" 25 | 26 | cd .. 27 | 28 | cd ../ -------------------------------------------------------------------------------- /tools/pkg/5/twm/diff/libxt.diff: -------------------------------------------------------------------------------- 1 | diff -Naur libXt-1.2.1/src/Shell.c libXt-patched/src/Shell.c 2 | --- libXt-1.2.1/src/Shell.c 2021-01-24 17:47:39.000000000 +0300 3 | +++ libXt-patched/src/Shell.c 2025-10-26 08:06:07.473650705 +0300 4 | @@ -1003,10 +1003,10 @@ 5 | static void 6 | _XtShellAncestorSensitive(Widget widget, int closure, XrmValue *value) 7 | { 8 | - static Boolean true = True; 9 | + int xx = 1; 10 | 11 | if (widget->core.parent == NULL) 12 | - value->addr = (XPointer) (&true); 13 | + value->addr = (XPointer) (&xx); 14 | else 15 | _XtCopyFromParent(widget, closure, value); 16 | } 17 | -------------------------------------------------------------------------------- /tools/pkg/1/liborange/include/log.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | #define LEVEL_MESSAGE_OK 0 7 | #define LEVEL_MESSAGE_FAIL 1 8 | #define LEVEL_MESSAGE_WARN 2 9 | #define LEVEL_MESSAGE_INFO 3 10 | 11 | const char* level_messages[] = { 12 | [LEVEL_MESSAGE_OK] = "[ \x1b[38;2;0;255;0mOK\033[0m ] ", 13 | [LEVEL_MESSAGE_FAIL] = "[ \x1b[38;2;255;0;0mFAILED\033[0m ] ", 14 | [LEVEL_MESSAGE_WARN] = "[ \x1b[38;2;255;165;0mWARN\033[0m ] ", 15 | [LEVEL_MESSAGE_INFO] = "[ \x1b[38;2;0;191;255mINFO\033[0m ] " 16 | }; 17 | 18 | #define log(level, format,...) printf("%s" format "", level_messages[level], ##__VA_ARGS__) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | orange 3 | orange.iso 4 | obj 5 | serial.txt 6 | trash 7 | .code 8 | serial_output.txt 9 | kernel-deps 10 | /limine 11 | initrd/usr/include 12 | kernel/bin 13 | kernel/cc-runtime 14 | kernel/cc-runtime-x86_64 15 | kernel/freestnd-c-hdrs 16 | kernel/freestnd-cxx-hdrs 17 | main.o 18 | .jinx-cache 19 | serial.txt 20 | output.txt 21 | Orange-distro-build 22 | ovmf 23 | cached 24 | .vscode 25 | initrd/usr/lib 26 | initrd/usr/include 27 | initrd 28 | orange-mlibc 29 | sources 30 | ./initrd 31 | qemu_log.txt 32 | orange.hdd 33 | ./tools/toolchain/pack 34 | pack 35 | initrd.tar 36 | qemu.txt 37 | build-x86_64 38 | linux-headers -------------------------------------------------------------------------------- /tools/pkg/5/orangeutils/src/dmesg.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | uint64_t dmesg(char* buffer, uint64_t count) { 10 | int ret; 11 | uint64_t size; 12 | asm volatile("syscall" : "=a"(ret), "=d"(size) : "a"(64), "D"(buffer), "S"(count) : "rcx","r11"); 13 | return size; 14 | } 15 | 16 | int main() { 17 | printf("Orange dmesg utility\n"); 18 | uint64_t size = dmesg(0,0); 19 | char* buffer = malloc(size + 1); 20 | memset(buffer,0,size); 21 | dmesg(buffer,size); 22 | write(STDOUT_FILENO,buffer,size); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /tools/pkg/3/bash/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | mkdir -p cached 4 | 5 | rm -rf pack 6 | 7 | mkdir -p pack 8 | 9 | cd pack 10 | 11 | fast_install "$1" $GNU_MIRROR/gnu/gettext/gettext-0.26.tar.gz "--enable-shared" ../../diff/gettext.diff 12 | 13 | installgnu bash bash 5.2.21 14 | mkdir -p bash-build 15 | 16 | cd bash-5.2.21 17 | patch_config_sub "$(realpath $1/..)" 18 | cd .. 19 | 20 | cd bash-build 21 | ../bash-5.2.21/configure --host=x86_64-orange-mlibc --prefix="/usr" --disable-readline --with-curses --without-bash-malloc CFLAGS="-std=gnu17 -fPIC -Os" 22 | make install-strip -j$(nproc) DESTDIR="$1" 23 | 24 | cz=$(pwd) 25 | 26 | cd "$1/usr/bin" 27 | ln -sf bash sh 28 | 29 | cd "$cz" 30 | 31 | cd .. -------------------------------------------------------------------------------- /tools/pkg/2/ncurses/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | mkdir -p cached 4 | 5 | rm -rf pack 6 | 7 | mkdir -p pack 8 | 9 | cd pack 10 | 11 | installgnu ncurses ncurses 6.5 12 | mkdir -p ncurses-build 13 | 14 | cd ncurses-6.5 15 | diff_patch ../../diff/ncurses.diff 16 | patch_config_sub "$(realpath $1/..)" 17 | cd .. 18 | 19 | cd ncurses-build 20 | ../ncurses-6.5/configure --host=x86_64-orange-mlibc --prefix="/usr" --with-shared --without-ada CFLAGS="-std=gnu17" 21 | make -j$(nproc) 22 | make install -j$(nproc) DESTDIR="$1" 23 | 24 | cd .. 25 | 26 | cz=$(pwd) 27 | 28 | cd "$1/usr/lib" 29 | ln -sf libncursesw.so libcurses.so 30 | ln -sf libncursesw.so libcursesw.so 31 | 32 | ln -sf libtinfow.so libtinfo.so 33 | 34 | cd "$cz" 35 | -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/interrupts/irq.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | #define IRQ_TYPE_OTHER 0 7 | #define IRQ_TYPE_LEGACY 1 8 | #define IRQ_TYPE_MSI 2 9 | #define IRQ_TYPE_LEGACY_USERSPACE 3 10 | 11 | typedef struct { 12 | void (*func)(void* arg); 13 | void* arg; 14 | int irq; 15 | char is_userspace; 16 | } irq_t; 17 | 18 | namespace arch { 19 | namespace x86_64 { 20 | namespace interrupts { 21 | class irq { 22 | public: 23 | static std::uint8_t create(std::uint16_t irq,std::uint8_t type,void (*func)(void* arg),void* arg,std::uint64_t flags); 24 | static void reset(); 25 | }; 26 | }; 27 | }; 28 | }; -------------------------------------------------------------------------------- /tools/pkg/1/pkg-config/diff/pkg-config.diff: -------------------------------------------------------------------------------- 1 | diff -Naur pkg-config-0.29.2/config.sub pkg-config-patched/config.sub 2 | --- pkg-config-0.29.2/config.sub 2015-09-27 17:07:23.000000000 +0300 3 | +++ pkg-config-patched/config.sub 2025-10-14 19:04:15.422008115 +0300 4 | @@ -1393,7 +1393,7 @@ 5 | | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ 6 | | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ 7 | | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ 8 | - | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) 9 | + | -skyos* | -haiku* | -orange* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) 10 | # Remember, each alternative MUST END IN *, to match a version number. 11 | ;; 12 | -qnx*) 13 | -------------------------------------------------------------------------------- /kernel/include/generic/vfs/ustar.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | namespace vfs { 5 | 6 | typedef struct { 7 | char file_name[100]; 8 | char file_mode[8]; 9 | char owner_id[8]; 10 | char group_id[8]; 11 | char file_size[12]; 12 | char last_modific[12]; 13 | char checksum[8]; 14 | char type; 15 | char name_linked[100]; 16 | char ustar[6]; 17 | char ustar_ver[2]; 18 | char owner_name[32]; 19 | char group_name[32]; 20 | char dev_major_num[8]; 21 | char dev_minor_num[8]; 22 | char filename_prefix[155]; 23 | } __attribute__((packed)) ustar_header_t; 24 | 25 | class ustar { 26 | public: 27 | static void copy(); 28 | }; 29 | }; -------------------------------------------------------------------------------- /tools/initbase/etc/orangesad: -------------------------------------------------------------------------------- 1 | 2 | 3 | ▓█▒ 4 | ▒▓▓██ 5 | ▒█▓▓█░ ░░░░░░ 6 | █▓▓█▒ ░██▒▒▒▒▒▒▒▒▒▒██░ 7 | ▒█▓▓███▓█▓█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒ 8 | █▓▓▓▒▒▒▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░ 9 | ▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░ 10 | █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█ 11 | █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█ 12 | ▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░ 13 | █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒░ 14 | ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░ 15 | █▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▓▒▒▒▒▒▒▓▓ 16 | █▒▒▒▒▒▒▒▒▒▒▒▒▒█▓▒▒▒▒▒▒▒▒▒█▒ 17 | █▒▒▒▒▒▒▒▒▒▒▓▒▒▒▒▒▒▒▒▒▒▒█ 18 | ░█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█ 19 | ██▒▒▒▒▒▒▒▒▒▒▒▒▓ 20 | ░▒▓████▒░ 21 | 22 | -------------------------------------------------------------------------------- /tools/pkg/3/nano/diff/nano.diff: -------------------------------------------------------------------------------- 1 | diff -Naur nano-8.4/config.sub nano-patched/config.sub 2 | --- nano-8.4/config.sub 2022-01-31 17:43:17.000000000 +0300 3 | +++ nano-patched/config.sub 2025-06-02 10:06:02.670396019 +0300 4 | @@ -1750,7 +1750,7 @@ 5 | | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ 6 | | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ 7 | | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ 8 | - | skyos* | haiku* | rdos* | toppers* | drops* | es* \ 9 | + | skyos* | orange* | haiku* | rdos* | toppers* | drops* | es* \ 10 | | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ 11 | | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ 12 | | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ -------------------------------------------------------------------------------- /kernel/src/etc/libc.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | 6 | char *strtok(char *str, const char *delim) { 7 | static char *next = NULL; 8 | if (str) next = str; 9 | if (!next) return NULL; 10 | 11 | char *start = next; 12 | while (*start && strchr(delim, *start)) { 13 | start++; 14 | } 15 | if (!*start) { 16 | next = NULL; 17 | return NULL; 18 | } 19 | 20 | char *end = start; 21 | while (*end && !strchr(delim, *end)) { 22 | end++; 23 | } 24 | 25 | if (*end) { 26 | *end = '\0'; 27 | next = end + 1; 28 | } else { 29 | next = NULL; 30 | } 31 | 32 | return start; 33 | } 34 | 35 | int strlen(const char* str) { 36 | int idx = 0; 37 | while(str[idx]) 38 | idx++; 39 | return idx; 40 | } -------------------------------------------------------------------------------- /kernel/include/generic/vfs/tmpfs.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #pragma once 6 | 7 | #define TMPFS_TYPE_NONE 0 8 | #define TMPFS_TYPE_FILE 1 9 | #define TMPFS_TYPE_DIRECTORY 2 10 | #define TMPFS_TYPE_SYMLINK 3 11 | 12 | namespace vfs { 13 | 14 | typedef struct tmpfs_node { 15 | std::uint64_t size; 16 | std::uint64_t busy; 17 | std::uint64_t vars[8]; 18 | std::uint8_t type; 19 | std::uint8_t* content; 20 | std::uint64_t real_size; // real size in ram (optimization) 21 | struct tmpfs_node* next; 22 | char name[2048]; 23 | } tmpfs_node_t; 24 | 25 | class tmpfs { 26 | public: 27 | static void mount(vfs_node_t* node); 28 | }; 29 | }; 30 | 31 | #define NODE_POOL_BLOCK_SIZE (16 * 1024 * 1024) 32 | 33 | struct NodePoolBlock { 34 | vfs::tmpfs_node_t* block; 35 | NodePoolBlock* next; 36 | }; 37 | -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/interrupts/pit.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace arch::x86_64::interrupts; 9 | 10 | std::uint64_t pit_counter = 0; 11 | 12 | void __pit_int_handler(void *arg) { 13 | pit_counter++; 14 | } 15 | 16 | void arch::x86_64::interrupts::pit::init() { 17 | drivers::io io; 18 | std::uint8_t entry = irq::create(0,IRQ_TYPE_LEGACY,__pit_int_handler,0,0); 19 | std::uint32_t div = PIT_FREQUENCY / 1000; 20 | io.outb(0x43, 0x36); 21 | io.outb(0x40,div & 0xFF); 22 | io.outb(0x40,(div >> 8) & 0xFF); 23 | 24 | pic::clear(0); 25 | 26 | } 27 | 28 | /* idk why but pit sleep is broken on modern hw, redirect to hpet */ 29 | void arch::x86_64::interrupts::pit::sleep(std::uint32_t ms) { 30 | drivers::hpet::sleep(ms); 31 | } -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/cpu/sse.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | #define DEFAULT_SSE_FLAGS ((1 << 9) | (1 << 10) | (1 << 1)) 7 | #define SSE_XSAVE_SUPPORT (1 << 26) 8 | #define SSE_XSAVE_CR4 (1 << 18) 9 | 10 | #define SSE_CONTROL_DEFAULT ((1 << 0) | (1 << 1)) 11 | 12 | #define SSE_CHECK_AND_SET(bit) \ 13 | if(a & bit) \ 14 | sse_control |= bit; 15 | 16 | typedef struct { 17 | std::uint16_t dumb0; 18 | std::uint32_t dumb1; 19 | std::uint16_t dumb2; 20 | std::uint64_t dumb3; 21 | std::uint64_t dumb4; 22 | std::uint32_t dumb5; 23 | } __attribute__((packed)) fpu_head_t; 24 | 25 | namespace arch { 26 | namespace x86_64 { 27 | namespace cpu { 28 | class sse { 29 | public: 30 | static void init(); 31 | static std::uint64_t size(); 32 | static void save(std::uint8_t* buf); 33 | static void load(std::uint8_t* buf); 34 | }; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /kernel/src/generic/time.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | std::uint64_t time::counter() { 10 | extern std::uint16_t KERNEL_GOOD_TIMER; 11 | switch(KERNEL_GOOD_TIMER) { 12 | case TSC_TIMER: 13 | return drivers::tsc::currentnano(); 14 | case KVM_TIMER: 15 | return drivers::kvmclock::currentnano(); 16 | case HPET_TIMER: 17 | return drivers::hpet::nanocurrent(); 18 | 19 | } 20 | } 21 | 22 | void time::sleep(std::uint64_t us) { 23 | extern std::uint16_t KERNEL_GOOD_TIMER; 24 | switch(KERNEL_GOOD_TIMER) { 25 | case TSC_TIMER: 26 | drivers::tsc::sleep(us); 27 | break; 28 | case KVM_TIMER: 29 | drivers::kvmclock::sleep(us); 30 | break; 31 | case HPET_TIMER: 32 | drivers::hpet::sleep(us); 33 | break; 34 | } 35 | return; 36 | } -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/syscalls/futex.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | syscall_ret_t sys_futex_wait(int* pointer, int excepted) { 8 | 9 | arch::x86_64::process_t* proc = arch::x86_64::cpu::data()->temp.proc; 10 | int copied_pointer_val = 0; 11 | copy_in_userspace(proc,&copied_pointer_val,pointer,sizeof(int)); 12 | //DEBUG(1,"Waiting for futex, pointer: 0x%p excepted: %d, pointer_value %d in proc %d",pointer,excepted,copied_pointer_val,proc->id); 13 | arch::x86_64::scheduling::futexwait(proc,&copied_pointer_val,excepted,pointer); 14 | yield(); 15 | return {0,0,0}; 16 | } 17 | 18 | syscall_ret_t sys_futex_wake(int* pointer) { 19 | arch::x86_64::process_t* proc = arch::x86_64::cpu::data()->temp.proc; 20 | //DEBUG(1,"Wakeup futex with pointer 0x%p in proc %d",pointer,proc->id); 21 | arch::x86_64::scheduling::futexwake(proc,pointer); 22 | return {0,0,0}; 23 | } 24 | -------------------------------------------------------------------------------- /tools/pkg/6/terms/diff/xloadimage.diff: -------------------------------------------------------------------------------- 1 | diff -Naur xloadimage.4.1/Makefile xloadimage-patched/Makefile 2 | --- xloadimage.4.1/Makefile 1993-11-10 01:25:12.000000000 +0300 3 | +++ xloadimage-patched/Makefile 2025-11-12 17:18:16.608965209 +0300 4 | @@ -9,9 +9,11 @@ 5 | include Make.conf 6 | 7 | CFLAGS=$(OPT_FLAGS) $(CC_FLAGS) $(CC_CONFIG_FLAGS) $(X11_INC_DIR) \ 8 | - -DSYSPATHFILE=\"$(SYSPATHFILE)\" 9 | + -DSYSPATHFILE=\"$(SYSPATHFILE)\" -Wno-implicit-int -Wno-implicit-function-declaration -fPIC 10 | LIBS=$(X11_LIB_DIR) $(X11_LIB_NAME) $(SYS_LIBS) -lm 11 | 12 | +CC=x86_64-orange-mlibc-gcc 13 | + 14 | # stuff that should eventually make the configuration file 15 | SYSPATHFILE=/usr/lib/X11/Xloadimage 16 | 17 | @@ -23,7 +25,7 @@ 18 | # the Make.conf file and recursively calls make. 19 | 20 | autoconfig: autoconfig.c 21 | - $(CC) -g -o autoconfig autoconfig.c 22 | + $(CC) -Wno-implicit-int -Wno-implicit-function-declaration -fPIC -g -o autoconfig autoconfig.c 23 | 24 | # manual configuration target 25 | configure:: autoconfig 26 | -------------------------------------------------------------------------------- /kernel/include/drivers/ioapic.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace drivers { 9 | class ioapic { 10 | public: 11 | 12 | static inline void write(std::uint64_t base, std::uint32_t reg,std::uint32_t value) { 13 | std::uint64_t virt = (std::uint64_t)Other::toVirt(base); 14 | *(volatile std::uint32_t*)virt = reg; 15 | *(volatile std::uint32_t*)(virt + 0x10) = value; 16 | } 17 | 18 | static inline std::uint32_t read(std::uint64_t base, std::uint32_t reg) { 19 | std::uint64_t virt = (std::uint64_t)Other::toVirt(base); 20 | *(volatile std::uint32_t*)virt = reg; 21 | return *(volatile std::uint32_t*)(virt + 0x10); 22 | } 23 | 24 | static void init(); 25 | static void set(std::uint8_t vec,std::uint8_t irq,std::uint64_t flags,std::uint64_t lapic); 26 | static void mask(std::uint8_t irq); 27 | static void unmask(std::uint8_t irq); 28 | 29 | }; 30 | }; -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/asm/syscall.asm: -------------------------------------------------------------------------------- 1 | 2 | global syscall_handler 3 | extern syscall_handler_c 4 | syscall_handler: 5 | cli 6 | swapgs 7 | mov qword [gs:0],rsp 8 | mov rsp, qword [gs:8] 9 | push qword (0x18 | 3) 10 | push qword [gs:0] 11 | push qword r11 12 | push qword (0x20 | 3) 13 | push qword rcx 14 | push qword 0 15 | push qword 0 16 | push r15 17 | push r14 18 | push r13 19 | push r12 20 | push r11 21 | push r10 22 | push r9 23 | push r8 24 | push rbp 25 | push rdi 26 | push rsi 27 | push rdx 28 | push rcx 29 | push rbx 30 | push rax 31 | mov rax,cr3 32 | push rax 33 | mov rdi,rsp 34 | call syscall_handler_c 35 | pop rax 36 | pop rax 37 | pop rbx 38 | pop rcx 39 | pop rdx 40 | pop rsi 41 | pop rdi 42 | pop rbp 43 | pop r8 44 | pop r9 45 | pop r10 46 | pop r11 47 | pop r12 48 | pop r13 49 | pop r14 50 | pop r15 51 | cli 52 | mov rsp, qword [gs:0] 53 | swapgs 54 | o64 sysret -------------------------------------------------------------------------------- /tools/pkg/1/liborange/include/io.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef LIBORANGE_IO_H 3 | #define LIBORANGE_IO_H 4 | 5 | static inline void outb(unsigned short port, unsigned char val) { 6 | __asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port)); 7 | } 8 | 9 | static inline void outw(unsigned short port, unsigned short val) { 10 | __asm__ volatile ("outw %0, %1" : : "a"(val), "Nd"(port)); 11 | } 12 | 13 | static inline void outd(unsigned short port, unsigned int val) { 14 | __asm__ volatile ("outl %0, %1" : : "a"(val), "Nd"(port)); 15 | } 16 | 17 | static inline unsigned char inb(unsigned short port) { 18 | unsigned char ret; 19 | __asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port)); 20 | return ret; 21 | } 22 | 23 | static inline unsigned short inw(unsigned short port) { 24 | unsigned short ret; 25 | __asm__ volatile ("inw %1, %0" : "=a"(ret) : "Nd"(port)); 26 | return ret; 27 | } 28 | 29 | static inline unsigned int ind(unsigned short port) { 30 | unsigned int ret; 31 | __asm__ volatile ("inl %1, %0" : "=a"(ret) : "Nd"(port)); 32 | return ret; 33 | } 34 | 35 | #endif -------------------------------------------------------------------------------- /tools/pkg/7/python/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | 6 | mkdir -p pack 7 | 8 | cd pack 9 | 10 | export ac_cv_file__dev_ptmx=yes 11 | export ac_cv_file__dev_ptc=yes 12 | export ac_cv_func_sched_setscheduler=no 13 | export ac_cv_buggy_getaddrinfo=no 14 | 15 | fast_install "$1" https://www.python.org/ftp/python/3.13.9/Python-3.13.9.tar.xz "--build=x86_64 --with-computed-gotos --disable-optimizations --disable-ipv6 --without-system-expat --enable-loadable-sqlite-extensions --without-ensurepip --with-tzpath=/usr/share/zoneinfo --with-build-python=python3 --without-static-libpython" "../../diff/python.diff" 16 | 17 | ln -sfv python3 "$1/usr"/bin/python 18 | ln -sfv python3-config "$1/usr"/bin/python-config 19 | ln -sfv pydoc3 "$1/usr"/bin/pydoc 20 | ln -sfv idle3 "$1/usr"/bin/idle 21 | 22 | mv "$1/usr"/lib/python3.13 "$1/usr"/lib/python3 23 | 24 | ln -sfv python3 "$1/usr"/lib/python3.13 25 | 26 | # rm -r "$1"/usr/lib/python*/{test,ctypes/test,distutils/tests,idlelib/idle_test,lib2to3/tests,sqlite3/test,tkinter/test,unittest/test} # used from arch linux pkgbuild 27 | 28 | cd .. -------------------------------------------------------------------------------- /tools/pkg/8/llvm/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | exit 0 #im not compiling this shit 5 | 6 | rm -rf pack 7 | 8 | mkdir -p pack 9 | 10 | cd pack 11 | 12 | wget https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.5/llvm-project-21.1.5.src.tar.xz 13 | tar -xvf llvm-project-21.1.5.src.tar.xz 14 | cd llvm-project-21.1.5.src 15 | 16 | diff_patch ../../diff/llvm.diff 17 | mkdir build 18 | 19 | cd build 20 | cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-D_GNU_SOURCE=1 -fPIC -O3" -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_CXX_STANDARD=17 -DUNIX=1 -DCMAKE_TOOLCHAIN_FILE=$(realpath ../../../../../toolchain.cmake) -DCMAKE_INSTALL_PREFIX="/usr" -UBUILD_SHARED_LIBS -UENABLE_STATIC -DLLVM_LINK_LLVM_DYLIB=ON -DLLVM_ENABLE_FFI=ON -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-orange-mlibc -DLLVM_HOST_TRIPLE=x86_64-orange-mlibc -Wno-dev 21 | 22 | mkdir temp_sysroot 23 | 24 | cmake --build . -j$(nproc) 25 | DESTDIR="$(realpath temp_sysroot)" cmake --install . 26 | 27 | rm -rf temp_sysroot/bin 28 | rm -rf temp_sysroot/lib/*.a 29 | 30 | cp -r temp_sysroot "$1" 31 | 32 | cd ../.. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 cppLover0 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tools/pkg/0/mlibc/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | mkdir -p pack 6 | mkdir -p cached 7 | 8 | mkdir -p "$1/usr/include" 9 | mkdir -p "$1/usr/bin" 10 | mkdir -p "$1/usr/lib" 11 | mkdir -p "$1/lib" 12 | mkdir -p "$1/bin" 13 | 14 | if [ ! -d "./linux-headers" ]; then 15 | mkdir -p temp 16 | mkdir -p linux-headers 17 | git clone https://github.com/torvalds/linux.git --depth=1 18 | cd linux 19 | make headers_install ARCH=x86_64 INSTALL_HDR_PATH="$(realpath ../temp)" 20 | cd .. 21 | cp -rf temp/include/* linux-headers 22 | rm -rf temp 23 | rm -rf linux 24 | fi 25 | 26 | echo Copying linux-headers... 27 | mkdir -p "$1/usr/include" 28 | cp -rf linux-headers/* "$1/usr/include" 29 | 30 | cd pack 31 | 32 | export CFLAGS="-std=gnu11" 33 | 34 | # mlibc doesn't need to be cached 35 | git clone https://github.com/cpplover0/orange-mlibc --depth=1 36 | cd orange-mlibc 37 | 38 | sh build_to_cross.sh "$(realpath $1/..)" 39 | 40 | T=$(realpath .) 41 | 42 | cd $1/usr/lib 43 | ln -sf ld.so ld64.so.1 44 | cp -rf $HOME/opt/cross/orange/x86_64-orange-mlibc/lib/libs*.so* . 45 | 46 | cd "$T" 47 | 48 | cd .. 49 | -------------------------------------------------------------------------------- /tools/pkg/9/mesa/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | 6 | mkdir -p pack 7 | 8 | cd pack 9 | 10 | fast_install "$1" https://www.x.org/archive/individual/lib/libXext-1.3.4.tar.gz 11 | 12 | wget https://gitlab.freedesktop.org/mesa/mesa/-/archive/mesa-25.2.7/mesa-mesa-25.2.7.tar.gz 13 | tar -xvf mesa-mesa-25.2.7.tar.gz 14 | cd mesa-mesa-25.2.7 15 | 16 | diff_patch ../../diff/mesa.diff 17 | 18 | mkdir build 19 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dglx=xlib -Dplatforms=x11 -Dgallium-drivers=softpipe -Dllvm=false -Dvulkan-drivers= -Dvideo-codecs=all_free build 20 | cd build 21 | 22 | meson compile -j$(nproc) 23 | DESTDIR="$1" meson install --no-rebuild 24 | 25 | cp -rf "../../../glx.pc" "$1/usr/lib/pkgconfig" 26 | 27 | cd ../.. 28 | 29 | wget https://archive.mesa3d.org/glu/glu-9.0.3.tar.xz 30 | tar -xvf glu-9.0.3.tar.xz 31 | cd glu-9.0.3 32 | 33 | mkdir build 34 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dgl_provider=gl build 35 | 36 | cd build 37 | 38 | meson compile -j$(nproc) 39 | DESTDIR="$1" meson install --no-rebuild 40 | 41 | cd ../.. 42 | 43 | 44 | cd .. -------------------------------------------------------------------------------- /kernel/src/drivers/tsc.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | using namespace drivers; 15 | 16 | std::uint64_t freq; 17 | 18 | void tsc::init() { 19 | std::uint64_t start = __rdtsc(); 20 | time::sleep(100); 21 | std::uint64_t end = __rdtsc(); 22 | std::uint64_t d = end - start; 23 | arch::x86_64::cpu::data()->tsc.freq = (d * 1000000ULL) / (100 * 1000ULL); 24 | } 25 | 26 | 27 | void tsc::sleep(std::uint64_t us) { 28 | 29 | if(arch::x86_64::cpu::data()->tsc.freq == 0) { 30 | drivers::hpet::sleep(us); 31 | return; 32 | } 33 | 34 | std::uint64_t current = currentnano(); 35 | std::uint64_t end = us * 1000; 36 | while((currentnano() - current) < end); 37 | __nop(); 38 | } 39 | 40 | std::uint64_t tsc::currentnano() { 41 | return (__rdtsc() * 1000000ULL) / arch::x86_64::cpu::data()->tsc.freq; 42 | } 43 | 44 | std::uint64_t tsc::currentus() { 45 | return currentnano() / 1000; 46 | } -------------------------------------------------------------------------------- /tools/pkg/10/gtk_final/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | 6 | mkdir -p pack 7 | 8 | cd pack 9 | 10 | wget https://github.com/anholt/libepoxy/archive/refs/tags/1.5.10.tar.gz 11 | tar -xvf 1.5.10.tar.gz 12 | cd libepoxy-1.5.10 13 | 14 | mkdir build 15 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Degl=no -Dtests=false build 16 | 17 | cd build 18 | 19 | meson compile -j$(nproc) 20 | DESTDIR="$1" meson install --no-rebuild 21 | 22 | cd ../.. 23 | 24 | 25 | wget https://codeload.github.com/GNOME/gtk/tar.gz/refs/tags/3.24.51 26 | mv 3.24.51 gtk-3.24.51.tar.gz 27 | 28 | tar -xvf gtk-3.24.51.tar.gz 29 | 30 | cd gtk-3.24.51 31 | 32 | autotools_recursive_regen 33 | mkdir -p build 34 | 35 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dprint_backends=file -Dintrospection=false -Dx11_backend=true -Dbroadway_backend=true -Dwayland_backend=false -Dcolord=no build 36 | 37 | cd build 38 | meson compile -j$(nproc) 39 | 40 | sudo chmod -R 777 "$1/usr/share/locale" 41 | 42 | DESTDIR="$1" meson install --no-rebuild 43 | 44 | glib-compile-schemas "$1/usr"/share/glib-2.0/schemas 45 | 46 | cd ../../.. -------------------------------------------------------------------------------- /tools/pkg/11/other-stuff/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | mkdir -p "$1/usr/share/gtk-3.0/" 5 | mkdir -p "$1/etc/gtk-3.0" 6 | cp -rf settings.ini "$1/usr/share/gtk-3.0/settings.ini" 7 | cp -rf settings.ini "$1/etc/gtk-3.0/settings.ini" 8 | 9 | rm -rf pack 10 | mkdir -p pack 11 | 12 | cd pack 13 | 14 | fast_install "$1" https://www.x.org/releases/individual/xcb/xcb-util-renderutil-0.3.10.tar.gz 15 | fast_install "$1" https://www.x.org/releases/individual/xcb/xcb-util-cursor-0.1.6.tar.gz 16 | fast_install "$1" https://www.x.org/releases/individual/xcb/xcb-util-keysyms-0.4.1.tar.gz 17 | fast_install "$1" https://www.x.org/releases/individual/xcb/xcb-util-wm-0.4.2.tar.gz 18 | 19 | 20 | 21 | fast_install "$1" https://www.x.org/releases/individual/app/xrandr-1.5.2.tar.gz 22 | fast_install "$1" https://www.x.org/releases/individual/app/xdpyinfo-1.3.4.tar.gz 23 | 24 | wget https://github.com/dejavu-fonts/dejavu-fonts/releases/download/version_2_37/dejavu-fonts-ttf-2.37.tar.bz2 25 | tar -xvf dejavu-fonts-ttf-2.37.tar.bz2 26 | 27 | cd dejavu-fonts-ttf-2.37 28 | mkdir -p "$1/usr/share/fonts/truetype/dejavu" 29 | cp -rf ttf/* "$1/usr/share/fonts/truetype/dejavu" 30 | 31 | cd .. -------------------------------------------------------------------------------- /kernel/include/generic/locks/spinlock.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | extern "C" void yield0(); 11 | 12 | namespace locks { 13 | class spinlock { 14 | private: 15 | volatile std::atomic_flag flag = ATOMIC_FLAG_INIT; 16 | char is_cli = 0; 17 | public: 18 | spinlock() { 19 | 20 | } 21 | 22 | void lock() { 23 | while(flag.test_and_set(std::memory_order_acquire)) { 24 | asm volatile("nop"); 25 | 26 | } 27 | } 28 | 29 | void enable_scheduling_optimization() { 30 | is_cli = 1; 31 | } 32 | 33 | std::uint8_t test_and_set() { 34 | return flag.test_and_set(std::memory_order_acquire); 35 | } 36 | 37 | void nowaitlock() { 38 | flag.test_and_set(std::memory_order_acquire); 39 | } 40 | 41 | void unlock() { 42 | flag.clear(std::memory_order_release); 43 | } 44 | 45 | std::uint8_t test() { 46 | return flag.test(); 47 | } 48 | 49 | }; 50 | }; -------------------------------------------------------------------------------- /tools/pkg/5/xorg-modules/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | mkdir -p pack 6 | 7 | cd pack 8 | 9 | ca="$(pwd)" 10 | 11 | cd "$1/usr/lib" 12 | 13 | for file in xorg/modules/*.so; do ln -s "$file" .; done 14 | 15 | cd "$ca" 16 | 17 | fast_install "$1" https://www.x.org/archive//individual/font/font-util-1.4.1.tar.xz 18 | 19 | fast_install "$1" https://www.x.org/pub/individual/font/font-alias-1.0.5.tar.xz 20 | 21 | wget https://ftp.debian.org/debian/pool/main/x/xfonts-base/xfonts-base_1.0.5_all.deb 22 | ar -x xfonts-base_1.0.5_all.deb 23 | 24 | tar -xvf data.tar.xz 25 | cp -rf usr/* "$1/usr" 26 | cp -rf etc/* "$1/etc" 27 | 28 | CFLAGS="-fPIC" SYSROOT="$1/" fast_install "$1" https://www.x.org/releases/individual/driver/xf86-video-fbdev-0.5.1.tar.gz "--disable-pciaccess --disable-static --enable-shared" "../../diff/xfbdev.diff" 29 | CFLAGS="-fPIC" SYSROOT="$1/" fast_install "$1" https://www.x.org/releases/individual/driver/xf86-input-keyboard-2.1.0.tar.gz "--disable-static --enable-shared" "../../diff/xkeyboard.diff" 30 | CFLAGS="-fPIC" SYSROOT="$1/" fast_install "$1" https://xorg.freedesktop.org/archive/individual/driver/xf86-input-mouse-1.9.5.tar.gz "--enable-shared" "../../diff/xmouse.diff" -------------------------------------------------------------------------------- /kernel/include/etc/etc.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #define ALIGNUP(VALUE,c) ((VALUE + c - 1) & ~(c - 1)) 8 | #define ALIGNDOWN(VALUE,c) ((VALUE / c) * c) 9 | 10 | static inline uint64_t get_rflags() { 11 | uint64_t rflags; 12 | 13 | __asm__ volatile ( 14 | "pushfq\n\t" 15 | "popq %0" 16 | : "=r"(rflags) 17 | : 18 | : "memory" 19 | ); 20 | return rflags; 21 | } 22 | 23 | static inline int is_sti() { 24 | std::uint64_t eflags = get_rflags(); 25 | return (eflags & (1 << 9)) != 0; 26 | } 27 | 28 | class Other { 29 | public: 30 | static void ConstructorsInit(); 31 | 32 | static inline std::uint64_t toPhys(void* addr) { 33 | uint64_t hhdm = BootloaderInfo::AccessHHDM(); 34 | return (uint64_t)addr - hhdm; 35 | } 36 | 37 | static inline void* toVirt(uint64_t phys) { 38 | uint64_t hhdm = BootloaderInfo::AccessHHDM(); 39 | return (void*)(phys + hhdm); 40 | } 41 | 42 | static inline std::uint64_t toPhys(std::uint64_t addr) { 43 | uint64_t hhdm = BootloaderInfo::AccessHHDM(); 44 | return (uint64_t)addr - hhdm; 45 | } 46 | 47 | }; -------------------------------------------------------------------------------- /tools/pkg/3/coreutils/diff/coreutils.diff: -------------------------------------------------------------------------------- 1 | diff -Naur coreutils/build-aux/config.sub coreutils-patched/build-aux/config.sub 2 | --- coreutils/build-aux/config.sub 2024-08-11 16:58:11.000000000 +0300 3 | +++ coreutils-patched/build-aux/config.sub 2025-05-25 12:55:11.367837322 +0300 4 | @@ -2012,6 +2012,7 @@ 5 | | glidix* \ 6 | | gnu* \ 7 | | go32* \ 8 | + | orange* \ 9 | | haiku* \ 10 | | hcos* \ 11 | | hiux* \ 12 | diff -Naur coreutils/gnulib-tests/getlocalename_l-unsafe.c coreutils-patched/gnulib-tests/getlocalename_l-unsafe.c 13 | --- coreutils/gnulib-tests/getlocalename_l-unsafe.c 2025-04-06 01:23:58.000000000 +0300 14 | +++ coreutils-patched/gnulib-tests/getlocalename_l-unsafe.c 2025-05-25 16:46:35.306435434 +0300 15 | @@ -469,6 +469,8 @@ 16 | struct gl_locale_category_t *plc = 17 | &locale->category[gl_log2_lcmask_to_index (gl_log2_lc_mask (category))]; 18 | return (struct string_with_storage) { plc->name, STORAGE_OBJECT }; 19 | +#elif defined __orange__ 20 | + return (struct string_with_storage) { "C", STORAGE_INDEFINITE }; 21 | #elif __GLIBC__ >= 2 && !defined __UCLIBC__ 22 | /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in 23 | glibc < 2.12. -------------------------------------------------------------------------------- /tools/pkg/3/poll_test/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | int main() { 10 | struct pollfd fds[1]; 11 | fds[0].fd = 0; 12 | fds[0].events = POLLIN; 13 | 14 | struct termios newt; 15 | tcgetattr(STDIN_FILENO, &newt); 16 | newt.c_lflag &= ~(ICANON | ECHO); 17 | tcsetattr(STDIN_FILENO, TCSANOW, &newt); 18 | 19 | printf("Waiting for input (5 second timeout)...\n"); 20 | int ret = poll(fds, 1, 5000); 21 | 22 | if (ret == -1) { 23 | perror("poll"); 24 | return 1; 25 | } else if (ret == 0) { 26 | printf("Timeout !\n"); 27 | } else { 28 | if (fds[0].revents & POLLIN) { 29 | printf("Input ! waiting for string\n"); 30 | char buf[100]; 31 | read(STDIN_FILENO,buf,100); 32 | memset(buf,0,100); 33 | newt.c_lflag |= ICANON | ECHO; 34 | tcsetattr(STDIN_FILENO, TCSANOW, &newt); 35 | read(STDIN_FILENO,buf,100); 36 | printf("You enter: %s", buf); 37 | } 38 | } 39 | 40 | newt.c_lflag |= ICANON | ECHO; 41 | tcsetattr(STDIN_FILENO, TCSANOW, &newt); 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/cpu/data.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | typedef struct { 13 | std::uint64_t user_stack; 14 | std::uint64_t kernel_stack; 15 | std::uint64_t timer_ist_stack; 16 | int last_sys; 17 | std::uint64_t lapic_block; 18 | struct { 19 | std::uint16_t cpu_id; 20 | } smp; 21 | struct { 22 | std::uint64_t freq; 23 | } tsc; 24 | struct { 25 | int_frame_t temp_ctx; 26 | arch::x86_64::process_t* proc; 27 | arch::x86_64::process_queue_run_list_t* next; 28 | } temp; 29 | } cpudata_t; 30 | 31 | namespace arch { 32 | namespace x86_64 { 33 | namespace cpu { 34 | inline static cpudata_t* data() { 35 | std::uint64_t cpudata = __rdmsr(0xC0000101); 36 | if(!cpudata) { 37 | cpudata = (std::uint64_t)new cpudata_t; 38 | memset((void*)cpudata,0,sizeof(cpudata_t)); 39 | __wrmsr(0xC0000101,cpudata); 40 | } 41 | return (cpudata_t*)cpudata; 42 | } 43 | }; 44 | }; 45 | }; -------------------------------------------------------------------------------- /tools/pkg/2/ncurses/diff/ncurses.diff: -------------------------------------------------------------------------------- 1 | diff -Naur ncurses-6.5/config.sub ncurses-patched/config.sub 2 | --- ncurses-6.5/config.sub 2023-12-27 17:41:27.000000000 +0300 3 | +++ ncurses-patched/config.sub 2025-06-02 08:30:55.408408771 +0300 4 | @@ -1764,7 +1764,7 @@ 5 | | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ 6 | | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ 7 | | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ 8 | - | skyos* | haiku* | rdos* | toppers* | drops* | es* \ 9 | + | skyos* | orange* | haiku* | rdos* | toppers* | drops* | es* \ 10 | | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ 11 | | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ 12 | | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ 13 | diff -Naur ncurses-6.5/configure ncurses-patched/configure 14 | --- ncurses-6.5/configure 2024-04-10 11:09:48.000000000 +0300 15 | +++ ncurses-patched/configure 2025-06-02 09:00:16.635459472 +0300 16 | @@ -6925,6 +6925,10 @@ 17 | LINK_PROGS="$SHELL ${rel_builddir}/mk_prog.sh" 18 | LINK_TESTS="$SHELL ${rel_builddir}/mk_prog.sh" 19 | ;; 20 | + (orange*) 21 | + CC_SHARED_OPTS='-fPIC' 22 | + MK_SHARED_LIB='${CC} -shared -o $@' 23 | + ;; 24 | (mingw*) 25 | cf_cv_shlib_version=mingw 26 | cf_cv_shlib_version_infix=mingw -------------------------------------------------------------------------------- /tools/initbase/etc/gaster: -------------------------------------------------------------------------------- 1 | @@@@@@@ 2 | @@@ @ 3 | @ @ @ 4 | @ @ @ 5 | @ @@ @@@@@ @@ 6 | @@ @@ @@ @@@@@@ @@ 7 | @@ @ @@@ @@@@@@ @@ 8 | @@ @ @@@@@ @@@@@@ @@ 9 | @@ @@@@@ @@ @@ 10 | @@ @@ @@ @@ 11 | @ @ @@@ @@ 12 | @ @@ @@@ @ 13 | @ @@@@@@ @ 14 | @@ @@@@@ @ 15 | @@@@@ @@@@ 16 | @@@@@@@@@@@@@@@@ 17 | @@@@@@@@ @@@@@ 18 | @@@@@@@@ @@@@@@@ 19 | @@@@@@@@ @@@@@@@ 20 | @@@@@@@@@ @@@@@@@@ 21 | @@@@@@@@@@ @@@@@@@@ 22 | @@@@@@@@@@ @@@@@@@@ 23 | @@@@ @@@@@ @@@@@@@@@ 24 | @% @@@@@@@@@ @@@ 25 | @% @@@@@@@ @ @@ 26 | @@@ @@@@@@@@ @@ 27 | @@@@@@@@@@@@@@@@@ @@@ 28 | @@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@@@@@@@@@@@ 32 | @@@@@@@@@@@@@@@@@ 33 | 34 | -------------------------------------------------------------------------------- /kernel/include/drivers/serial.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #pragma once 8 | 9 | 10 | #define DEFAULT_SERIAL_PORT 0x3F8 11 | 12 | typedef struct { 13 | std::uint16_t port; 14 | std::uint8_t is_init; 15 | } serial_mapping_t; 16 | 17 | namespace drivers { 18 | class serial { 19 | private: 20 | std::uint16_t target_port; 21 | std::uint8_t is_possible; 22 | public: 23 | 24 | static void init(uint16_t port); 25 | static std::uint8_t is_init(uint16_t port); 26 | 27 | serial(uint16_t port) { 28 | target_port = port; 29 | if(!is_init(port)) 30 | init(port); 31 | } 32 | 33 | void send(std::uint8_t data) { 34 | drivers::io io; 35 | while((io.inb(target_port + 5) & 0x20) == 0); 36 | io.outb(target_port,data); 37 | } 38 | 39 | void write(std::uint8_t* data,std::size_t len) { 40 | //return; 41 | for(std::size_t i = 0; i < len; i++) { 42 | send(data[i]); 43 | } 44 | } 45 | 46 | std::uint8_t fetch() { 47 | drivers::io io; 48 | while((io.inb(target_port + 5) & 1) == 0); 49 | return io.inb(target_port); 50 | } 51 | 52 | }; 53 | }; -------------------------------------------------------------------------------- /kernel/src/lib/Flanterm/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2022-2025 mintsuki and contributors. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /tar-initrd.sh: -------------------------------------------------------------------------------- 1 | 2 | sudo rm -rf initrd 3 | 4 | export LIBTOOL="$HOME/opt/cross/orange/bin/libtool" 5 | export LIBTOOLIZE="$HOME/opt/cross/orange/bin/libtoolize" 6 | export PATH="$HOME/opt/cross/orange/bin:$PATH" 7 | 8 | sysroot_path="$(realpath initrd)" 9 | 10 | export CFLAGS="-fPIC -Wno-error -O2" 11 | export PKG_CONFIG_SYSROOT_DIR="$sysroot_path" 12 | export PKG_CONFIG_PATH="$sysroot_path/usr/lib/pkgconfig:$sysroot_path/usr/share/pkgconfig:$sysroot_path/usr/local/lib/pkgconfig:$sysroot_path/usr/local/share/pkgconfig:$HOME/opt/cross/orange/lib/pkgconfig:$HOME/opt/cross/orange/share/pkgconfig" 13 | if [ ! "$(which x86_64-orange-mlibc-gcc)" ]; then 14 | echo "It looks like you don't have the cross-compiler installed, or it isn't in your PATH." 15 | echo "If you built your cross-compiler, add it to your PATH with:" 16 | echo 'export PATH="$HOME/opt/cross/orange/bin:$PATH"' 17 | echo 'Alternatively, you can build the cross-compiler with: sh build-cross.sh' 18 | echo 'Also you should have host gcc with version < 14 (i am using 13.3.0)' 19 | exit 1 20 | fi 21 | 22 | 23 | bash tools/pkg/build-pkg.sh "$(realpath initrd)" 24 | 25 | cd initrd 26 | 27 | rm -rf lib lib64 bin 28 | 29 | ln -sf usr/lib lib 30 | ln -sf usr/lib lib64 31 | ln -sf usr/bin bin 32 | 33 | cd ../ 34 | 35 | cp -rf tools/initbase/* initrd 36 | 37 | mkdir -p tools/base/boot 38 | tar -cf tools/base/boot/initrd.tar -C initrd . 39 | -------------------------------------------------------------------------------- /tools/pkg/1/pkg-config/pkg.sh: -------------------------------------------------------------------------------- 1 | # https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz 2 | 3 | 4 | . ../../pkg-lib.sh 5 | 6 | mkdir -p cached 7 | 8 | rm -rf pack 9 | 10 | mkdir -p pack 11 | 12 | cd pack 13 | 14 | wget https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz 15 | tar -xvf pkg-config-0.29.2.tar.gz 16 | cd pkg-config-0.29.2 17 | 18 | diff_patch ../../diff/pkg-config.diff 19 | ./configure --prefix="$HOME/opt/cross/orange" --with-internal-glib --target=x86_64-orange 20 | make -j$(nproc) 21 | make install 22 | 23 | mkdir -p "$HOME/opt/cross/orange"/share/pkgconfig/personality.d 24 | 25 | cat > "$HOME/opt/cross/orange"/share/pkgconfig/personality.d/x86_64-orange.personality << EOF 26 | Triplet: x86_64-orange 27 | SysrootDir: $1 28 | DefaultSearchPaths: $1/usr/lib/pkgconfig:$1/usr/share/pkgconfig 29 | SystemIncludePaths: $1/usr/include 30 | SystemLibraryPaths: $1/usr/lib 31 | EOF 32 | 33 | c="$(pwd)" 34 | 35 | cd "$HOME/opt/cross/orange/bin" 36 | 37 | ln -sf pkg-config x86_64-orange-mlibc-pkg-config 38 | 39 | cd "$c" 40 | 41 | # wget https://ftpmirror.gnu.org/gnu/libtool/libtool-2.5.4.tar.gz 42 | # tar -xvf libtool-2.5.4.tar.gz 43 | # cd libtool-2.5.4 44 | 45 | # diff_patch ../../diff/libtool.diff 46 | # ./configure --prefix="$HOME/opt/cross/orange" --with-gnu-ld --enable-shared --disable-static 47 | # make -j$(nproc) 48 | # make install 49 | 50 | # cd .. 51 | 52 | cd .. 53 | -------------------------------------------------------------------------------- /kernel/src/lib/Flanterm/README.md: -------------------------------------------------------------------------------- 1 | # Flanterm 2 | 3 | Flanterm is a fast and reasonably complete terminal emulator with support for 4 | multiple output backends. Included is a fast framebuffer backend. 5 | 6 | ### Quick usage 7 | 8 | To quickly set up and use a framebuffer Flanterm instance, it is possible to 9 | use the `flanterm_fb_init()` function as such: 10 | ```c 11 | #include 12 | #include 13 | 14 | struct flanterm_context *ft_ctx = flanterm_fb_init( 15 | NULL, 16 | NULL, 17 | framebuffer_ptr, width, height, pitch, 18 | red_mask_size, red_mask_shift, 19 | green_mask_size, green_mask_shift, 20 | blue_mask_size, blue_mask_shift, 21 | NULL, 22 | NULL, NULL, 23 | NULL, NULL, 24 | NULL, NULL, 25 | NULL, 0, 0, 1, 26 | 0, 0, 27 | 0 28 | ); 29 | ``` 30 | Where `framebuffer_ptr, width, height, pitch` and `{red,green,blue}_mask_{size,shift}` 31 | represent the corresponding info about the framebuffer to use for this given instance. 32 | 33 | The meaning of the other arguments can be found in `flanterm_backends/fb.h`. 34 | 35 | To then print to the terminal instance, simply use the `flanterm_write()` 36 | function on the given instance. For example: 37 | ```c 38 | #include 39 | 40 | const char msg[] = "Hello world\n"; 41 | 42 | flanterm_write(ft_ctx, msg, sizeof(msg)); 43 | ``` 44 | -------------------------------------------------------------------------------- /kernel/src/drivers/serial.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | serial_mapping_t __serial_map[32]; 11 | int __serial_map_ptr = 0; 12 | 13 | void drivers::serial::init(uint16_t port) { 14 | 15 | if(__serial_map_ptr == 0) 16 | memset(__serial_map,0,sizeof(serial_mapping_t)); 17 | 18 | drivers::io io; 19 | io.outb(DEFAULT_SERIAL_PORT + 1, 0x00); 20 | io.outb(DEFAULT_SERIAL_PORT + 3, 0x80); 21 | io.outb(DEFAULT_SERIAL_PORT + 0, 0x03); 22 | io.outb(DEFAULT_SERIAL_PORT + 1, 0x00); 23 | io.outb(DEFAULT_SERIAL_PORT + 3, 0x03); 24 | io.outb(DEFAULT_SERIAL_PORT + 2, 0xC7); 25 | io.outb(DEFAULT_SERIAL_PORT + 4, 0x0B); 26 | io.outb(DEFAULT_SERIAL_PORT + 4, 0x1E); 27 | io.outb(DEFAULT_SERIAL_PORT + 0, 0xAE); 28 | 29 | if(io.inb(DEFAULT_SERIAL_PORT + 0) != 0xAE) { 30 | __serial_map[__serial_map_ptr].port = port; 31 | __serial_map[__serial_map_ptr++].is_init = 0; 32 | } 33 | 34 | io.outb(DEFAULT_SERIAL_PORT + 4, 0x0F); 35 | __serial_map[__serial_map_ptr].port = port; 36 | __serial_map[__serial_map_ptr++].is_init = 1; 37 | } 38 | 39 | std::uint8_t drivers::serial::is_init(uint16_t port) { 40 | 41 | for(int i = 0;i < __serial_map_ptr;i++) { 42 | if(__serial_map[i].port == port && __serial_map[i].is_init == 1) 43 | return 1; 44 | } 45 | return 0; 46 | } -------------------------------------------------------------------------------- /tools/pkg/4/xorg-server/diff/openssl.diff: -------------------------------------------------------------------------------- 1 | diff --git openssl-clean/Configurations/10-main.conf openssl-workdir/Configurations/10-main.conf 2 | index 2a047ca..357fd04 100644 3 | --- openssl-clean/Configurations/10-main.conf 4 | +++ openssl-workdir/Configurations/10-main.conf 5 | @@ -192,6 +192,35 @@ my %targets = ( 6 | thread_scheme => "(unknown)", 7 | }, 8 | 9 | +#### Oranges config 10 | + "orange-generic64" => { 11 | + inherit_from => [ "BASE_unix" ], 12 | + CFLAGS => picker(default => "-Wall", 13 | + debug => "-O0 -g", 14 | + release => "-O3"), 15 | + CXXFLAGS => picker(default => "-Wall", 16 | + debug => "-O0 -g", 17 | + release => "-O3"), 18 | + cxxflags => add("-std=c++11"), 19 | + lib_cppflags => combine("-DOPENSSL_USE_NODELETE", "-DL_ENDIAN"), 20 | + bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR", 21 | + thread_scheme => "pthreads", 22 | + dso_scheme => "dlfcn", 23 | + shared_target => "linux-shared", 24 | + shared_cflag => "-fPIC", 25 | + shared_ldflag => sub { $disabled{pinshared} ? () : "-Wl,-znodelete" }, 26 | + shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)", 27 | + }, 28 | + 29 | + "x86_64-orange-mlibc" => { 30 | + inherit_from => [ "orange-generic64", asm("x86_64_asm") ], 31 | + perlasm_scheme => "elf", 32 | + 33 | + CC => "x86_64-orange-mlibc-gcc", 34 | + CXX => "x86_64-orange-mlibcss-g++", 35 | + 36 | + }, 37 | + 38 | #### VOS Configurations 39 | "vos-gcc" => { 40 | inherit_from => [ "BASE_unix" ], -------------------------------------------------------------------------------- /kernel/include/etc/assembly.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | inline std::uint64_t __rdmsr(std::uint32_t msr) { 7 | std::uint32_t lo, hi; 8 | __asm__ volatile ("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr)); 9 | return ((std::uint64_t)hi << 32) | lo; 10 | } 11 | 12 | inline void __wrmsr(std::uint32_t msr, std::uint64_t value) { 13 | std::uint32_t lo = (uint32_t)(value & 0xFFFFFFFF); 14 | std::uint32_t hi = (uint32_t)(value >> 32); 15 | __asm__ volatile ("wrmsr" : : "c"(msr), "a"(lo), "d"(hi)); 16 | } 17 | 18 | inline void __nop() { 19 | __asm__ volatile ("nop"); 20 | } 21 | 22 | inline void __cli() { 23 | __asm__ volatile ("cli"); 24 | } 25 | 26 | inline void __sti() { 27 | __asm__ volatile ("sti"); 28 | } 29 | 30 | inline void __hlt() { 31 | __asm__ volatile ("hlt"); 32 | } 33 | 34 | inline void __invlpg(unsigned long long virt) { 35 | __asm__ volatile ("invlpg (%0)" : : "r" (virt) : "memory"); 36 | } 37 | 38 | inline void __cpuid(int code, int code2, std::uint32_t *a, std::uint32_t *b, std::uint32_t *c , std::uint32_t *d) { 39 | __asm__ volatile("cpuid":"=a"(*a),"=b"(*b),"=c"(*c),"=d"(*d):"a"(code),"c"(code2)); 40 | } 41 | 42 | inline int __cpuid_string(int code, std::uint32_t where[4]) { 43 | __asm__ volatile("cpuid":"=a"(*where),"=b"(*(where+1)),"=c"(*(where+2)),"=d"(*(where+3)):"a"(code)); 44 | return (int)where[0]; 45 | } 46 | 47 | inline std::uint64_t __rdtsc() { 48 | unsigned int hi, lo; 49 | __asm__ volatile ("rdtsc" : "=a"(lo), "=d"(hi)); 50 | return ((uint64_t)hi << 32) | lo; 51 | } -------------------------------------------------------------------------------- /tools/pkg/build-pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | echo "Building orange's packages" 3 | 4 | export PATH="$HOME/opt/cross/orange/bin:$PATH" 5 | 6 | if [ ! "$(which x86_64-orange-mlibc-gcc)" ]; then 7 | echo "It looks like you don't have the cross-compiler installed, or it isn't in your PATH." 8 | echo "If you built your cross-compiler, add it to your PATH with:" 9 | echo 'export PATH="$HOME/opt/cross/orange/bin:$PATH"' 10 | echo 'Alternatively, you can build the cross-compiler with: sh build-cross.sh' 11 | echo 'Also you should have host gcc with version < 14 (i am using 13.3.0)' 12 | exit 1 13 | fi 14 | 15 | max_depth=0 16 | while IFS= read -r -d '' dir; do 17 | dir="${dir#./}" 18 | if [[ -z "$dir" ]]; then 19 | depth=0 20 | else 21 | depth=$(( $(grep -o "/" <<< "$dir" | wc -l) + 1 )) 22 | fi 23 | (( depth > max_depth )) && max_depth=$depth 24 | done < <(find . -type d -print0) 25 | 26 | if [[ $max_depth -lt 0 ]]; then 27 | max_depth=0 28 | fi 29 | 30 | for (( level=0; level<=max_depth; level++ )); do 31 | mapfile -d '' dirs < <(find . -mindepth $level -maxdepth $level -type d -print0 | sort -z) 32 | for dir in "${dirs[@]}"; do 33 | display_dir="${dir#./}" 34 | if [[ -f "$dir/pkg.sh" ]]; then 35 | if [[ -f "$dir/info.txt" ]]; then 36 | info=$(<"$dir/info.txt") 37 | else 38 | info="(no info.txt)" 39 | fi 40 | echo "Building $info in directory: $display_dir" 41 | (cd "$dir" && bash pkg.sh "$1") 42 | fi 43 | done 44 | done 45 | -------------------------------------------------------------------------------- /tools/pkg/5/twm/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | mkdir -p pack 6 | 7 | cd pack 8 | 9 | fast_install "$1" https://www.x.org/releases/individual/lib/libXext-1.3.4.tar.gz 10 | fast_install "$1" https://www.x.org/releases/individual/lib/libICE-1.1.0.tar.gz 11 | fast_install "$1" https://www.x.org/releases/individual/lib/libSM-1.2.4.tar.gz 12 | fast_install "$1" https://www.x.org/releases/individual/lib/libXt-1.2.1.tar.gz "--enable-shared" "../../diff/libxt.diff" 13 | fast_install "$1" https://www.x.org/releases/individual/lib/libXmu-1.1.3.tar.gz 14 | 15 | fast_install "$1" https://www.x.org/archive//individual/app/twm-1.0.11.tar.gz 16 | 17 | fast_install "$1" https://www.x.org/releases/individual/lib/libXpm-3.5.14.tar.gz 18 | fast_install "$1" https://www.x.org/releases/individual/lib/libXaw-1.0.14.tar.gz 19 | 20 | fast_install "$1" https://github.com/libexpat/libexpat/releases/download/R_2_4_9/expat-2.4.9.tar.xz 21 | fast_install "$1" https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.13.94.tar.gz "--enable-shared" "../../diff/fontconfig.diff" 22 | 23 | fast_install "$1" https://www.x.org/releases/individual/lib/libXrender-0.9.11.tar.gz 24 | fast_install "$1" https://www.x.org/releases/individual/lib/libXft-2.3.4.tar.gz 25 | 26 | fast_install "$1" https://www.x.org/releases/individual/lib/libXi-1.8.1.tar.gz 27 | 28 | fast_install "$1" https://www.x.org/pub/individual/app/xclock-1.1.1.tar.xz 29 | fast_install "$1" https://www.x.org/releases/individual/app/xeyes-1.2.0.tar.gz 30 | 31 | fast_install "$1" https://www.x.org/releases/individual/app/xinit-1.4.1.tar.gz -------------------------------------------------------------------------------- /kernel/src/drivers/kvmtimer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | struct pvclock_vcpu_time_info* kvmclock_info; 14 | 15 | extern std::uint16_t KERNEL_GOOD_TIMER; 16 | 17 | void drivers::kvmclock::init() { 18 | 19 | std::uint32_t a,b,c,d; 20 | 21 | __cpuid(0x40000000,0,&a,&b,&c,&d); 22 | if(b != 0x4b4d564b || d != 0x4d || c != 0x564b4d56) 23 | return; 24 | 25 | __cpuid(0x40000001,0,&a,&b,&c,&d); 26 | if(!(a & (1 << 3))) 27 | return; 28 | 29 | KERNEL_GOOD_TIMER = KVM_TIMER; 30 | 31 | kvmclock_info = (struct pvclock_vcpu_time_info*)memory::pmm::_virtual::alloc(4096); 32 | 33 | __wrmsr(0x4b564d01,(std::uint64_t)Other::toPhys(kvmclock_info) | 1); 34 | Log::Display(LEVEL_MESSAGE_OK,"KVMClock initializied\n"); 35 | 36 | } 37 | 38 | void drivers::kvmclock::sleep(std::uint64_t us) { 39 | std::uint64_t start = currentnano(); 40 | std::uint64_t conv = us * 1000; 41 | while((currentnano() - start) < conv) 42 | asm volatile("nop"); 43 | } 44 | 45 | std::uint64_t drivers::kvmclock::currentnano() { 46 | std::uint64_t time0 = __rdtsc() - kvmclock_info->tsc_timestamp; 47 | if(kvmclock_info->tsc_shift >= 0) 48 | time0 <<= kvmclock_info->tsc_shift; 49 | else 50 | time0 >>= -kvmclock_info->tsc_shift; 51 | time0 = (time0 * kvmclock_info->tsc_to_system_mul) >> 32; 52 | time0 = time0 + kvmclock_info->system_time; 53 | return time0; 54 | } -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/interrupts/idt.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | typedef struct { 7 | std::uint16_t low; 8 | std::uint16_t cs; 9 | std::uint8_t ist; 10 | std::uint8_t attr; 11 | std::uint16_t mid; 12 | std::uint32_t high; 13 | std::uint32_t reserved0; 14 | } __attribute__((packed)) idt_entry_t; 15 | 16 | typedef struct { 17 | std::uint16_t limit; 18 | std::uint64_t base; 19 | } __attribute__((packed)) idtr_t; 20 | 21 | typedef struct { 22 | std::uint64_t cr3; 23 | std::uint64_t rax; 24 | std::uint64_t rbx; 25 | std::uint64_t rcx; 26 | std::uint64_t rdx; 27 | std::uint64_t rsi; 28 | std::uint64_t rdi; 29 | std::uint64_t rbp; 30 | std::uint64_t r8; 31 | std::uint64_t r9; 32 | std::uint64_t r10; 33 | std::uint64_t r11; 34 | std::uint64_t r12; 35 | std::uint64_t r13; 36 | std::uint64_t r14; 37 | std::uint64_t r15; 38 | std::uint64_t vec; 39 | std::uint64_t err_code; 40 | std::uint64_t rip; 41 | std::uint64_t cs; 42 | std::uint64_t rflags; 43 | std::uint64_t rsp; 44 | std::uint64_t ss; 45 | } int_frame_t; 46 | 47 | extern "C" void ignoreStub(); 48 | 49 | namespace arch { 50 | namespace x86_64 { 51 | namespace interrupts { 52 | class idt { 53 | public: 54 | static void init(); 55 | static void set_entry(std::uint64_t base,std::uint8_t vec,std::uint8_t flags,std::uint8_t ist); 56 | static std::uint8_t alloc(); 57 | 58 | static void load(); 59 | }; 60 | }; 61 | }; 62 | }; 63 | 64 | -------------------------------------------------------------------------------- /tools/pkg/8/gtk/diff/dbus.diff: -------------------------------------------------------------------------------- 1 | diff --git dbus-clean/dbus/dbus-sysdeps-unix.c dbus-workdir/dbus/dbus-sysdeps-unix.c 2 | index 87ba2d8..c4ab364 100644 3 | --- dbus-clean/dbus/dbus-sysdeps-unix.c 4 | +++ dbus-workdir/dbus/dbus-sysdeps-unix.c 5 | @@ -2589,29 +2589,12 @@ DBusSocket 6 | _dbus_accept (DBusSocket listen_fd) 7 | { 8 | DBusSocket client_fd; 9 | - struct sockaddr addr; 10 | - socklen_t addrlen; 11 | -#ifdef HAVE_ACCEPT4 12 | - dbus_bool_t cloexec_done; 13 | -#endif 14 | - 15 | - addrlen = sizeof (addr); 16 | + struct sockaddr_un addr; 17 | + socklen_t addrlen = sizeof (addr); 18 | 19 | retry: 20 | - 21 | -#ifdef HAVE_ACCEPT4 22 | - /* 23 | - * At compile-time, we assume that if accept4() is available in 24 | - * libc headers, SOCK_CLOEXEC is too. At runtime, it is still 25 | - * not necessarily true that either is supported by the running kernel. 26 | - */ 27 | - client_fd.fd = accept4 (listen_fd.fd, &addr, &addrlen, SOCK_CLOEXEC); 28 | - cloexec_done = client_fd.fd >= 0; 29 | - 30 | - if (client_fd.fd < 0 && (errno == ENOSYS || errno == EINVAL)) 31 | -#endif 32 | { 33 | - client_fd.fd = accept (listen_fd.fd, &addr, &addrlen); 34 | + client_fd.fd = accept (listen_fd.fd, (struct sockaddr *)&addr, &addrlen); 35 | } 36 | 37 | if (client_fd.fd < 0) 38 | @@ -2620,14 +2603,6 @@ _dbus_accept (DBusSocket listen_fd) 39 | goto retry; 40 | } 41 | 42 | - _dbus_verbose ("client fd %d accepted\n", client_fd.fd); 43 | - 44 | -#ifdef HAVE_ACCEPT4 45 | - if (!cloexec_done) 46 | -#endif 47 | - { 48 | - _dbus_fd_set_close_on_exec(client_fd.fd); 49 | - } 50 | 51 | return client_fd; 52 | } 53 | -------------------------------------------------------------------------------- /kernel/src/drivers/hpet.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | std::uint64_t hpet_base,hpet_clock_nano; 8 | std::uint8_t hpet_is_32_bit = 0; 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | std::uint64_t __hpet_timestamp() { 24 | return hpet_is_32_bit ? *(volatile uint32_t*)(hpet_base + 0xf0) : *(volatile uint64_t*)(hpet_base + 0xf0); 25 | } 26 | 27 | std::uint64_t drivers::hpet::nanocurrent() { 28 | return __hpet_timestamp() * hpet_clock_nano; 29 | } 30 | 31 | extern std::uint16_t KERNEL_GOOD_TIMER; 32 | 33 | void drivers::hpet::init() { 34 | uacpi_table hpet; 35 | uacpi_status ret = uacpi_table_find_by_signature("HPET",&hpet); 36 | assert(ret == UACPI_STATUS_OK,"HPET required to get working orange"); 37 | struct acpi_hpet* hpet_table = ((struct acpi_hpet*)hpet.virt_addr); 38 | hpet_base = (std::uint64_t)Other::toVirt(hpet_table->address.address); 39 | memory::paging::kernelmap(0,hpet_table->address.address); 40 | 41 | *(volatile std::uint64_t*)(hpet_base + 0x10) |= 1; 42 | hpet_is_32_bit = (*(volatile uint64_t*)hpet_base & (1 << 13)) ? 0 : 1; 43 | hpet_clock_nano = (*(volatile uint32_t*)(hpet_base + 4)) / 1000000; 44 | 45 | } 46 | 47 | void drivers::hpet::sleep(std::uint64_t us) { 48 | std::uint64_t start = __hpet_timestamp(); 49 | std::uint64_t conv = us * 1000; 50 | while((__hpet_timestamp() - start) * hpet_clock_nano < conv) 51 | asm volatile("nop"); 52 | } 53 | -------------------------------------------------------------------------------- /kernel/include/drivers/cmos.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #pragma once 6 | 7 | #define CMOS_ADDRESS 0x70 8 | #define CMOS_DATA 0x71 9 | #define CMOS_SECONDS 0x00 10 | #define CMOS_MINUTES 0x02 11 | #define CMOS_HOURS 0x04 12 | #define CMOS_DAY 0x07 13 | #define CMOS_MONTH 0x08 14 | #define CMOS_YEAR 0x09 15 | 16 | namespace drivers { 17 | class cmos { 18 | public: 19 | static inline std::uint8_t cmos_read(std::uint8_t reg) { 20 | drivers::io io; 21 | io.outb(CMOS_ADDRESS, reg); 22 | return io.inb(CMOS_DATA); 23 | } 24 | 25 | static inline std::uint8_t bcd_to_binary(std::uint8_t bcd) { 26 | return (bcd & 0x0F) + ((bcd / 16) * 10); 27 | } 28 | 29 | static std::uint8_t second() { 30 | uint8_t seconds = cmos_read(CMOS_SECONDS); 31 | return bcd_to_binary(seconds); 32 | } 33 | 34 | static std::uint8_t minute() { 35 | uint8_t minutes = cmos_read(CMOS_MINUTES); 36 | return bcd_to_binary(minutes); 37 | } 38 | 39 | static std::uint8_t hour() { 40 | uint8_t hours = cmos_read(CMOS_HOURS); 41 | return bcd_to_binary(hours); 42 | } 43 | 44 | static std::uint8_t day() { 45 | uint8_t day = cmos_read(CMOS_DAY); 46 | return bcd_to_binary(day); 47 | } 48 | 49 | static std::uint8_t month() { 50 | uint8_t month = cmos_read(CMOS_MONTH); 51 | return bcd_to_binary(month); 52 | } 53 | 54 | static std::uint16_t year() { 55 | uint8_t year = cmos_read(CMOS_YEAR); 56 | return 2000 + bcd_to_binary(year); 57 | } 58 | }; 59 | }; -------------------------------------------------------------------------------- /kernel/include/etc/logging.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define LEVEL_MESSAGE_OK 0 5 | #define LEVEL_MESSAGE_FAIL 1 6 | #define LEVEL_MESSAGE_WARN 2 7 | #define LEVEL_MESSAGE_INFO 3 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | int __snprintf(char *buffer, size_t bufsz, char const *fmt, va_list vlist); 15 | int __printfbuf(char* buffer, size_t bufsf, char const* fmt, ...); 16 | 17 | 18 | class Log { 19 | private: 20 | struct flanterm_context* ft_ctx0; 21 | public: 22 | 23 | void Setup(struct flanterm_context* ft_ctx) { 24 | ft_ctx0 = ft_ctx; 25 | } 26 | 27 | void Write(char* buffer, int len) { 28 | flanterm_write(ft_ctx0,buffer,len); 29 | } 30 | 31 | static void Raw(char* msg,...); 32 | static void Init(); 33 | static void Display(int level,char* msg,...); 34 | static void SerialDisplay(int level,char* msg,...); 35 | }; 36 | 37 | void dmesg0(char* msg,...); 38 | std::uint64_t dmesg_bufsize(); 39 | 40 | void dmesg_read(char* buffer,std::uint64_t count); 41 | 42 | #include 43 | 44 | void panic_wrap(const char* msg, ...); 45 | 46 | #define assert(cond, msg,...) if(!(cond)) panic_wrap("Failed assert at %s:%s:%d \"" msg "\"\n" , __FILE__ ,__FUNCTION__, __LINE__ , ##__VA_ARGS__) 47 | 48 | #define dmesg(fmt,...) if(1) dmesg0("[%llu] %s: " fmt "\n", drivers::tsc::currentus() ,__FUNCTION__, ##__VA_ARGS__) 49 | #define BREAKPOINT() Log::Display(LEVEL_MESSAGE_INFO,"breakpoint %s:%d\n ",__FILE__,__LINE__) 50 | 51 | #define DEBUG(is_enabled,fmt,...) if(is_enabled) dmesg0("[%llu] %s: " fmt "\n", drivers::tsc::currentus() ,__FUNCTION__, ##__VA_ARGS__) 52 | #define STUB(is_enabled) if(is_enabled) Log::SerialDisplay(LEVEL_MESSAGE_INFO, "%s() is a stub !\n", __FUNCTION__) -------------------------------------------------------------------------------- /kernel/include/drivers/io.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | namespace drivers { 7 | class io { 8 | private: 9 | public: 10 | io() { 11 | 12 | } 13 | 14 | inline void outb(std::uint16_t port, std::uint8_t val) { 15 | __asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory"); 16 | } 17 | 18 | inline void outw(std::uint16_t port, std::uint16_t val) { 19 | __asm__ volatile ("outw %0, %1" : : "a"(val), "Nd"(port) : "memory"); 20 | } 21 | 22 | inline void outd(std::uint16_t port, std::uint32_t val) { 23 | __asm__ volatile ("outl %0, %1" : : "a"(val), "Nd"(port) : "memory"); 24 | } 25 | 26 | inline std::uint8_t inb(std::uint16_t port) { 27 | std::uint8_t ret; 28 | __asm__ volatile ("inb %1, %0" 29 | : "=a"(ret) 30 | : "Nd"(port) 31 | : "memory"); 32 | return ret; 33 | } 34 | 35 | inline std::uint16_t inw(std::uint16_t port) { 36 | std::uint16_t ret; 37 | __asm__ volatile ("inw %1, %0" 38 | : "=a"(ret) 39 | : "Nd"(port) 40 | : "memory"); 41 | return ret; 42 | } 43 | 44 | inline std::uint32_t ind(std::uint16_t port) { 45 | std::uint32_t ret; 46 | __asm__ volatile ("inl %1, %0" 47 | : "=a"(ret) 48 | : "Nd"(port) 49 | : "memory"); 50 | return ret; 51 | } 52 | 53 | 54 | inline void wait() { 55 | outb(0x80,0); 56 | } 57 | 58 | }; 59 | }; -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Orange 2 | 3 | Orange is my posix x86_64 os with microkernel features 4 | 5 | [![GitHub top language](https://img.shields.io/github/languages/top/cpplover0/orange?logo=c&label=)](https://github.com/cpplover0/orange/blob/main/kernel/GNUmakefile) 6 | [![GitHub license](https://img.shields.io/github/license/cpplover0/orange)](https://github.com/cpplover0/orange/blob/master/LICENSE) 7 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/e78ad48f394f46d1bb98f1942c7e1f21)]() 8 | [![GitHub contributors](https://img.shields.io/github/contributors/cpplover0/orange)](https://github.com/cpplover0/orange/graphs/contributors) 9 | [![GitHub commit activity](https://img.shields.io/github/commit-activity/m/cpplover0/orange)](https://github.com/cpplover0/orange/commits) 10 | 11 | ## Preview 12 | ![fastfetch and lua](https://github.com/cppLover0/Orange/blob/main/tools/img/work.png?raw=true) 13 | 14 | ## Devices which supported by orange 15 | 16 | - [x] hpet 17 | - [x] pvclock 18 | - [x] ioapic 19 | - [x] ps/2 20 | - [x] ps/2 keyboard 21 | - [x] ps/2 mouse 22 | - [x] xhci 23 | - [x] usb keyboard 24 | - [x] usb mouse 25 | 26 | # Build 27 | 28 | Build kernel 29 | ```sh 30 | make all 31 | ``` 32 | 33 | Build initrd (You should build it before running os) 34 | ```sh 35 | sh tar-initrd.sh 36 | ``` 37 | 38 | Build cross-compiler 39 | ```sh 40 | sh build-cross.sh 41 | ``` 42 | 43 | Build kernel and run iso 44 | ```sh 45 | make run 46 | ``` 47 | 48 | ## TODO 49 | 50 | - [x] Move XHCI driver from old kernel to userspace 51 | - [x] Implement IRQ userspace handling 52 | - [x] Port lua, fastfetch, doomgeneric, nano and etc. 53 | - [x] Improve XHCI driver 54 | - [x] Port Xorg 55 | - [ ] Port twm 56 | - [ ] Port wine 57 | - [ ] Implement userspace disk drivers 58 | - [x] Improve kernel path resolver (add symlink support when trying to access another filesystem) -------------------------------------------------------------------------------- /kernel/include/generic/mm/paging.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #pragma once 6 | 7 | #define PTE_MASK_VALUE 0x000ffffffffff000 8 | 9 | #define PTE_PRESENT (1 << 0) 10 | #define PTE_RW (1 << 1) 11 | #define PTE_USER (1 << 2) 12 | #define PTE_WC ((1 << 7) | (1 << 3)) 13 | #define PTE_MMIO (1ull << 4) 14 | 15 | #define PTE_INDEX(address,bit) ((address & (uint64_t)0x1FF << bit) >> bit) 16 | 17 | typedef struct alwaysmapped { 18 | std::uint64_t phys; 19 | std::uint64_t len; 20 | struct alwaysmapped* next; 21 | } alwaysmapped_t; 22 | 23 | namespace memory { 24 | 25 | inline void pat(std::uint8_t index, std::uint8_t type) { 26 | std::uint64_t pat = __rdmsr(0x277); 27 | pat &= ~(0xFFULL << (index * 8)); 28 | pat |= ((std::uint64_t)type << (index * 8)); 29 | __wrmsr(0x277, pat); 30 | } 31 | 32 | class paging { 33 | public: 34 | static void init(); 35 | static void map(std::uint64_t cr3,std::uint64_t phys,std::uint64_t virt,std::uint64_t flags); 36 | static void mapid(std::uint64_t cr3,std::uint64_t phys,std::uint64_t virt,std::uint64_t flags,std::uint32_t id); 37 | static void maprange(std::uint64_t cr3,std::uint64_t phys,std::uint64_t virt,std::uint64_t len,std::uint64_t flags); 38 | static void maprangeid(std::uint64_t cr3,std::uint64_t phys,std::uint64_t virt,std::uint64_t len,std::uint64_t flags, std::uint32_t id); 39 | static void mapentry(std::uint64_t cr3,std::uint8_t type,std::uint64_t add_flags); 40 | static void mapkernel(std::uint64_t cr3,std::uint32_t id); 41 | static void* kernelmap(std::uint64_t cr3,std::uint64_t phys); 42 | static void enablekernel(); 43 | static void enablepaging(std::uint64_t cr3); 44 | static void alwaysmappedadd(std::uint64_t phys, std::uint64_t len); 45 | static void alwaysmappedmap(std::uint64_t cr3,std::uint32_t id); 46 | static std::uint64_t kernelget(); 47 | }; 48 | 49 | }; -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/interrupts/idt.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | using namespace Lists; 11 | using namespace arch::x86_64::interrupts; 12 | 13 | idt_entry_t idt_entries[255]; 14 | Bitmap* idt_bitmap; 15 | idtr_t idtr; 16 | 17 | extern "C" void* isrTable[]; 18 | 19 | extern "C" void ignoreStubC() { 20 | arch::x86_64::cpu::lapic::eoi(); 21 | } 22 | 23 | void arch::x86_64::interrupts::idt::init() { 24 | memset(idt_entries,0,sizeof(idt_entries)); 25 | idt_bitmap = new Bitmap(255); 26 | 27 | idtr.base = (std::uint64_t)idt_entries; 28 | idtr.limit = (std::uint16_t)sizeof(idt_entry_t) * 256 - 1; 29 | 30 | for(uint8_t vec = 0;vec <32;vec++){ 31 | set_entry((std::uint64_t)isrTable[vec],vec,0x8E,1); 32 | } 33 | 34 | for(uint8_t vec = 32; vec < 255; vec++) { 35 | set_entry((std::uint64_t)ignoreStub,vec,0x8E,4); 36 | idt_bitmap->clear(vec); 37 | } 38 | 39 | idt_bitmap->set(32); 40 | load(); 41 | } 42 | 43 | void arch::x86_64::interrupts::idt::load() { 44 | __asm__ volatile ("lidt %0" : : "m"(idtr)); 45 | } 46 | 47 | void arch::x86_64::interrupts::idt::set_entry(std::uint64_t base,std::uint8_t vec,std::uint8_t flags,std::uint8_t ist) { 48 | idt_entry_t* descriptor = &idt_entries[vec]; 49 | 50 | descriptor->low = (std::uint64_t)base & 0xFFFF; 51 | descriptor->cs = 0x08; 52 | descriptor->ist = ist; 53 | descriptor->attr = flags; 54 | descriptor->mid = ((std::uint64_t)base >> 16) & 0xFFFF; 55 | descriptor->high = ((std::uint64_t)base >> 32) & 0xFFFFFFFF; 56 | descriptor->reserved0 = 0; 57 | 58 | idt_bitmap->set(vec); 59 | 60 | } 61 | 62 | std::uint8_t arch::x86_64::interrupts::idt::alloc() { 63 | for(int i = 0;i < 255;i++) 64 | if(!idt_bitmap->test(i)) { 65 | idt_bitmap->set(i); 66 | return i; 67 | } 68 | } -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/cpu/gdt.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | typedef struct __attribute__((packed)) { 7 | std::uint16_t size; 8 | std::uint64_t base; 9 | } gdt_pointer_t; 10 | 11 | typedef struct __attribute__((packed)) { 12 | std::uint16_t limit; 13 | std::uint16_t baselow16; 14 | std::uint8_t basemid8; 15 | std::uint8_t access; 16 | std::uint8_t granularity; 17 | std::uint8_t basehigh8; 18 | } gdt_entry_t; 19 | 20 | typedef struct __attribute__((packed)) { 21 | std::uint16_t length; 22 | std::uint16_t baselow16; 23 | std::uint8_t basemid8; 24 | std::uint8_t flags0; 25 | std::uint8_t flags1; 26 | std::uint8_t basehigh8; 27 | std::uint32_t baseup32; 28 | std::uint32_t reserved; 29 | } tss_entry_t; 30 | 31 | typedef struct __attribute__((packed)) { 32 | std::uint32_t reserved0; 33 | std::uint64_t rsp[3]; 34 | std::uint64_t reserved1; 35 | std::uint64_t ist[7]; 36 | std::uint32_t reserved2; 37 | std::uint32_t reserved3; 38 | std::uint16_t reserved4; 39 | std::uint16_t iopb_offsset; 40 | } tss_t; 41 | 42 | typedef struct __attribute__((packed)) { 43 | gdt_entry_t zero; 44 | gdt_entry_t _64bitcode; 45 | gdt_entry_t _64bitdata; 46 | gdt_entry_t usercode; 47 | gdt_entry_t userdata; 48 | tss_entry_t tss; 49 | } gdt_t; 50 | 51 | extern "C" void loadtss(); 52 | extern "C" void loadgdt(void* gdtr); 53 | 54 | namespace arch { 55 | namespace x86_64 { 56 | namespace cpu { 57 | class gdt { 58 | private: 59 | gdt_t gdt_obj; 60 | gdt_pointer_t gdtr; 61 | public: 62 | 63 | void LoadTSS() { 64 | loadtss(); 65 | } 66 | 67 | void LoadGDT() { 68 | loadgdt(&gdtr); 69 | } 70 | 71 | static void init(); 72 | 73 | gdt() { 74 | init(); 75 | } 76 | }; 77 | }; 78 | }; 79 | }; -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/cpu/lapic.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace arch { 19 | namespace x86_64 { 20 | namespace cpu { 21 | class lapic { 22 | 23 | static inline std::uint64_t base() { 24 | return (std::uint64_t)Other::toVirt(__rdmsr(0x1B) & 0xFFFFF000); 25 | } 26 | 27 | static inline std::uint32_t read(std::uint32_t reg) { 28 | return *(volatile std::uint32_t*)(base() + reg); 29 | } 30 | 31 | static inline void write(std::uint32_t reg,std::uint32_t value) { 32 | *(volatile std::uint32_t*)(base() + reg) = value; 33 | } 34 | 35 | public: 36 | 37 | static inline std::uint32_t id() { 38 | return read(0x20) >> 24; 39 | } 40 | 41 | static inline void eoi() { 42 | write(0xB0,0); 43 | } 44 | 45 | static inline void tick(std::uint64_t tick) { 46 | write(0x380,tick); 47 | } 48 | 49 | static inline std::uint64_t init(std::uint32_t us) { 50 | __wrmsr(0x1B,__rdmsr(0x1B)); 51 | memory::paging::kernelmap(0,__rdmsr(0x1B) & 0xFFFFF000); 52 | write(0xf0,0xff | 0x100); 53 | write(0x3e0,1); 54 | write(0x320,32 | (1 << 16)); 55 | write(0x380,0xFFFFFFFF); 56 | time::sleep(us); 57 | std::uint64_t ticks = 0xFFFFFFFF - read(0x390); 58 | write(0x320, 32 | (1 << 17)); 59 | write(0x3e0,1); 60 | write(0x380,0); 61 | return ticks; 62 | } 63 | }; 64 | }; 65 | }; 66 | }; -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/asm/scheduling.asm: -------------------------------------------------------------------------------- 1 | 2 | extern schedulingSchedule 3 | global schedulingEnter 4 | global schedulingEnd 5 | global yield 6 | 7 | yield: 8 | int 32 9 | ret 10 | 11 | global yield0 12 | 13 | yield0: 14 | int 32 15 | ret 16 | 17 | 18 | schedulingEnter: 19 | cli 20 | cmp byte [rsp + 8],0x08 21 | jz .cont 22 | swapgs 23 | .cont: 24 | push qword 0 25 | push qword 0 26 | push r15 27 | push r14 28 | push r13 29 | push r12 30 | push r11 31 | push r10 32 | push r9 33 | push r8 34 | push rbp 35 | push rdi 36 | push rsi 37 | push rdx 38 | push rcx 39 | push rbx 40 | push rax 41 | mov rax,cr3 42 | push rax 43 | mov rdi,rsp 44 | jmp schedulingSchedule 45 | 46 | global schedulingScheduleSaveAndChangeStack 47 | schedulingScheduleSaveAndChangeStack: 48 | cli 49 | mov rsi,rsp 50 | pop rdx 51 | mov rsp,rdi 52 | 53 | push 0x10 54 | push rsi 55 | pushfq 56 | push 0x08 57 | push rdx 58 | 59 | push qword 0 60 | push qword 0 61 | push r15 62 | push r14 63 | push r13 64 | push r12 65 | push r11 66 | push r10 67 | push r9 68 | push r8 69 | push rbp 70 | push rdi 71 | push rsi 72 | push rdx 73 | push rcx 74 | push rbx 75 | push rax 76 | mov rax,cr3 77 | push rax 78 | mov rdi,rsp 79 | jmp schedulingSchedule 80 | 81 | 82 | global schedulingScheduleAndChangeStack 83 | schedulingScheduleAndChangeStack: 84 | mov rsp,rdi 85 | mov rdi,rsi 86 | jmp schedulingSchedule 87 | 88 | schedulingEnd: 89 | mov rsp,rdi 90 | pop rax 91 | mov cr3,rax 92 | pop rax 93 | pop rbx 94 | pop rcx 95 | pop rdx 96 | pop rsi 97 | pop rdi 98 | pop rbp 99 | pop r8 100 | pop r9 101 | pop r10 102 | pop r11 103 | pop r12 104 | pop r13 105 | pop r14 106 | pop r15 107 | add rsp,16 108 | 109 | cmp byte [rsp + 8],0x08 110 | jz .end 111 | swapgs 112 | .end: 113 | iretq -------------------------------------------------------------------------------- /kernel/include/drivers/pci.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | /* Copypasted from old kernel :) */ 6 | 7 | typedef struct { 8 | std::uint16_t vendorID; 9 | std::uint16_t deviceID; 10 | std::uint16_t command; 11 | std::uint16_t status; 12 | std::uint8_t revisionID; 13 | std::uint8_t progIF; 14 | std::uint8_t subclass; 15 | std::uint8_t _class; 16 | std::uint8_t cacheLineSize; 17 | std::uint8_t latencyTimer; 18 | std::uint8_t headerType; 19 | std::uint8_t bist; 20 | std::uint32_t bar0; 21 | std::uint32_t bar1; 22 | std::uint32_t bar2; 23 | std::uint32_t bar3; 24 | std::uint32_t bar4; 25 | std::uint32_t bar5; 26 | std::uint32_t cardbusCISPointer; 27 | std::uint16_t subsystemVendorID; 28 | std::uint16_t subsystemID; 29 | std::uint32_t expansionROMBaseAddress; 30 | std::uint8_t capabilitiesPointer; 31 | std::uint8_t reserved0; 32 | std::uint16_t reserved1; 33 | std::uint32_t reserved2; 34 | std::uint8_t irq; 35 | std::uint8_t interruptPIN; 36 | std::uint8_t minGrant; 37 | std::uint8_t maxLatency; 38 | } __attribute__((packed)) pci_t; 39 | 40 | typedef struct pci_cap { 41 | std::uint8_t id; 42 | std::uint8_t off; 43 | std::uint8_t bus; 44 | std::uint8_t num; 45 | std::uint8_t func; 46 | std::uint16_t venID; 47 | std::uint16_t devID; 48 | std::uint8_t data[32]; 49 | struct pci_cap* next; 50 | } __attribute__((packed)) pci_cap_t; 51 | 52 | typedef struct { 53 | int used; 54 | std::uint8_t _class; 55 | std::uint8_t subclass; 56 | void (*pcidrv)(pci_t, std::uint8_t, std::uint8_t, std::uint8_t); 57 | } __attribute__((packed)) pci_driver_t; 58 | 59 | #define PCI_BAR_MASK ((1 << 0) | (1 << 1)) 60 | 61 | namespace drivers { 62 | class pci { 63 | public: 64 | static void initworkspace(); 65 | static void reg(void (*pcidrv)(pci_t, std::uint8_t, std::uint8_t, std::uint8_t), std::uint8_t _class, std::uint8_t subclass); 66 | static std::uint32_t in(std::int8_t bus, std::uint8_t num, std::uint8_t function, std::uint8_t offset, std::uint8_t bytewidth); 67 | static void out(std::uint8_t bus, std::uint8_t num, std::uint8_t function, std::uint8_t offset, std::uint32_t value, std::uint8_t bytewidth); 68 | }; 69 | }; -------------------------------------------------------------------------------- /tools/pkg/4/xorg-server/diff/xfbdev.diff: -------------------------------------------------------------------------------- 1 | diff --git xf86-video-fbdev-clean/src/Makefile.in xf86-video-fbdev-workdir/src/Makefile.in 2 | index 016d61d..84213a5 100644 3 | --- xf86-video-fbdev-clean/src/Makefile.in 4 | +++ xf86-video-fbdev-workdir/src/Makefile.in 5 | @@ -373,7 +373,7 @@ top_srcdir = @top_srcdir@ 6 | # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. 7 | AM_CFLAGS = $(BASE_CFLAGS) $(XORG_CFLAGS) 8 | fbdev_drv_la_LTLIBRARIES = fbdev_drv.la 9 | -fbdev_drv_la_LDFLAGS = -module -avoid-version 10 | +fbdev_drv_la_LDFLAGS = -module -avoid-version -L/ -lfbdevhw -lshadow 11 | fbdev_drv_ladir = @moduledir@/drivers 12 | fbdev_drv_la_SOURCES = \ 13 | fbdev.c 14 | diff --git xf86-video-fbdev-clean/src/fbdev.c xf86-video-fbdev-workdir/src/fbdev.c 15 | index 939c5b8..4ec1ccb 100644 16 | --- xf86-video-fbdev-clean/src/fbdev.c 17 | +++ xf86-video-fbdev-workdir/src/fbdev.c 18 | @@ -331,7 +331,7 @@ FBDevProbe(DriverPtr drv, int flags) 19 | 20 | dev = xf86FindOptionValue(devSections[i]->options,"fbdev"); 21 | if (devSections[i]->busID) { 22 | -#ifndef XSERVER_LIBPCIACCESS 23 | +#ifdef XSERVER_LIBPCIACCESS 24 | if (xf86ParsePciBusString(devSections[i]->busID,&bus,&device, 25 | &func)) { 26 | if (!xf86CheckPciSlot(bus,device,func)) 27 | @@ -343,7 +343,7 @@ FBDevProbe(DriverPtr drv, int flags) 28 | if (fbdevHWProbe(NULL,dev,NULL)) { 29 | pScrn = NULL; 30 | if (isPci) { 31 | -#ifndef XSERVER_LIBPCIACCESS 32 | +#ifdef XSERVER_LIBPCIACCESS 33 | /* XXX what about when there's no busID set? */ 34 | int entity; 35 | 36 | @@ -419,6 +419,7 @@ FBDevPreInit(ScrnInfoPtr pScrn, int flags) 37 | fPtr->pEnt = xf86GetEntityInfo(pScrn->entityList[0]); 38 | 39 | #ifndef XSERVER_LIBPCIACCESS 40 | +#if 0 41 | pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT; 42 | /* XXX Is this right? Can probably remove RAC_FB */ 43 | pScrn->racIoFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT; 44 | @@ -429,6 +430,7 @@ FBDevPreInit(ScrnInfoPtr pScrn, int flags) 45 | "xf86RegisterResources() found resource conflicts\n"); 46 | return FALSE; 47 | } 48 | +#endif 49 | #else 50 | if (fPtr->pEnt->location.type == BUS_PCI) 51 | pci_dev = fPtr->pEnt->location.id.pci; -------------------------------------------------------------------------------- /tools/pkg/5/xorg-modules/diff/xfbdev.diff: -------------------------------------------------------------------------------- 1 | diff --git xf86-video-fbdev-clean/src/Makefile.in xf86-video-fbdev-workdir/src/Makefile.in 2 | index 016d61d..84213a5 100644 3 | --- xf86-video-fbdev-clean/src/Makefile.in 4 | +++ xf86-video-fbdev-workdir/src/Makefile.in 5 | @@ -373,7 +373,7 @@ top_srcdir = @top_srcdir@ 6 | # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. 7 | AM_CFLAGS = $(BASE_CFLAGS) $(XORG_CFLAGS) 8 | fbdev_drv_la_LTLIBRARIES = fbdev_drv.la 9 | -fbdev_drv_la_LDFLAGS = -module -avoid-version 10 | +fbdev_drv_la_LDFLAGS = -module -avoid-version -lfbdevhw -lshadow 11 | fbdev_drv_ladir = @moduledir@/drivers 12 | fbdev_drv_la_SOURCES = \ 13 | fbdev.c 14 | diff --git xf86-video-fbdev-clean/src/fbdev.c xf86-video-fbdev-workdir/src/fbdev.c 15 | index 939c5b8..4ec1ccb 100644 16 | --- xf86-video-fbdev-clean/src/fbdev.c 17 | +++ xf86-video-fbdev-workdir/src/fbdev.c 18 | @@ -331,7 +331,7 @@ FBDevProbe(DriverPtr drv, int flags) 19 | 20 | dev = xf86FindOptionValue(devSections[i]->options,"fbdev"); 21 | if (devSections[i]->busID) { 22 | -#ifndef XSERVER_LIBPCIACCESS 23 | +#ifdef XSERVER_LIBPCIACCESS 24 | if (xf86ParsePciBusString(devSections[i]->busID,&bus,&device, 25 | &func)) { 26 | if (!xf86CheckPciSlot(bus,device,func)) 27 | @@ -343,7 +343,7 @@ FBDevProbe(DriverPtr drv, int flags) 28 | if (fbdevHWProbe(NULL,dev,NULL)) { 29 | pScrn = NULL; 30 | if (isPci) { 31 | -#ifndef XSERVER_LIBPCIACCESS 32 | +#ifdef XSERVER_LIBPCIACCESS 33 | /* XXX what about when there's no busID set? */ 34 | int entity; 35 | 36 | @@ -419,6 +419,7 @@ FBDevPreInit(ScrnInfoPtr pScrn, int flags) 37 | fPtr->pEnt = xf86GetEntityInfo(pScrn->entityList[0]); 38 | 39 | #ifndef XSERVER_LIBPCIACCESS 40 | +#if 0 41 | pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT; 42 | /* XXX Is this right? Can probably remove RAC_FB */ 43 | pScrn->racIoFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT; 44 | @@ -429,6 +430,7 @@ FBDevPreInit(ScrnInfoPtr pScrn, int flags) 45 | "xf86RegisterResources() found resource conflicts\n"); 46 | return FALSE; 47 | } 48 | +#endif 49 | #else 50 | if (fPtr->pEnt->location.type == BUS_PCI) 51 | pci_dev = fPtr->pEnt->location.id.pci; -------------------------------------------------------------------------------- /tools/pkg/12/i3wm/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | # 3 | 4 | 5 | . ../../pkg-lib.sh 6 | 7 | rm -rf pack 8 | 9 | mkdir -p pack 10 | 11 | cd pack 12 | 13 | git clone https://github.com/lloyd/yajl.git --depth=1 14 | 15 | cd yajl 16 | 17 | mkdir -p "$1/usr/include/yajl/api" 18 | 19 | cp -rf src/*.h "$1/usr/include/yajl" 20 | cp -rf src/api/*.h "$1/usr/include/yajl/" 21 | 22 | cp -rf ../../yajl_version.h "$1/usr/include/yajl/yajl_version.h" 23 | 24 | x86_64-orange-mlibc-gcc -c src/*.c -Isrc 25 | 26 | x86_64-orange-mlibc-ar rcs "$1/usr/lib/libyajl.a" ./*.o 27 | 28 | cp -rf ../../yajl.pc "$1/usr/lib/pkgconfig" 29 | 30 | cd .. 31 | 32 | git clone https://github.com/Airblader/xcb-util-xrm.git --depth=1 33 | cd xcb-util-xrm 34 | 35 | cp -rf include/xcb_xrm.h "$1/usr/include/xcb" 36 | x86_64-orange-mlibc-gcc -c src/database.c src/entry.c src/match.c src/resource.c src/util.c -Iinclude -Wno-implicit-function-declaration 37 | 38 | x86_64-orange-mlibc-ar rcs "$1/usr/lib/libxcb-xrm.a" database.o entry.o match.o resource.o util.o 39 | 40 | cp -rf ../../xcb-xrm.pc.in "$1/usr/lib/pkgconfig/xcb-xrm.pc" 41 | 42 | cd .. 43 | 44 | wget https://github.com/xkbcommon/libxkbcommon/archive/refs/tags/xkbcommon-1.13.0.tar.gz 45 | tar -xvf xkbcommon-1.13.0.tar.gz 46 | 47 | cd libxkbcommon-xkbcommon-1.13.0 48 | 49 | mkdir -p build 50 | 51 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Denable-wayland=false -Denable-x11=true build 52 | 53 | cd build 54 | 55 | meson compile -j$(nproc) 56 | DESTDIR="$1" meson install --no-rebuild 57 | 58 | cd ../.. 59 | 60 | fast_install "$1" http://www.freedesktop.org/software/startup-notification/releases/startup-notification-0.12.tar.gz "lf_cv_sane_realloc=1" 61 | 62 | git clone https://github.com/enki/libev.git --depth=1 63 | cd libev 64 | 65 | autotools_recursive_regen 66 | ./configure --host=x86_64-orange-mlibc --prefix=/usr 67 | make -j$(nproc) 68 | DESTDIR="$1" make install 69 | 70 | cd .. 71 | 72 | wget https://i3wm.org/downloads/i3-4.24.tar.xz 73 | tar -xvf i3-4.24.tar.xz 74 | 75 | cd i3-4.24 76 | 77 | mkdir -p build 78 | 79 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr build 80 | 81 | cd build 82 | 83 | meson compile -j$(nproc) 84 | DESTDIR="$1" meson install --no-rebuild 85 | 86 | cd ../.. 87 | 88 | cd .. -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/cpu/gdt.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | gdt_t original_gdt = { 12 | {0,0,0,0,0,0}, /* 0x0 Null */ 13 | {0,0,0,0x9a,0xa2,0}, /* 0x08 64 bit code */ 14 | {0,0,0,0x92,0xa0,0}, /* just align user data and user code */ 15 | {0,0,0,0xF2,0,0}, /* 0x18 user data, here because its easier for syscalls */ 16 | {0,0,0,0xFA,0x20,0}, /* 0x20 user code */ 17 | {0x68,0,0,0x89,0x20,0,0,0} /* 0x28 tss */ 18 | }; 19 | 20 | void arch::x86_64::cpu::gdt::init() { 21 | arch::x86_64::cpu::gdt* new_gdt = (arch::x86_64::cpu::gdt*)memory::heap::malloc(sizeof(arch::x86_64::cpu::gdt)); 22 | tss_t* tss = new tss_t; 23 | 24 | /* For optimizations kheap doesn't zero memory */ 25 | memset(&new_gdt->gdt_obj,0,sizeof(gdt_t)); 26 | memset(tss,0,sizeof(tss_t)); 27 | 28 | memcpy(&new_gdt->gdt_obj,&original_gdt,sizeof(gdt_t)); 29 | 30 | tss->rsp[0] = memory::pmm::helper::alloc_kernel_stack(KERNEL_STACK_SIZE); 31 | tss->ist[0] = memory::pmm::helper::alloc_kernel_stack(KERNEL_STACK_SIZE); /* Exceptions */ 32 | tss->ist[1] = memory::pmm::helper::alloc_kernel_stack(KERNEL_STACK_SIZE); /* Timer */ 33 | tss->ist[2] = memory::pmm::helper::alloc_kernel_stack(KERNEL_STACK_SIZE); /* IRQ Layout */ 34 | tss->ist[3] = memory::pmm::helper::alloc_kernel_stack(KERNEL_STACK_SIZE); /* For ignorestub */ 35 | 36 | tss->iopb_offsset = sizeof(tss_t); 37 | new_gdt->gdt_obj.tss.baselow16 = (std::uint64_t)tss & 0xFFFF; 38 | new_gdt->gdt_obj.tss.basemid8 = ((std::uint64_t)tss >> 16) & 0xFF; 39 | new_gdt->gdt_obj.tss.basehigh8 = ((std::uint64_t)tss >> 24) & 0xFF; 40 | new_gdt->gdt_obj.tss.baseup32 = (std::uint64_t)tss >> 32; 41 | 42 | new_gdt->gdtr.size = sizeof(gdt_t) - 1; 43 | new_gdt->gdtr.base = (std::uint64_t)&new_gdt->gdt_obj; 44 | 45 | new_gdt->LoadGDT(); 46 | new_gdt->LoadTSS(); 47 | 48 | /* Also i want to init cpu data too */ 49 | auto cpudata = arch::x86_64::cpu::data(); 50 | cpudata->timer_ist_stack = memory::pmm::helper::alloc_kernel_stack(KERNEL_STACK_SIZE); 51 | 52 | } -------------------------------------------------------------------------------- /tools/pkg/4/xorg-server/diff/libgpg-error.diff: -------------------------------------------------------------------------------- 1 | diff -Naur libgpg-error-1.45/build-aux/config.sub libgpg-error-patched3/build-aux/config.sub 2 | --- libgpg-error-1.45/build-aux/config.sub 2018-10-24 11:00:20.000000000 +0300 3 | +++ libgpg-error-patched3/build-aux/config.sub 2025-10-15 14:39:02.553948824 +0300 4 | @@ -1358,7 +1358,7 @@ 5 | | os2* | vos* | palmos* | uclinux* | nucleus* \ 6 | | morphos* | superux* | rtmk* | windiss* \ 7 | | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ 8 | - | skyos* | haiku* | rdos* | toppers* | drops* | es* \ 9 | + | skyos* | orange* | haiku* | rdos* | toppers* | drops* | es* \ 10 | | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ 11 | | midnightbsd*) 12 | # Remember, each alternative MUST END IN *, to match a version number. 13 | diff -Naur libgpg-error-1.45/src/syscfg/lock-obj-pub.orange.h libgpg-error-patched3/src/syscfg/lock-obj-pub.orange.h 14 | --- libgpg-error-1.45/src/syscfg/lock-obj-pub.orange.h 1970-01-01 03:00:00.000000000 +0300 15 | +++ libgpg-error-patched3/src/syscfg/lock-obj-pub.orange.h 2018-10-12 18:12:38.000000000 +0300 16 | @@ -0,0 +1,25 @@ 17 | +## lock-obj-pub.x86_64-pc-linux-gnu.h 18 | +## File created by gen-posix-lock-obj - DO NOT EDIT 19 | +## To be included by mkheader into gpg-error.h 20 | + 21 | +typedef struct 22 | +{ 23 | + long _vers; 24 | + union { 25 | + volatile char _priv[40]; 26 | + long _x_align; 27 | + long *_xp_align; 28 | + } u; 29 | +} gpgrt_lock_t; 30 | + 31 | +#define GPGRT_LOCK_INITIALIZER {1,{{0,0,0,0,0,0,0,0, \ 32 | + 0,0,0,0,0,0,0,0, \ 33 | + 0,0,0,0,0,0,0,0, \ 34 | + 0,0,0,0,0,0,0,0, \ 35 | + 0,0,0,0,0,0,0,0}}} 36 | +## 37 | +## Local Variables: 38 | +## mode: c 39 | +## buffer-read-only: t 40 | +## End: 41 | +## 42 | diff -Naur libgpg-error-1.45/tests/t-printf.c libgpg-error-patched3/tests/t-printf.c 43 | --- libgpg-error-1.45/tests/t-printf.c 2018-12-12 11:14:31.000000000 +0300 44 | +++ libgpg-error-patched3/tests/t-printf.c 2025-10-15 14:44:20.729513269 +0300 45 | @@ -449,7 +449,7 @@ 46 | static void 47 | check_fprintf_sf (void) 48 | { 49 | - volatile char *nullptr = NULL; /* Avoid compiler warning. */ 50 | + 51 | struct sfstate_s sfstate = {NULL}; 52 | gpgrt_stream_t stream; 53 | const char *expect; 54 | -------------------------------------------------------------------------------- /tools/pkg/7/benchmark/main.c: -------------------------------------------------------------------------------- 1 | 2 | #define _GNU_SOURCE 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | void pipe_rw_test() { 15 | int fd[2]; 16 | pipe(fd); 17 | printf("OS pipe test\n"); 18 | 19 | char buffer[5]; 20 | 21 | for(int i = 0;i < 5;i++) { 22 | struct timespec start; 23 | struct timespec end; 24 | clock_gettime(CLOCK_MONOTONIC,&start); 25 | write(fd[1],"test\n",4); 26 | read(fd[0],buffer,5); 27 | clock_gettime(CLOCK_MONOTONIC,&end); 28 | printf("OS pipe test %d - %d ns\n",i,end.tv_nsec - start.tv_nsec); 29 | 30 | } 31 | 32 | } 33 | 34 | void rw_test() { 35 | printf("OS r/w test\n"); 36 | int fd = open("/tmp/testfd",O_RDWR | O_CREAT | O_TRUNC); 37 | char buffer[5]; 38 | 39 | for(int i = 0;i < 5;i++) { 40 | struct timespec start; 41 | struct timespec end; 42 | clock_gettime(CLOCK_MONOTONIC,&start); 43 | write(fd,"test\n",4); 44 | lseek(fd,0,SEEK_SET); 45 | read(fd,buffer,5); 46 | lseek(fd,0,SEEK_SET); 47 | clock_gettime(CLOCK_MONOTONIC,&end); 48 | printf("OS pipe test %d - %d ns\n",i,end.tv_nsec - start.tv_nsec); 49 | 50 | } 51 | } 52 | 53 | void open_test() { 54 | printf("OS open test\n"); 55 | for(int i = 0;i < 5;i++) { 56 | struct timespec start; 57 | struct timespec end; 58 | clock_gettime(CLOCK_MONOTONIC,&start); 59 | int fd = open("/tmp/testfd",O_RDWR | O_CREAT | O_TRUNC); 60 | close(fd); 61 | clock_gettime(CLOCK_MONOTONIC,&end); 62 | printf("OS pipe test %d - %d ns\n",i,end.tv_nsec - start.tv_nsec); 63 | 64 | } 65 | } 66 | 67 | void mmap_test() { 68 | printf("OS mmap test\n"); 69 | for(int i = 0;i < 5;i++) { 70 | struct timespec start; 71 | struct timespec end; 72 | clock_gettime(CLOCK_MONOTONIC,&start); 73 | void* addr = mmap(0,0x80000,0,MAP_ANONYMOUS,-1,0); 74 | clock_gettime(CLOCK_MONOTONIC,&end); 75 | printf("OS pipe test %d - %d ns\n",i,end.tv_nsec - start.tv_nsec); 76 | 77 | } 78 | } 79 | 80 | int main() { 81 | pipe_rw_test(); 82 | rw_test(); 83 | open_test(); 84 | mmap_test(); 85 | } -------------------------------------------------------------------------------- /kernel/include/generic/vfs/fd.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #pragma once 8 | 9 | namespace vfs { 10 | class fdmanager { 11 | public: 12 | 13 | inline static int create(arch::x86_64::process_t* proc) { 14 | userspace_fd_t* current = proc->fd; 15 | while(current) { 16 | if(current->state == USERSPACE_FD_STATE_UNUSED && current->index > 2) 17 | break; 18 | current = current->next; 19 | } 20 | 21 | if(!current) { 22 | current = (userspace_fd_t*)memory::pmm::_virtual::alloc(4096); 23 | zeromem(current); 24 | current->next = proc->fd; 25 | proc->fd = current; 26 | current->index = proc->fd_ptr++; 27 | } 28 | 29 | current->state = USERSPACE_FD_STATE_FILE; 30 | current->read_counter = -1; 31 | current->write_counter = -1; 32 | current->can_be_closed = 0; 33 | current->is_cached_path = 0; 34 | current->is_debug = 0; 35 | 36 | memset(current->path,0,2048); 37 | 38 | return current->index; 39 | 40 | } 41 | 42 | inline static userspace_fd_t* searchlowest(arch::x86_64::process_t* proc,std::uint32_t idx) { 43 | 44 | if(!proc) 45 | return 0; 46 | 47 | userspace_fd_t* current = proc->fd; 48 | userspace_fd_t* lowest = 0; 49 | 50 | while(current) { 51 | if(current->state == USERSPACE_FD_STATE_UNUSED || current->can_be_closed) { 52 | if(!lowest) 53 | lowest = current; 54 | if(current->index < lowest->index) 55 | lowest = current; 56 | } 57 | current = current->next; 58 | } 59 | 60 | return lowest; 61 | } 62 | 63 | inline static userspace_fd_t* search(arch::x86_64::process_t* proc,std::uint32_t idx) { 64 | 65 | if(!proc) 66 | return 0; 67 | 68 | userspace_fd_t* current = proc->fd; 69 | while(current) { 70 | if(current->index == idx && current->state != USERSPACE_FD_STATE_UNUSED) 71 | return current; 72 | current = current->next; 73 | } 74 | return 0; 75 | } 76 | }; 77 | } -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/cpu/smp.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | 33 | using namespace arch::x86_64::cpu; 34 | 35 | int balance_how_much_cpus = 1; 36 | 37 | int how_much_cpus = 1; 38 | std::atomic temp_how_much_cpus[12]; 39 | 40 | locks::spinlock mp_lock; 41 | 42 | void mp::sync(std::uint8_t id) { 43 | temp_how_much_cpus[id].fetch_add(1, std::memory_order_acq_rel); 44 | while (how_much_cpus != temp_how_much_cpus[id].load(std::memory_order_acquire)) { 45 | asm volatile("nop"); 46 | } 47 | time::sleep(1000*1000); // perform 1 second sleep 48 | temp_how_much_cpus[id].store(0, std::memory_order_release); 49 | } 50 | 51 | void __mp_bootstrap(struct LIMINE_MP(info)* smp_info) { 52 | mp_lock.lock(); 53 | memory::paging::enablekernel(); 54 | arch::x86_64::interrupts::idt::load(); 55 | arch::x86_64::cpu::gdt::init(); 56 | drivers::tsc::init(); 57 | 58 | arch::x86_64::cpu::data()->smp.cpu_id = balance_how_much_cpus++; 59 | 60 | arch::x86_64::cpu::data()->lapic_block = arch::x86_64::cpu::lapic::init(15000); 61 | arch::x86_64::cpu::sse::init(); 62 | arch::x86_64::syscall::init(); 63 | Log::Display(LEVEL_MESSAGE_OK,"Cpu %d is online \n",arch::x86_64::cpu::data()->smp.cpu_id); 64 | arch::x86_64::cpu::lapic::tick(arch::x86_64::cpu::data()->lapic_block); 65 | mp_lock.unlock(); 66 | mp::sync(0); 67 | mp::sync(1); 68 | asm volatile("sti"); 69 | while(1) { 70 | asm volatile("hlt"); 71 | } 72 | } 73 | 74 | void mp::init() { 75 | struct LIMINE_MP(response)* mp_info = BootloaderInfo::AccessMP(); 76 | 77 | how_much_cpus = mp_info->cpu_count; 78 | 79 | memset(temp_how_much_cpus,0,4*12); 80 | for(std::uint16_t i = 0;i < mp_info->cpu_count;i++) { 81 | if(mp_info->bsp_lapic_id != i) { 82 | mp_info->cpus[i]->goto_address = __mp_bootstrap; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /tools/pkg/8/gtk/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | 6 | mkdir -p pack 7 | 8 | cd pack 9 | 10 | # git clone https://github.com/libexpat/libexpat.git 11 | # cd libexpat 12 | # mkdir build 13 | # cd build 14 | 15 | # cmake ../expat -DCMAKE_TOOLCHAIN_FILE=$(realpath ../../../../../toolchain.cmake) -DCMAKE_INSTALL_PREFIX="/usr" 16 | 17 | # cmake --build . -j$(nproc) 18 | # DESTDIR="$1" cmake --install . 19 | 20 | # cd ../.. 21 | 22 | fast_install "$1" https://www.x.org/archive/individual/lib/libXtst-1.2.5.tar.gz 23 | 24 | git clone https://gitlab.gnome.org/GNOME/libxml2.git --depth=1 25 | cd libxml2 26 | 27 | mkdir build 28 | 29 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dpython=disabled -Dhistory=disabled -Dicu=disabled -Dreadline=disabled -Dzlib=enabled build 30 | cd build 31 | 32 | meson compile -j$(nproc) 33 | DESTDIR="$1" meson install --no-rebuild 34 | 35 | cd ../.. 36 | 37 | wget https://gitlab.freedesktop.org/dbus/dbus/-/archive/dbus-1.16.2/dbus-dbus-1.16.2.tar.gz 38 | tar -xvf dbus-dbus-1.16.2.tar.gz 39 | cd dbus-dbus-1.16.2 40 | 41 | diff_patch ../../diff/dbus.diff 42 | 43 | mkdir build 44 | 45 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Druntime_dir=/run -Dsystemd_system_unitdir=no -Dsystemd_user_unitdir=no -Dsystem_pid_file=/run/dbus/pid -Dsystem_socket=/run/dbus/system_bus_socket -Dselinux=disabled -Dapparmor=disabled -Dlibaudit=disabled -Dkqueue=disabled -Dlaunchd=disabled -Dsystemd=disabled -Dmodular_tests=disabled -Depoll=disabled build 46 | cd build 47 | 48 | meson compile -j$(nproc) 49 | DESTDIR="$1" meson install --no-rebuild 50 | 51 | touch "$1/usr/share/dbus-1/session.d/.keep" 52 | touch "$1/var/lib/dbus/.keep" 53 | 54 | cd ../.. 55 | 56 | wget https://gitlab.gnome.org/GNOME/at-spi2-core/-/archive/2.56.6/at-spi2-core-2.56.6.tar 57 | tar -xvf at-spi2-core-2.56.6.tar 58 | cd at-spi2-core-2.56.6 59 | 60 | mkdir build 61 | 62 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" -Dsystemd_user_dir=/tmp -Dintrospection=disabled --prefix=/usr build 63 | cd build 64 | 65 | meson compile -j$(nproc) 66 | DESTDIR="$1" meson install --no-rebuild 67 | 68 | cd ../.. 69 | 70 | wget https://github.com/GNOME/gobject-introspection/archive/refs/tags/1.73.0.tar.gz 71 | mv 1.73.0.tar.gz intro.tar.gz 72 | tar -xvf intro.tar.gz 73 | 74 | cd gobject-introspection-1.73.0 75 | 76 | mkdir build 77 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dgtk_doc=false -Dbuild_introspection_data=false build 78 | 79 | cd build 80 | 81 | meson compile -j$(nproc) 82 | DESTDIR="$1" meson install --no-rebuild 83 | 84 | cd ../.. 85 | 86 | cd .. -------------------------------------------------------------------------------- /kernel/include/generic/mm/pmm.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #pragma once 6 | 7 | #define LEVEL_TO_SIZE(level) (1U << (level)) 8 | #define MAX_LEVEL 32 9 | 10 | typedef struct buddy_info { 11 | union { 12 | struct { 13 | std::uint16_t level : 8; 14 | std::uint16_t is_was_splitted : 1; 15 | std::uint16_t is_splitted : 1; 16 | std::uint16_t is_free : 1; 17 | std::uint16_t split_x : 1; 18 | }; 19 | std::uint16_t buddy_info_raw; 20 | }; 21 | struct buddy_info* parent; 22 | struct buddy_info* twin; 23 | std::uint32_t id; 24 | std::uint64_t phys; 25 | } __attribute__((packed)) buddy_info_t; 26 | 27 | typedef struct { 28 | buddy_info_t* first; 29 | buddy_info_t* second; 30 | } buddy_split_t; 31 | 32 | typedef struct { 33 | uint64_t buddy_queue; 34 | uint64_t total_size; 35 | buddy_info_t* mem; 36 | } __attribute__((packed)) buddy_t; 37 | 38 | typedef struct { 39 | std::uint64_t virt; 40 | std::uint64_t real_size; //optimization for tmpfs 41 | } alloc_t; 42 | 43 | 44 | namespace memory { 45 | class buddy { 46 | private: 47 | static buddy_info_t* split_maximum(buddy_info_t* blud, std::uint64_t size); 48 | static buddy_info_t* put(std::uint64_t phys, std::uint8_t level); 49 | static buddy_split_t split(buddy_info_t* info); 50 | static void merge(buddy_info_t* budy); 51 | public: 52 | static void init(); 53 | static void free(std::uint64_t phys); 54 | static void fullfree(std::uint32_t id); 55 | static alloc_t alloc_ext(std::size_t size); 56 | static std::int64_t alloc(std::size_t size); 57 | static std::int64_t allocid(std::size_t size, std::uint32_t id); 58 | }; 59 | namespace pmm { 60 | 61 | 62 | class _physical { 63 | public: 64 | static void init(); 65 | static void free(std::uint64_t phys); 66 | static void fullfree(std::uint32_t id); 67 | static alloc_t alloc_ext(std::size_t size); 68 | static std::int64_t alloc(std::size_t size); 69 | static std::int64_t allocid(std::size_t size, std::uint32_t id); 70 | 71 | static void lock(); 72 | static void unlock(); 73 | 74 | }; 75 | class _virtual { 76 | public: 77 | static void free(void* virt); 78 | static void* alloc(std::size_t size); 79 | }; 80 | class helper { 81 | public: 82 | static std::uint64_t alloc_kernel_stack(std::size_t size); 83 | }; 84 | }; 85 | }; -------------------------------------------------------------------------------- /tools/pkg/3/bash/diff/gettext.diff: -------------------------------------------------------------------------------- 1 | diff --git gettext-clean/gettext-runtime/gnulib-lib/getlocalename_l-unsafe.c gettext-workdir/gettext-runtime/gnulib-lib/getlocalename_l-unsafe.c 2 | index 76dfec6..009f763 100644 3 | --- gettext-clean/gettext-runtime/gnulib-lib/getlocalename_l-unsafe.c 4 | +++ gettext-workdir/gettext-runtime/gnulib-lib/getlocalename_l-unsafe.c 5 | @@ -488,6 +488,8 @@ getlocalename_l_unsafe (int category, locale_t locale) 6 | struct gl_locale_category_t *plc = 7 | &locale->category[gl_log2_lcmask_to_index (gl_log2_lc_mask (category))]; 8 | return (struct string_with_storage) { plc->name, STORAGE_OBJECT }; 9 | +#elif defined __mlibc__ 10 | + return (struct string_with_storage) { "C", STORAGE_INDEFINITE }; 11 | #elif __GLIBC__ >= 2 && !defined __UCLIBC__ 12 | /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in 13 | glibc < 2.12. 14 | diff --git gettext-clean/gettext-runtime/intl/gnulib-lib/getlocalename_l-unsafe.c gettext-workdir/gettext-runtime/intl/gnulib-lib/getlocalename_l-unsafe.c 15 | index 76dfec6..009f763 100644 16 | --- gettext-clean/gettext-runtime/intl/gnulib-lib/getlocalename_l-unsafe.c 17 | +++ gettext-workdir/gettext-runtime/intl/gnulib-lib/getlocalename_l-unsafe.c 18 | @@ -488,6 +488,8 @@ getlocalename_l_unsafe (int category, locale_t locale) 19 | struct gl_locale_category_t *plc = 20 | &locale->category[gl_log2_lcmask_to_index (gl_log2_lc_mask (category))]; 21 | return (struct string_with_storage) { plc->name, STORAGE_OBJECT }; 22 | +#elif defined __mlibc__ 23 | + return (struct string_with_storage) { "C", STORAGE_INDEFINITE }; 24 | #elif __GLIBC__ >= 2 && !defined __UCLIBC__ 25 | /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in 26 | glibc < 2.12. 27 | diff --git gettext-clean/gettext-tools/gnulib-lib/getlocalename_l-unsafe.c gettext-workdir/gettext-tools/gnulib-lib/getlocalename_l-unsafe.c 28 | index 76dfec6..009f763 100644 29 | --- gettext-clean/gettext-tools/gnulib-lib/getlocalename_l-unsafe.c 30 | +++ gettext-workdir/gettext-tools/gnulib-lib/getlocalename_l-unsafe.c 31 | @@ -488,6 +488,8 @@ getlocalename_l_unsafe (int category, locale_t locale) 32 | struct gl_locale_category_t *plc = 33 | &locale->category[gl_log2_lcmask_to_index (gl_log2_lc_mask (category))]; 34 | return (struct string_with_storage) { plc->name, STORAGE_OBJECT }; 35 | +#elif defined __mlibc__ 36 | + return (struct string_with_storage) { "C", STORAGE_INDEFINITE }; 37 | #elif __GLIBC__ >= 2 && !defined __UCLIBC__ 38 | /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in 39 | glibc < 2.12. 40 | -------------------------------------------------------------------------------- /kernel/linker.ld: -------------------------------------------------------------------------------- 1 | /* Tell the linker that we want an x86_64 ELF64 output file */ 2 | OUTPUT_FORMAT(elf64-x86-64) 3 | 4 | /* We want the symbol kmain to be our entry point */ 5 | ENTRY(kmain) 6 | 7 | /* Define the program headers we want so the bootloader gives us the right */ 8 | /* MMU permissions; this also allows us to exert more control over the linking */ 9 | /* process. */ 10 | PHDRS 11 | { 12 | limine_requests PT_LOAD; 13 | text PT_LOAD; 14 | rodata PT_LOAD; 15 | data PT_LOAD; 16 | } 17 | 18 | SECTIONS 19 | { 20 | /* We want to be placed in the topmost 2GiB of the address space, for optimisations */ 21 | /* and because that is what the Limine spec mandates. */ 22 | /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */ 23 | /* that is the beginning of the region. */ 24 | . = 0xffffffff80000000; 25 | 26 | kernel_start = .; 27 | 28 | /* Define a section to contain the Limine requests and assign it to its own PHDR */ 29 | .limine_requests : { 30 | KEEP(*(.limine_requests_start)) 31 | KEEP(*(.limine_requests)) 32 | KEEP(*(.limine_requests_end)) 33 | } :limine_requests 34 | 35 | /* Move to the next memory page for .text */ 36 | . = ALIGN(CONSTANT(MAXPAGESIZE)); 37 | 38 | .text : { 39 | *(.text .text.*) 40 | } :text 41 | 42 | /* Move to the next memory page for .rodata */ 43 | . = ALIGN(CONSTANT(MAXPAGESIZE)); 44 | 45 | .rodata : { 46 | *(.rodata .rodata.*) 47 | } :rodata 48 | 49 | /* C++ is a language that allows for global constructors. In order to obtain the */ 50 | /* address of the ".init_array" section we need to define a symbol for it. */ 51 | .init_array : { 52 | __init_array = .; 53 | KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) 54 | KEEP(*(.init_array .ctors)) 55 | __init_array_end = .; 56 | } :rodata 57 | 58 | /* Move to the next memory page for .data */ 59 | . = ALIGN(CONSTANT(MAXPAGESIZE)); 60 | 61 | .data : { 62 | *(.data .data.*) 63 | } :data 64 | 65 | /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ 66 | /* unnecessary zeros will be written to the binary. */ 67 | /* If you need, for example, .init_array and .fini_array, those should be placed */ 68 | /* above this. */ 69 | .bss : { 70 | *(.bss .bss.*) 71 | *(COMMON) 72 | } :data 73 | 74 | kernel_end = .; 75 | 76 | /* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */ 77 | /DISCARD/ : { 78 | *(.eh_frame*) 79 | *(.note .note.*) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /kernel/src/etc/etc.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | 8 | void *memcpy(void *__restrict dest, const void *__restrict src, std::size_t n) { 9 | std::uint8_t *__restrict pdest = static_cast(dest); 10 | const std::uint8_t *__restrict psrc = static_cast(src); 11 | 12 | for (std::size_t i = 0; i < n; i++) { 13 | pdest[i] = psrc[i]; 14 | } 15 | 16 | return dest; 17 | } 18 | 19 | void *memset(void *s, int c, std::size_t n) { 20 | std::uint8_t *p = static_cast(s); 21 | 22 | for (std::size_t i = 0; i < n; i++) { 23 | p[i] = static_cast(c); 24 | } 25 | 26 | return s; 27 | } 28 | 29 | void *memmove(void *dest, const void *src, std::size_t n) { 30 | std::uint8_t *pdest = static_cast(dest); 31 | const std::uint8_t *psrc = static_cast(src); 32 | 33 | if (src > dest) { 34 | for (std::size_t i = 0; i < n; i++) { 35 | pdest[i] = psrc[i]; 36 | } 37 | } else if (src < dest) { 38 | for (std::size_t i = n; i > 0; i--) { 39 | pdest[i-1] = psrc[i-1]; 40 | } 41 | } 42 | 43 | return dest; 44 | } 45 | 46 | int memcmp(const void *s1, const void *s2, std::size_t n) { 47 | const std::uint8_t *p1 = static_cast(s1); 48 | const std::uint8_t *p2 = static_cast(s2); 49 | 50 | for (std::size_t i = 0; i < n; i++) { 51 | if (p1[i] != p2[i]) { 52 | return p1[i] < p2[i] ? -1 : 1; 53 | } 54 | } 55 | 56 | return 0; 57 | } 58 | 59 | } 60 | 61 | extern void (*__init_array[])(); 62 | extern void (*__init_array_end[])(); 63 | 64 | void Other::ConstructorsInit() { 65 | for (std::size_t i = 0; &__init_array[i] != __init_array_end; i++) { 66 | __init_array[i](); 67 | } 68 | } 69 | 70 | extern "C" { 71 | int __cxa_atexit(void (*)(void *), void *, void *) { return 0; } 72 | void __cxa_pure_virtual() { asm volatile("hlt"); } 73 | void *__dso_handle; 74 | } 75 | 76 | #include 77 | 78 | void *operator new(size_t size) 79 | { 80 | return memory::heap::malloc(size); 81 | } 82 | 83 | void *operator new[](size_t size) 84 | { 85 | return memory::heap::malloc(size); 86 | } 87 | 88 | void operator delete(void *p) 89 | { 90 | memory::heap::free(p); 91 | } 92 | 93 | void operator delete(void *p,unsigned long sz) 94 | { 95 | memory::heap::free(p); 96 | } 97 | 98 | void operator delete[](void *p) 99 | { 100 | memory::heap::free(p); 101 | } 102 | -------------------------------------------------------------------------------- /tools/initbase/root/.twmrc: -------------------------------------------------------------------------------- 1 | # 2 | # Default twm configuration file; needs to be kept small to conserve string 3 | # space in systems whose compilers don't handle medium-sized strings. 4 | # 5 | # Sites should tailor this file, providing any extra title buttons, menus, etc. 6 | # that may be appropriate for their environment. For example, if most of the 7 | # users were accustomed to uwm, the defaults could be set up not to decorate 8 | # any windows and to use meta-keys. 9 | # 10 | 11 | NoGrabServer 12 | RestartPreviousState 13 | DecorateTransients 14 | TitleFont "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*" 15 | ResizeFont "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*" 16 | MenuFont "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*" 17 | IconFont "-adobe-helvetica-bold-r-normal--*-100-*-*-*-*-*-*" 18 | IconManagerFont "-adobe-helvetica-bold-r-normal--*-100-*-*-*" 19 | #ClientBorderWidth 20 | 21 | Color 22 | { 23 | BorderColor "slategrey" 24 | DefaultBackground "rgb:2/a/9" 25 | DefaultForeground "gray85" 26 | TitleBackground "rgb:2/a/9" 27 | TitleForeground "gray85" 28 | MenuBackground "rgb:2/a/9" 29 | MenuForeground "gray85" 30 | MenuBorderColor "slategrey" 31 | MenuTitleBackground "gray70" 32 | MenuTitleForeground "rgb:2/a/9" 33 | IconBackground "rgb:2/a/9" 34 | IconForeground "gray85" 35 | IconBorderColor "gray85" 36 | IconManagerBackground "rgb:2/a/9" 37 | IconManagerForeground "gray85" 38 | } 39 | 40 | # 41 | # Define some useful functions for motion-based actions. 42 | # 43 | MoveDelta 3 44 | Function "move-or-lower" { f.move f.deltastop f.lower } 45 | Function "move-or-raise" { f.move f.deltastop f.raise } 46 | Function "move-or-iconify" { f.move f.deltastop f.iconify } 47 | 48 | # 49 | # Set some useful bindings. Sort of uwm-ish, sort of simple-button-ish 50 | # 51 | Button1 = : root : f.menu "defops" 52 | 53 | Button1 = m : window|icon : f.function "move-or-lower" 54 | Button2 = m : window|icon : f.iconify 55 | Button3 = m : window|icon : f.function "move-or-raise" 56 | 57 | Button1 = : title : f.function "move-or-raise" 58 | Button2 = : title : f.raiselower 59 | 60 | Button1 = : icon : f.function "move-or-iconify" 61 | Button2 = : icon : f.iconify 62 | 63 | Button1 = : iconmgr : f.iconify 64 | Button2 = : iconmgr : f.iconify 65 | 66 | # 67 | # And a menus with the usual things 68 | # 69 | menu "defops" 70 | { 71 | "Twm" f.title 72 | "Iconify" f.iconify 73 | "Resize" f.resize 74 | "Move" f.move 75 | "Raise" f.raise 76 | "Lower" f.lower 77 | "" f.nop 78 | "Focus" f.focus 79 | "Unfocus" f.unfocus 80 | "Show Iconmgr" f.showiconmgr 81 | "Hide Iconmgr" f.hideiconmgr 82 | "" f.nop 83 | "Sterm" f.exec "exec st &" 84 | "" f.nop 85 | "Kill" f.destroy 86 | "Delete" f.delete 87 | "" f.nop 88 | "Restart" f.restart 89 | "Exit" f.quit 90 | } -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/interrupts/irq.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | irq_t irq_table[255]; 16 | std::uint16_t irq_ptr = 0; 17 | 18 | std::uint8_t is_legacy_pic = 1; 19 | 20 | extern "C" void* irqTable[]; 21 | 22 | extern "C" void irqHandler(int_frame_t* ctx) { 23 | 24 | memory::paging::enablekernel(); 25 | if(!irq_table[ctx->vec - 1].is_userspace) 26 | irq_table[ctx->vec - 1].func(irq_table[ctx->vec - 1].arg); 27 | else { 28 | 29 | if(irq_table[ctx->vec - 1].irq == 1) { // irq 12 and irq 1 are connected together 30 | drivers::ioapic::mask(12); 31 | } else if(irq_table[ctx->vec - 1].irq == 12) { 32 | drivers::ioapic::mask(1); 33 | } else 34 | drivers::ioapic::mask(irq_table[ctx->vec - 1].irq); /* Mask */ 35 | 36 | userspace_fd_t fd; 37 | fd.is_cached_path = 0; 38 | memset(fd.path,0,sizeof(fd.path)); 39 | __printfbuf(fd.path,sizeof(fd.path),"/dev/masterirq%d",irq_table[ctx->vec - 1].irq); 40 | 41 | char i = 1; 42 | int status = vfs::vfs::write(&fd,&i,1); 43 | } 44 | 45 | arch::x86_64::cpu::lapic::eoi(); 46 | 47 | if(ctx->cs & 3) 48 | ctx->ss |= 3; 49 | 50 | if(ctx->ss & 3) 51 | ctx->cs |= 3; 52 | 53 | if(ctx->cs == 0x20) 54 | ctx->cs |= 3; 55 | 56 | if(ctx->ss == 0x18) 57 | ctx->ss |= 3; 58 | 59 | } 60 | 61 | void arch::x86_64::interrupts::irq::reset() { 62 | irq_ptr = 0; 63 | memset(irq_table,0,sizeof(irq_table)); 64 | } 65 | 66 | std::uint8_t arch::x86_64::interrupts::irq::create(std::uint16_t irq,std::uint8_t type,void (*func)(void* arg),void* arg,std::uint64_t flags) { 67 | uint8_t entry = 0; 68 | 69 | if(!is_legacy_pic) { 70 | entry = arch::x86_64::interrupts::idt::alloc(); 71 | arch::x86_64::interrupts::idt::set_entry((std::uint64_t)irqTable[entry - 0x20],entry,0x8E,3); 72 | if(type == IRQ_TYPE_LEGACY_USERSPACE) 73 | irq_table[irq_ptr].is_userspace = 1; 74 | 75 | drivers::ioapic::set(entry,irq,0,arch::x86_64::cpu::lapic::id()); 76 | } else { 77 | arch::x86_64::interrupts::idt::set_entry((std::uint64_t)irqTable[irq],irq + 0x20,0x8E,3); 78 | irq_table[irq].arg = arg; 79 | 80 | irq_table[irq].func = func; 81 | return irq + 0x20; 82 | } 83 | 84 | irq_table[irq_ptr].arg = arg; 85 | irq_table[irq_ptr].irq = irq; 86 | irq_table[irq_ptr++].func = func; 87 | return entry; 88 | } -------------------------------------------------------------------------------- /tools/pkg/7/games/diff/ace.diff: -------------------------------------------------------------------------------- 1 | diff --git ace-of-penguins-clean/lib/Makefile.am ace-of-penguins-workdir/lib/Makefile.am 2 | index 2056424..e93f8bd 100644 3 | --- ace-of-penguins-clean/lib/Makefile.am 4 | +++ ace-of-penguins-workdir/lib/Makefile.am 5 | @@ -6,7 +6,7 @@ noinst_HEADERS = cards.h 6 | CLEANFILES = images.c images.d 7 | 8 | INCLUDES = $(X_CFLAGS) @PDA@ 9 | -AM_LDFLAGS = $(X_LIBS) 10 | +AM_LDFLAGS = $(X_LIBS) -lpng -lz -lm 11 | 12 | BUILD_CC = @BUILD_CC@ 13 | AR = @AR@ 14 | diff --git ace-of-penguins-clean/lib/make-imglib.c ace-of-penguins-workdir/lib/make-imglib.c 15 | index 84cda12..8f12d4a 100644 16 | --- ace-of-penguins-clean/lib/make-imglib.c 17 | +++ ace-of-penguins-workdir/lib/make-imglib.c 18 | @@ -5,6 +5,7 @@ 19 | #include 20 | #include 21 | #include 22 | +#include 23 | 24 | #include 25 | 26 | @@ -86,7 +87,7 @@ scan_image_directory () 27 | png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0); 28 | info_ptr = png_create_info_struct (png_ptr); 29 | 30 | - if (setjmp (png_ptr->jmpbuf)) { 31 | + if (setjmp (png_jmpbuf(png_ptr))) { 32 | fclose (f); 33 | continue; 34 | } 35 | @@ -202,7 +203,7 @@ tokenize(char *string) 36 | char *rv; 37 | if (string) { 38 | next = string; 39 | - return; 40 | + return NULL; 41 | } 42 | while (*next && !isgraph(*next)) next++; 43 | if (!*next) return 0; 44 | diff --git ace-of-penguins-clean/lib/xwin.c ace-of-penguins-workdir/lib/xwin.c 45 | index e4bcca2..724be23 100644 46 | --- ace-of-penguins-clean/lib/xwin.c 47 | +++ ace-of-penguins-workdir/lib/xwin.c 48 | @@ -55,7 +55,7 @@ OptionDesc xwin_options_list[] = { 49 | { "-visual", OPTION_INTEGER, &visual_id }, 50 | { 0, 0, 0 } 51 | }; 52 | -OptionDesc *xwin_options = xwin_options_list; 53 | +//OptionDesc *xwin_options = xwin_options_list; 54 | 55 | Display *display=0; 56 | int screen=0; 57 | @@ -89,10 +89,10 @@ int help_background; 58 | /* Motif window hints */ 59 | typedef struct 60 | { 61 | - unsigned flags; 62 | - unsigned functions; 63 | - unsigned decorations; 64 | - int inputMode; 65 | + unsigned long flags; 66 | + unsigned long functions; 67 | + unsigned long decorations; 68 | + long inputMode; 69 | } PropMotifWmHints; 70 | 71 | typedef PropMotifWmHints PropMwmHints; 72 | @@ -841,13 +841,13 @@ build_image (image *src) 73 | png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0); 74 | info_ptr = png_create_info_struct (png_ptr); 75 | 76 | - if (setjmp (png_ptr->jmpbuf)) { 77 | + if (setjmp (png_jmpbuf(png_ptr))) { 78 | fprintf(stderr, "Invalid PNG image!\n"); 79 | return; 80 | } 81 | 82 | file_bytes = src->file_data; 83 | - png_set_read_fn (png_ptr, (voidp)&file_bytes, (png_rw_ptr)png_reader); 84 | + png_set_read_fn (png_ptr, (void*)&file_bytes, (png_rw_ptr)png_reader); 85 | 86 | png_read_info (png_ptr, info_ptr); 87 | -------------------------------------------------------------------------------- /kernel/src/lib/Flanterm/src/flanterm_backends/fb.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2022-2025 mintsuki and contributors. 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions are met: 5 | * 6 | * 1. Redistributions of source code must retain the above copyright notice, 7 | * this list of conditions and the following disclaimer. 8 | * 9 | * 2. Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 17 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23 | * POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef FLANTERM_FB_H 27 | #define FLANTERM_FB_H 1 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #include "../flanterm.h" 38 | 39 | #ifdef FLANTERM_IN_FLANTERM 40 | 41 | #include "fb_private.h" 42 | 43 | #endif 44 | 45 | struct flanterm_context *flanterm_fb_init( 46 | /* If _malloc and _free are nulled, use the bump allocated instance (1 use only). */ 47 | void *(*_malloc)(size_t size), 48 | void (*_free)(void *ptr, size_t size), 49 | uint32_t *framebuffer, size_t width, size_t height, size_t pitch, 50 | uint8_t red_mask_size, uint8_t red_mask_shift, 51 | uint8_t green_mask_size, uint8_t green_mask_shift, 52 | uint8_t blue_mask_size, uint8_t blue_mask_shift, 53 | uint32_t *canvas, /* If nulled, no canvas. */ 54 | uint32_t *ansi_colours, uint32_t *ansi_bright_colours, /* If nulled, default. */ 55 | uint32_t *default_bg, uint32_t *default_fg, /* If nulled, default. */ 56 | uint32_t *default_bg_bright, uint32_t *default_fg_bright, /* If nulled, default. */ 57 | /* If font is null, use default font and font_width and font_height ignored. */ 58 | void *font, size_t font_width, size_t font_height, size_t font_spacing, 59 | /* If scale_x and scale_y are 0, automatically scale font based on resolution. */ 60 | size_t font_scale_x, size_t font_scale_y, 61 | size_t margin 62 | ); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /kernel/src/etc/bootloaderinfo.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace { 10 | 11 | __attribute__((used, section(".limine_requests"))) 12 | volatile LIMINE_BASE_REVISION(3); 13 | 14 | } 15 | 16 | namespace { 17 | 18 | __attribute__((used, section(".limine_requests"))) 19 | volatile limine_framebuffer_request framebuffer_request = { 20 | .id = LIMINE_FRAMEBUFFER_REQUEST, 21 | .revision = 0, 22 | .response = nullptr 23 | }; 24 | 25 | __attribute__((used, section(".limine_requests"))) 26 | volatile limine_hhdm_request hhdm_request = { 27 | .id = LIMINE_HHDM_REQUEST, 28 | .revision = 0, 29 | .response = nullptr 30 | }; 31 | 32 | __attribute__((used, section(".limine_requests"))) 33 | volatile limine_memmap_request memmap_request = { 34 | .id = LIMINE_MEMMAP_REQUEST, 35 | .revision = 0, 36 | .response = nullptr 37 | }; 38 | 39 | __attribute__((used, section(".limine_requests"))) 40 | volatile limine_rsdp_request rsdp_request = { 41 | .id = LIMINE_RSDP_REQUEST, 42 | .revision = 0, 43 | .response = nullptr 44 | }; 45 | 46 | __attribute__((used, section(".limine_requests"))) 47 | volatile limine_executable_address_request keraddr_request = { 48 | .id = LIMINE_EXECUTABLE_ADDRESS_REQUEST, 49 | .revision = 0, 50 | .response = nullptr 51 | }; 52 | 53 | __attribute__((used, section(".limine_requests"))) 54 | volatile limine_module_request initrd_request = { 55 | .id = LIMINE_MODULE_REQUEST, 56 | .revision = 0, 57 | .response = nullptr 58 | }; 59 | 60 | __attribute__((used, section(".limine_requests"))) 61 | volatile LIMINE_MP(request) smp_request = { 62 | .id = LIMINE_MP_REQUEST, 63 | .revision = 0, 64 | .response = nullptr 65 | }; 66 | 67 | } 68 | 69 | namespace { 70 | 71 | __attribute__((used, section(".limine_requests_start"))) 72 | volatile LIMINE_REQUESTS_START_MARKER; 73 | 74 | __attribute__((used, section(".limine_requests_end"))) 75 | volatile LIMINE_REQUESTS_END_MARKER; 76 | 77 | } 78 | 79 | std::uint64_t BootloaderInfo::AccessRSDP() { 80 | return rsdp_request.response->address; 81 | } 82 | 83 | struct limine_framebuffer* BootloaderInfo::AccessFramebuffer() { 84 | return framebuffer_request.response->framebuffers[0]; 85 | } 86 | 87 | std::uint64_t BootloaderInfo::AccessHHDM() { 88 | return hhdm_request.response->offset; 89 | } 90 | 91 | struct limine_memmap_response* BootloaderInfo::AccessMemoryMap() { 92 | return memmap_request.response; 93 | } 94 | 95 | struct limine_executable_address_response* BootloaderInfo::AccessKernel() { 96 | return keraddr_request.response; 97 | } 98 | 99 | struct LIMINE_MP(response)* BootloaderInfo::AccessMP() { 100 | return smp_request.response; 101 | } 102 | 103 | struct limine_module_response* BootloaderInfo::AccessInitrd() { 104 | return initrd_request.response; 105 | } -------------------------------------------------------------------------------- /tools/toolchain-build.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | . pkg/pkg-lib.sh 4 | 5 | export CFLAGS="-fPIC" 6 | export CXXFLAGS="-fPIC" 7 | export CPPFLAGS="-fPIC" 8 | 9 | GNU_MIRROR=https://mirror.dogado.de/ 10 | CURRENT_DIR="$(realpath .)" 11 | 12 | rm -rf "$HOME/opt/cross/orange" 13 | 14 | rm -rf pack 15 | 16 | echo Downloading binutils and gcc 17 | 18 | mkdir -p pack 19 | 20 | mkdir -p $1/initrd/usr/include 21 | mkdir -p $1/initrd/usr/lib 22 | 23 | cd pack 24 | 25 | wget -nc $GNU_MIRROR/gnu/gcc/gcc-15.1.0/gcc-15.1.0.tar.gz 26 | wget -nc $GNU_MIRROR/gnu/binutils/binutils-2.38.tar.gz 27 | 28 | echo Unpacking binutils and gcc 29 | 30 | tar -xvf gcc-15.1.0.tar.gz 31 | tar -xvf binutils-2.38.tar.gz 32 | 33 | echo Patching binutils and gcc 34 | 35 | cd binutils-2.38 36 | patch -p1 <"$CURRENT_DIR/diffs/binutils.diff" 37 | cd ../gcc-15.1.0 38 | patch -p1 <"$CURRENT_DIR/diffs/gcc.diff" 39 | cd .. 40 | 41 | echo Downloading prerequisites 42 | cd gcc-15.1.0 43 | ./contrib/download_prerequisites 44 | cd .. 45 | 46 | echo Donwloading and installing automake and autoconf 47 | 48 | wget -nc $GNU_MIRROR/gnu/automake/automake-1.15.1.tar.gz 49 | wget -nc $GNU_MIRROR/gnu/autoconf/autoconf-2.69.tar.gz 50 | 51 | tar -xvf automake-1.15.1.tar.gz 52 | tar -xvf autoconf-2.69.tar.gz 53 | 54 | cd automake-1.15.1 55 | ./configure --prefix="$HOME/opt/cross/orange" 56 | make 57 | make install 58 | cd .. 59 | 60 | cd autoconf-2.69 61 | ./configure --prefix="$HOME/opt/cross/orange" 62 | make 63 | make install 64 | cd .. 65 | 66 | export PATH="$HOME/opt/cross/orange/bin:$PATH" 67 | 68 | cd binutils-2.38/ld 69 | automake 70 | cd ../../gcc-15.1.0/libstdc++-v3 71 | autoconf 72 | autotools_recursive_regen 73 | cd ../../ 74 | 75 | cd gcc-15.1.0 76 | cp -rf "$1/tools/pkg/config.sub" "$1/tools/pkg/config.guess" . 77 | cd .. 78 | 79 | cd binutils-2.38 80 | cp -rf "$1/tools/pkg/config.sub" "$1/tools/pkg/config.guess" . 81 | cd .. 82 | 83 | echo Building binutils and gcc 84 | 85 | mkdir -p binutils-build 86 | cd binutils-build 87 | mkdir -p $1/initrd 88 | ../binutils-2.38/configure --target=x86_64-orange-mlibc --prefix="$HOME/opt/cross/orange" --with-sysroot="$(realpath $1)/initrd" --enable-shared 89 | make -j$(nproc) 90 | make install -j$(nproc) 91 | 92 | export CFLAGS="-fPIC" 93 | export CXXFLAGS="-fPIC" 94 | 95 | cd .. 96 | mkdir -p gcc-build 97 | cd gcc-build 98 | 99 | ../gcc-15.1.0/configure --target=x86_64-orange-mlibc --prefix="$HOME/opt/cross/orange" --with-sysroot="$(realpath $1)/initrd" --enable-languages=c,c++,go --disable-nls --with-pic --enable-linker-build-id --enable-threads=posix --enable-default-pie --enable-default-ssp --disable-multilib --enable-initfini-array --enable-shared --enable-host-shared 100 | 101 | make all-gcc -j$(nproc) 102 | make all-target-libgcc -j$(nproc) 103 | make install-gcc -j$(nproc) 104 | make install-target-libgcc -j$(nproc) 105 | make all-target-libstdc++-v3 106 | make install-target-libstdc++-v3 107 | 108 | echo Done -------------------------------------------------------------------------------- /kernel/src/generic/vfs/ustar.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | inline int oct2bin(unsigned char *str, int size) { 14 | 15 | if(!str) 16 | return 0; 17 | 18 | std::uint64_t n = 0; 19 | volatile unsigned char *c = str; 20 | for(int i = 0;i < size;i++) { 21 | n *= 8; 22 | n += *c - '0'; 23 | c++; 24 | 25 | } 26 | return n; 27 | } 28 | 29 | 30 | void __ustar_fault(const char* msg) { 31 | 32 | Log::Display(LEVEL_MESSAGE_FAIL,"Can't continue kernel work ! initrd error, msg \"%s\"\n",msg); 33 | 34 | while(1) { 35 | asm volatile("hlt"); 36 | } 37 | } 38 | 39 | extern std::uint8_t __tmpfs__create_parent_dirs_by_default; 40 | 41 | void vfs::ustar::copy() { 42 | struct limine_module_response* initrd = BootloaderInfo::AccessInitrd(); 43 | if(!initrd || initrd->module_count < 1) 44 | __ustar_fault("there's no initrd"); 45 | 46 | ustar_header_t* current = (ustar_header_t*)initrd->modules[0]->address; 47 | std::uint64_t actual_tar_ptr_end = ((uint64_t)initrd->modules[0]->address + initrd->modules[0]->size) - 1024; 48 | while((std::uint64_t)current < actual_tar_ptr_end) { 49 | std::uint8_t type = oct2bin((uint8_t*)¤t->type,1); 50 | switch(type) { 51 | case 0: { 52 | char* file = (char*)((uint64_t)current->file_name + 1); 53 | vfs::vfs::create(file,VFS_TYPE_FILE); 54 | int size = oct2bin((uint8_t*)current->file_size,strlen(current->file_size)); 55 | 56 | userspace_fd_t fd; 57 | memset(&fd,0,sizeof(userspace_fd_t)); 58 | memcpy(fd.path,file,strlen(file)); 59 | 60 | vfs::vfs::write(&fd,(char*)((std::uint64_t)current + 512),size); 61 | vfs::vfs::var(&fd,(std::uint64_t)current->file_mode,TMPFS_VAR_CHMOD | (1 << 7)); 62 | break; 63 | } 64 | 65 | case 5: { 66 | char* file = (char*)((uint64_t)current->file_name + 1); 67 | vfs::vfs::create(file,VFS_TYPE_DIRECTORY); 68 | break; 69 | } 70 | 71 | case 2: { 72 | char* file = (char*)((uint64_t)current->file_name + 1); 73 | userspace_fd_t fd; 74 | memset(&fd,0,sizeof(userspace_fd_t)); 75 | memcpy(fd.path,file,strlen(file)); 76 | vfs::vfs::create(file,VFS_TYPE_SYMLINK); 77 | vfs::vfs::write(&fd,current->name_linked,strlen(current->name_linked)); 78 | break; 79 | } 80 | } 81 | current = (ustar_header_t*)((uint64_t)current + ALIGNUP(oct2bin((uint8_t*)¤t->file_size,strlen(current->file_size)),512) + 512); 82 | } 83 | 84 | __tmpfs__create_parent_dirs_by_default = 0; 85 | 86 | } -------------------------------------------------------------------------------- /kernel/src/generic/mm/heap.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | std::uint8_t* heap_pool; 18 | heap_block_t* heap_end; 19 | heap_block_t* current; 20 | 21 | locks::spinlock heap_lock; 22 | 23 | void memory::heap::init() { 24 | heap_pool = (std::uint8_t*)memory::pmm::_virtual::alloc(KHEAP_SIZE); 25 | heap_block_t* block = (heap_block_t*)heap_pool; 26 | block->size = KHEAP_SIZE; 27 | block->is_free = 1; 28 | block->next = 0; 29 | current = (heap_block_t*)heap_pool; 30 | heap_end = block; 31 | 32 | Log::Display(LEVEL_MESSAGE_OK,"heap_pool: 0x%p\n",heap_pool); 33 | memory::paging::alwaysmappedadd(Other::toPhys(heap_pool),KHEAP_SIZE); 34 | } 35 | 36 | void memory::heap::lock() { 37 | heap_lock.lock(); 38 | } 39 | 40 | void memory::heap::unlock() { 41 | heap_lock.unlock(); 42 | } 43 | 44 | void memory::heap::free(void* ptr) { 45 | if(ptr == 0) 46 | return; 47 | 48 | heap_lock.lock(); 49 | 50 | heap_block_t* block = (heap_block_t*)((std::uint64_t)ptr - sizeof(heap_block_t)); 51 | block->is_free = 1; 52 | if (block->next && block->next->is_free) { 53 | block->size += block->next->size; 54 | block->next = block->next->next; 55 | } 56 | 57 | heap_lock.unlock(); 58 | 59 | } 60 | 61 | void* memory::heap::malloc(std::uint32_t size) { 62 | 63 | heap_lock.lock(); 64 | 65 | size = (size + sizeof(heap_block_t) + 7) & ~7; 66 | 67 | if ((std::uint64_t)heap_end + size <= (std::uint64_t)heap_pool + KHEAP_SIZE) { 68 | heap_block_t* block = heap_end; 69 | block->size = size; 70 | block->is_free = 0; 71 | block->next = nullptr; 72 | 73 | heap_end = (heap_block_t*)((std::uint64_t)heap_end + size); 74 | 75 | heap_lock.unlock(); 76 | return (void*)((std::uint64_t)block + sizeof(heap_block_t)); 77 | } 78 | 79 | heap_block_t* start = current; 80 | do { 81 | if (current->is_free && current->size >= size) { 82 | if (current->size > size + sizeof(heap_block_t)) { 83 | heap_block_t* new_block = (heap_block_t*)((char*)current + size); 84 | new_block->size = current->size - size; 85 | new_block->is_free = 1; 86 | new_block->next = current->next; 87 | 88 | current->size = size; 89 | current->next = new_block; 90 | } 91 | 92 | current->is_free = 0; 93 | void* allocated = (void*)((char*)current + sizeof(heap_block_t)); 94 | current = current->next ? current->next : (heap_block_t*)heap_pool; 95 | heap_lock.unlock(); 96 | return allocated; 97 | } 98 | 99 | current = current->next ? current->next : (heap_block_t*)heap_pool; 100 | } while (current != start); 101 | 102 | heap_lock.unlock(); 103 | return 0; 104 | } 105 | -------------------------------------------------------------------------------- /tools/pkg/7/glib/pkg.sh: -------------------------------------------------------------------------------- 1 | 2 | . ../../pkg-lib.sh 3 | 4 | rm -rf pack 5 | 6 | mkdir -p pack 7 | 8 | cd pack 9 | 10 | fast_install "$1" https://github.com/libffi/libffi/releases/download/v3.5.2/libffi-3.5.2.tar.gz 11 | fast_install "$1" $GNU_MIRROR/gnu/libiconv/libiconv-1.18.tar.gz 12 | 13 | git clone https://github.com/PCRE2Project/pcre2.git --depth=1 14 | cd pcre2 15 | 16 | autotools_recursive_regen 17 | cd .. 18 | 19 | mkdir -p build2 20 | cd build2 21 | cmake ../pcre2 -DCMAKE_TOOLCHAIN_FILE=$(realpath ../../../../toolchain.cmake) -DCMAKE_INSTALL_PREFIX="/usr" 22 | 23 | cmake --build . -j$(nproc) 24 | DESTDIR="$1" cmake --install . 25 | 26 | cd .. 27 | 28 | wget https://github.com/GNOME/glib/archive/refs/tags/2.86.1.tar.gz 29 | mv 2.86.1.tar.gz glib2.tar.gz 30 | tar -xvf glib2.tar.gz 31 | 32 | cd glib-2.86.1 33 | 34 | cd subprojects 35 | rm -rf gvdb 36 | cd .. 37 | 38 | diff_patch ../../diff/glib.diff 39 | autotools_recursive_regen 40 | 41 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dglib_debug=disabled -Dsysprof=disabled -Dintrospection=disabled -Dxattr=false build 42 | 43 | cd build 44 | meson compile -j$(nproc) 45 | 46 | DESTDIR="$1" meson install --no-rebuild 47 | 48 | cd ../.. 49 | 50 | wget https://cairographics.org/releases/cairo-1.18.4.tar.xz 51 | tar -xvf cairo-1.18.4.tar.xz 52 | cd cairo-1.18.4 53 | 54 | mkdir -p build 55 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dxlib-xcb=enabled -Dzlib=enabled -Dtee=enabled -Dtests=disabled build 56 | 57 | cd build 58 | 59 | meson compile -j$(nproc) 60 | DESTDIR="$1" meson install --no-rebuild 61 | 62 | cd ../.. 63 | 64 | wget https://github.com/harfbuzz/harfbuzz/archive/refs/tags/5.0.0.tar.gz 65 | mv 5.0.0.tar.gz harfbuzz-5.0.0.tar.gz 66 | tar -xvf harfbuzz-5.0.0.tar.gz 67 | cd harfbuzz-5.0.0 68 | 69 | mkdir -p build 70 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dgraphite2=disabled -Dglib=enabled -Dgobject=disabled -Dicu=disabled -Dfreetype=enabled -Dcairo=enabled -Dintrospection=disabled -Dtests=disabled build 71 | 72 | cd build 73 | meson compile -j$(nproc) 74 | DESTDIR="$1" meson install --no-rebuild 75 | 76 | cd ../.. 77 | 78 | wget https://github.com/GNOME/pango/archive/refs/tags/1.49.2.tar.gz 79 | mv 1.49.2.tar.gz pango-1.49.2.tar.gz 80 | tar -xvf pango-1.49.2.tar.gz 81 | cd pango-1.49.2 82 | 83 | mkdir -p build 84 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dintrospection=disabled build 85 | 86 | cd build 87 | meson compile -j$(nproc) 88 | DESTDIR="$1" meson install --no-rebuild 89 | 90 | cd ../.. 91 | 92 | wget https://github.com/GNOME/gdk-pixbuf/archive/refs/tags/2.42.10.tar.gz 93 | mv 2.42.10.tar.gz gdk-pixbuf-2.42.10.tar.gz 94 | tar -xvf gdk-pixbuf-2.42.10.tar.gz 95 | cd gdk-pixbuf-2.42.10 96 | 97 | mkdir build 98 | meson --cross-file="$1/../tools/pkg/x86_64-orange.crossfile" --prefix=/usr -Dgio_sniffing=false -Dman=false build 99 | 100 | cd build 101 | 102 | meson compile -j$(nproc) 103 | DESTDIR="$1" meson install --no-rebuild 104 | 105 | cd ../.. 106 | 107 | # patch_config_sub "$(realpath $1/..)" 108 | 109 | # mkdir -p build0 110 | 111 | # 112 | 113 | # cd build0 114 | 115 | cd .. -------------------------------------------------------------------------------- /kernel/src/lib/Flanterm/src/flanterm.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2022-2025 mintsuki and contributors. 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions are met: 5 | * 6 | * 1. Redistributions of source code must retain the above copyright notice, 7 | * this list of conditions and the following disclaimer. 8 | * 9 | * 2. Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 17 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23 | * POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef FLANTERM_H 27 | #define FLANTERM_H 1 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #define FLANTERM_CB_DEC 10 38 | #define FLANTERM_CB_BELL 20 39 | #define FLANTERM_CB_PRIVATE_ID 30 40 | #define FLANTERM_CB_STATUS_REPORT 40 41 | #define FLANTERM_CB_POS_REPORT 50 42 | #define FLANTERM_CB_KBD_LEDS 60 43 | #define FLANTERM_CB_MODE 70 44 | #define FLANTERM_CB_LINUX 80 45 | 46 | #define FLANTERM_OOB_OUTPUT_OCRNL (1 << 0) 47 | #define FLANTERM_OOB_OUTPUT_OFDEL (1 << 1) 48 | #define FLANTERM_OOB_OUTPUT_OFILL (1 << 2) 49 | #define FLANTERM_OOB_OUTPUT_OLCUC (1 << 3) 50 | #define FLANTERM_OOB_OUTPUT_ONLCR (1 << 4) 51 | #define FLANTERM_OOB_OUTPUT_ONLRET (1 << 5) 52 | #define FLANTERM_OOB_OUTPUT_ONOCR (1 << 6) 53 | #define FLANTERM_OOB_OUTPUT_OPOST (1 << 7) 54 | 55 | #ifdef FLANTERM_IN_FLANTERM 56 | 57 | #include "flanterm_private.h" 58 | 59 | #else 60 | 61 | struct flanterm_context; 62 | 63 | #endif 64 | 65 | void flanterm_write(struct flanterm_context *ctx, const char *buf, size_t count); 66 | void flanterm_flush(struct flanterm_context *ctx); 67 | void flanterm_full_refresh(struct flanterm_context *ctx); 68 | void flanterm_deinit(struct flanterm_context *ctx, void (*_free)(void *ptr, size_t size)); 69 | 70 | void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols, size_t *rows); 71 | void flanterm_set_autoflush(struct flanterm_context *ctx, bool state); 72 | void flanterm_set_callback(struct flanterm_context *ctx, void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t)); 73 | uint64_t flanterm_get_oob_output(struct flanterm_context *ctx); 74 | void flanterm_set_oob_output(struct flanterm_context *ctx, uint64_t oob_output); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /kernel/include/etc/libc.hpp: -------------------------------------------------------------------------------- 1 | 2 | // simple libc basic memory implementations 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | inline void *memcpy(void *__restrict dest, const void *__restrict src, size_t n) { 11 | uint8_t *__restrict pdest = static_cast(dest); 12 | const uint8_t *__restrict psrc = static_cast(src); 13 | 14 | for (size_t i = 0; i < n; i++) { 15 | pdest[i] = psrc[i]; 16 | } 17 | 18 | return dest; 19 | } 20 | 21 | inline void *memset(void *s, int c, size_t n) { 22 | uint8_t *p = static_cast(s); 23 | 24 | for (size_t i = 0; i < n; i++) { 25 | p[i] = static_cast(c); 26 | } 27 | 28 | return s; 29 | } 30 | 31 | #define zeromem(x) memset(x,0,sizeof(*x)) 32 | 33 | inline void *memmove(void *dest, const void *src, size_t n) { 34 | uint8_t *pdest = static_cast(dest); 35 | const uint8_t *psrc = static_cast(src); 36 | 37 | if (src > dest) { 38 | for (size_t i = 0; i < n; i++) { 39 | pdest[i] = psrc[i]; 40 | } 41 | } else if (src < dest) { 42 | for (size_t i = n; i > 0; i--) { 43 | pdest[i-1] = psrc[i-1]; 44 | } 45 | } 46 | 47 | return dest; 48 | } 49 | 50 | inline int memcmp(const void *s1, const void *s2, size_t n) { 51 | const uint8_t *p1 = static_cast(s1); 52 | const uint8_t *p2 = static_cast(s2); 53 | 54 | for (size_t i = 0; i < n; i++) { 55 | if (p1[i] != p2[i]) { 56 | return p1[i] < p2[i] ? -1 : 1; 57 | } 58 | } 59 | 60 | return 0; 61 | } 62 | 63 | int strlen(const char* str); 64 | 65 | inline void* malloc(size_t size) { 66 | return memory::heap::malloc(size); 67 | } 68 | 69 | inline void free(void* p) { 70 | memory::heap::free(p); 71 | } 72 | 73 | inline int strcmp(const char *s1, const char *s2) { 74 | while (*s1 && (*s1 == *s2)) { 75 | s1++; 76 | s2++; 77 | } 78 | return (unsigned char)*s1 - (unsigned char)*s2; 79 | } 80 | 81 | inline int strncmp(const char *s1, const char *s2, size_t n) { 82 | size_t i = 0; 83 | while (i < n && s1[i] && (s1[i] == s2[i])) { 84 | i++; 85 | } 86 | if (i == n) return 0; 87 | return (unsigned char)s1[i] - (unsigned char)s2[i]; 88 | } 89 | 90 | inline char *strchr(const char *s, int c) { 91 | while (*s) { 92 | if (*s == (char)c) return (char *)s; 93 | s++; 94 | } 95 | return NULL; 96 | } 97 | 98 | char *strtok(char *str, const char *delim); 99 | 100 | inline char* strdup(const char *s) { 101 | size_t len = 0; 102 | while (s[len]) len++; 103 | 104 | char *copy = (char *)malloc(len + 1); 105 | if (!copy) return NULL; 106 | 107 | for (size_t i = 0; i <= len; i++) { 108 | copy[i] = s[i]; 109 | } 110 | return copy; 111 | } 112 | 113 | inline char* strrchr(const char* str, int ch) { 114 | char* last_occurrence = 0; 115 | 116 | while (*str) { 117 | if (*str == ch) { 118 | last_occurrence = (char*)str; 119 | } 120 | str++; 121 | } 122 | 123 | return last_occurrence; 124 | } -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/cpu/sse.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | std::uint64_t __sse_size = 0; 9 | char __sse_is_initializied = 0; 10 | char __sse_legacy_save = 0; 11 | 12 | std::uint64_t __sse_cr4_read() { 13 | uint64_t val; 14 | asm volatile("mov %%cr4, %0" : "=r"(val)); 15 | return val; 16 | } 17 | 18 | void __sse_cr4_write(std::uint64_t val) { 19 | asm volatile("mov %0, %%cr4" : : "r"(val) : "memory"); 20 | } 21 | 22 | std::uint64_t __sse_cr0_read() { 23 | uint64_t val; 24 | asm volatile("mov %%cr0, %0" : "=r"(val)); 25 | return val; 26 | } 27 | 28 | void __sse_cr0_write(std::uint64_t val) { 29 | asm volatile("mov %0, %%cr0" : : "r"(val) : "memory"); 30 | } 31 | 32 | 33 | void __sse_xsetbv(std::uint64_t val) { 34 | asm volatile("xsetbv" : : "a"(val), "d"(val >> 32),"c"(0) : "memory"); 35 | } 36 | 37 | std::uint64_t __sse_xgetbv() { 38 | uint32_t a,d; 39 | asm volatile("xgetbv" : "=a"(a),"=d"(d) : "c"(0) : "memory"); 40 | return ((std::uint64_t)d << 32) | a; 41 | } 42 | 43 | void __sse_xsave(void* buf) { 44 | std::uint64_t xcr0 = __sse_xgetbv(); 45 | asm volatile("xsave (%0)" :: "r"(buf), "a"(xcr0 & 0xFFFFFFFF), "d"(xcr0 >> 32), "c"(0): "memory"); 46 | } 47 | 48 | void __sse_xrstor(void* buf) { 49 | std::uint64_t xcr0 = __sse_xgetbv(); 50 | asm volatile("xrstor (%0)" :: "r"(buf), "a"(xcr0 & 0xFFFFFFFF), "d"(xcr0 >> 32), "c"(0): "memory"); 51 | } 52 | 53 | using namespace arch::x86_64::cpu; 54 | 55 | void sse::init() { 56 | uint32_t a,b,c,d; 57 | __cpuid(1,0,&a,&b,&c,&d); 58 | if(!__sse_is_initializied) { 59 | if(c & SSE_XSAVE_SUPPORT) { 60 | __cpuid(13,0,&a,&b,&c,&d); 61 | __sse_legacy_save = 0; 62 | __sse_size = c; 63 | } else { 64 | __sse_legacy_save = 1; 65 | __sse_size = 512; 66 | } 67 | __sse_is_initializied = 1; 68 | } 69 | std::uint64_t cr4 = __sse_cr4_read(); 70 | 71 | cr4 |= DEFAULT_SSE_FLAGS; 72 | 73 | std::uint64_t cr0 = __sse_cr0_read(); 74 | 75 | cr0 &= ~(1 << 2); 76 | cr0 |= (1 << 1); 77 | 78 | __sse_cr0_write(cr0); 79 | 80 | std::uint64_t sse_control = 0; 81 | 82 | __sse_cr4_write(cr4); 83 | 84 | __cpuid(1,0,&a,&b,&c,&d); 85 | if(c & SSE_XSAVE_SUPPORT) 86 | cr4 |= SSE_XSAVE_CR4; 87 | else 88 | return; 89 | 90 | __sse_cr4_write(cr4); 91 | 92 | __cpuid(13,0,&a,&b,&c,&d); 93 | 94 | sse_control |= SSE_CONTROL_DEFAULT; 95 | SSE_CHECK_AND_SET((1 << 2)); 96 | SSE_CHECK_AND_SET((1 << 9)); 97 | SSE_CHECK_AND_SET((0b11 < 3)); 98 | SSE_CHECK_AND_SET((0b11 < 17)) 99 | SSE_CHECK_AND_SET((0b111 < 5)); 100 | 101 | __sse_xsetbv(sse_control); 102 | } 103 | 104 | std::uint64_t sse::size() { 105 | return __sse_size; 106 | } 107 | 108 | void sse::save(std::uint8_t* buf) { 109 | if(__sse_legacy_save) 110 | asm volatile("fxsave (%0)" : : "r"(buf)); 111 | else 112 | __sse_xsave(buf); 113 | } 114 | 115 | void sse::load(std::uint8_t* buf) { 116 | if(__sse_legacy_save) 117 | asm volatile("fxrstor (%0)" : : "r"(buf)); 118 | else 119 | __sse_xrstor(buf); 120 | } -------------------------------------------------------------------------------- /tools/pkg/6/terms/pkg.sh: -------------------------------------------------------------------------------- 1 | . ../../pkg-lib.sh 2 | 3 | rm -rf pack 4 | mkdir -p pack 5 | 6 | cd pack 7 | 8 | git clone https://github.com/Shourai/st.git 9 | cd st 10 | 11 | mkdir build 12 | 13 | CC=x86_64-orange-mlibc-gcc CXX=x86_64-orange-mlibc-g++ CPP=x86_64-orange-mlibc-g++ LD=x86_64-orange-mlibc-ld PKGCONFIG=x86_64-orange-mlibc-pkg-config PKG_CONFIG=x86_64-orange-mlibc-pkg-config make -j$(nproc) CFLAGS="-Wno-implicit-function-declaration -fPIC" 14 | CC=x86_64-orange-mlibc-gcc CXX=x86_64-orange-mlibc-g++ CPP=x86_64-orange-mlibc-g++ LD=x86_64-orange-mlibc-ld PKGCONFIG=x86_64-orange-mlibc-pkg-config PKG_CONFIG=x86_64-orange-mlibc-pkg-config make install DESTDIR="$(realpath build)" 15 | 16 | cp -rf build/usr/local/* "$1/usr/" 17 | 18 | cd .. 19 | 20 | fast_install "$1" https://invisible-mirror.net/archives/xterm/xterm-390.tgz "--disable-tcap-fkeys --disable-tcap-query --enable-256-color" "../../diff/xterm.diff" 21 | fast_install "$1" https://www.x.org/archive/individual/lib/libXrandr-1.5.3.tar.gz 22 | fast_install "$1" https://www.x.org/archive/individual/app/xev-1.2.5.tar.gz 23 | 24 | #fuck xv 25 | 26 | # wget https://xv.trilon.com/dist/xv-3.10a.tar.gz 27 | # tar -xvf xv-3.10a.tar.gz 28 | # cd xv-3.10a 29 | 30 | # diff_patch ../../diff/xv.diff 31 | 32 | # CC=x86_64-orange-mlibc-gcc CXX=x86_64-orange-mlibc-g++ CPP=x86_64-orange-mlibc-g++ LD=x86_64-orange-mlibc-ld PKGCONFIG=x86_64-orange-mlibc-pkg-config PKG_CONFIG=x86_64-orange-mlibc-pkg-config make -j$(nproc) CFLAGS="-Wno-implicit-function-declaration -fPIC -DHAVE_STDLIB_H -Wno-implicit-int -Wno-implicit-function-declaration" 33 | # echo installing xv 34 | # CC=x86_64-orange-mlibc-gcc CXX=x86_64-orange-mlibc-g++ CPP=x86_64-orange-mlibc-g++ LD=x86_64-orange-mlibc-ld PKGCONFIG=x86_64-orange-mlibc-pkg-config PKG_CONFIG=x86_64-orange-mlibc-pkg-config make install DESTDIR="$(realpath build)" 35 | 36 | # cd .. 37 | 38 | # wget http://deb.debian.org/debian/pool/main/x/xloadimage/xloadimage_4.1.orig.tar.gz 39 | # tar -xvf xloadimage_4.1.orig.tar.gz 40 | 41 | # cd xloadimage.4.1 42 | 43 | # autotools_recursive_regen 44 | # diff_patch ../../diff/xloadimage.diff 45 | 46 | # CC=x86_64-orange-mlibc-gcc CXX=x86_64-orange-mlibc-g++ CPP=x86_64-orange-mlibc-g++ LD=x86_64-orange-mlibc-ld PKGCONFIG=x86_64-orange-mlibc-pkg-config PKG_CONFIG=x86_64-orange-mlibc-pkg-config make -j$(nproc) 47 | # CC=x86_64-orange-mlibc-gcc CXX=x86_64-orange-mlibc-g++ CPP=x86_64-orange-mlibc-g++ LD=x86_64-orange-mlibc-ld PKGCONFIG=x86_64-orange-mlibc-pkg-config PKG_CONFIG=x86_64-orange-mlibc-pkg-config make install DESTDIR="$1" SYSPATHFILE="$1/usr/lib/X11/Xloadimage" INSTALLDIR="$1/usr/bin" 48 | 49 | 50 | # cd .. 51 | 52 | git clone https://github.com/libjpeg-turbo/libjpeg-turbo.git --depth=1 53 | cd libjpeg-turbo 54 | 55 | autotools_recursive_regen 56 | 57 | cd .. 58 | 59 | mkdir -p libjpeg-build 60 | cd libjpeg-build 61 | 62 | 63 | CFLAGS="-fPIC -Wno-implicit-function-declaration -O2" cmake ../libjpeg-turbo -DBUILD_SHARED_LIBS=OFF -DCMAKE_TOOLCHAIN_FILE=$(realpath ../../../../toolchain.cmake) -DCMAKE_INSTALL_PREFIX="$1/usr" 64 | 65 | make -j$(nproc) 66 | make install 67 | 68 | rm -rf "$1/lib/libjpeg.so" 69 | 70 | cd .. 71 | 72 | git clone https://github.com/stoeckmann/xwallpaper.git 73 | 74 | cd xwallpaper 75 | 76 | ./autogen.sh 77 | autotools_recursive_regen 78 | ./configure --host=x86_64-orange-mlibc --prefix="/usr" 79 | make -j$(nproc) 80 | make install DESTDIR="$1" 81 | 82 | cd .. -------------------------------------------------------------------------------- /kernel/include/arch/x86_64/interrupts/pic.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #pragma once 9 | 10 | #define PIC1 0x20 11 | #define PIC2 0xA0 12 | #define PIC1_COMMAND PIC1 13 | #define PIC1_DATA (PIC1+1) 14 | #define PIC2_COMMAND PIC2 15 | #define PIC2_DATA (PIC2+1) 16 | #define ICW1_ICW4 0x01 17 | #define ICW1_SINGLE 0x02 18 | #define ICW1_INTERVAL4 0x04 19 | #define ICW1_LEVEL 0x08 20 | #define ICW1_INIT 0x10 21 | 22 | #define ICW4_8086 0x01 23 | #define ICW4_AUTO 0x02 24 | #define ICW4_BUF_SLAVE 0x08 25 | #define ICW4_BUF_MASTER 0x0C 26 | #define ICW4_SFNM 0x10 27 | 28 | #define CASCADE_IRQ 2 29 | 30 | namespace arch { 31 | namespace x86_64 { 32 | namespace interrupts { 33 | class pic { 34 | public: 35 | static inline void eoi(std::uint8_t irq) { 36 | drivers::io io; 37 | if(irq >= 8) 38 | io.outb(PIC2_COMMAND,0x20); 39 | io.outb(PIC1_COMMAND,0x20); 40 | 41 | } 42 | 43 | static inline void disable() { 44 | drivers::io io; 45 | io.outb(PIC1_DATA, 0xff); 46 | io.outb(PIC2_DATA, 0xff); 47 | arch::x86_64::interrupts::irq::reset(); 48 | } 49 | 50 | static inline void init() { 51 | drivers::io io; 52 | io.outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); 53 | io.wait(); 54 | io.outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4); 55 | io.wait(); 56 | io.outb(PIC1_DATA, 0x20); 57 | io.wait(); 58 | io.outb(PIC2_DATA, 0x28); 59 | io.wait(); 60 | io.outb(PIC1_DATA, 1 << CASCADE_IRQ); 61 | io.wait(); 62 | io.outb(PIC2_DATA, 2); 63 | io.wait(); 64 | 65 | io.outb(PIC1_DATA, ICW4_8086); 66 | io.wait(); 67 | io.outb(PIC2_DATA, ICW4_8086); 68 | io.wait(); 69 | 70 | io.outb(PIC1_DATA, 0); 71 | io.outb(PIC2_DATA, 0); 72 | } 73 | 74 | static inline void mask(std::uint8_t irq) { 75 | drivers::io io; 76 | std::uint16_t port; 77 | std::uint8_t value; 78 | 79 | if(irq < 8) { 80 | port = PIC1_DATA; 81 | } else { 82 | port = PIC2_DATA; 83 | irq -= 8; 84 | } 85 | value = io.inb(port) | (1 << irq); 86 | io.outb(port, value); 87 | } 88 | 89 | static inline void clear(std::uint8_t irq) { 90 | drivers::io io; 91 | std::uint16_t port; 92 | std::uint8_t value; 93 | 94 | if(irq < 8) { 95 | port = PIC1_DATA; 96 | } else { 97 | port = PIC2_DATA; 98 | irq -= 8; 99 | } 100 | value = io.inb(port) & ~(1 << irq); 101 | io.outb(port, value); 102 | } 103 | 104 | }; 105 | }; 106 | }; 107 | }; -------------------------------------------------------------------------------- /tools/pkg/3/pthread_test/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define SOCKET_PATH "/tmp/test_unix_socket" 13 | #define THREADS 10 14 | 15 | void* client_thread(void* arg) { 16 | (void)arg; 17 | int sock = socket(AF_UNIX, SOCK_STREAM, 0); 18 | if (sock < 0) { 19 | perror("client socket"); 20 | return NULL; 21 | } 22 | 23 | struct sockaddr_un serv_addr; 24 | memset(&serv_addr, 0, sizeof(serv_addr)); 25 | serv_addr.sun_family = AF_UNIX; 26 | strncpy(serv_addr.sun_path, SOCKET_PATH, sizeof(serv_addr.sun_path) - 1); 27 | 28 | while (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { 29 | usleep(100000); 30 | } 31 | 32 | int one = 1; 33 | while (1) { 34 | ssize_t n = write(sock, &one, sizeof(one)); 35 | if (n != sizeof(one)) { 36 | perror("client write"); 37 | break; 38 | } 39 | 40 | } 41 | 42 | close(sock); 43 | return NULL; 44 | } 45 | 46 | int main() { 47 | 48 | unlink(SOCKET_PATH); 49 | 50 | int listen_fd = socket(AF_UNIX, SOCK_STREAM, 0); 51 | if (listen_fd < 0) { 52 | perror("socket"); 53 | exit(1); 54 | } 55 | 56 | struct sockaddr_un addr; 57 | memset(&addr, 0, sizeof(addr)); 58 | addr.sun_family = AF_UNIX; 59 | strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path) - 1); 60 | 61 | if (bind(listen_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { 62 | perror("bind"); 63 | exit(1); 64 | } 65 | 66 | if (listen(listen_fd, THREADS) < 0) { 67 | perror("listen"); 68 | exit(1); 69 | } 70 | 71 | pthread_t clients[THREADS]; 72 | for (int i = 0; i < THREADS; i++) { 73 | if (pthread_create(&clients[i], NULL, client_thread, NULL) != 0) { 74 | perror("pthread_create"); 75 | exit(1); 76 | } 77 | } 78 | 79 | int client_fds[THREADS]; 80 | for (int i = 0; i < THREADS; i++) { 81 | client_fds[i] = accept(listen_fd, NULL, NULL); 82 | if (client_fds[i] < 0) { 83 | perror("accept"); 84 | exit(1); 85 | } 86 | printf("Accepted client %d\n", i); 87 | } 88 | 89 | struct pollfd pfds[THREADS]; 90 | for (int i = 0; i < THREADS; i++) { 91 | pfds[i].fd = client_fds[i]; 92 | pfds[i].events = POLLIN; 93 | } 94 | 95 | while (1) { 96 | int ret = poll(pfds, THREADS, -1); 97 | if (ret < 0) { 98 | perror("poll"); 99 | break; 100 | } 101 | 102 | for (int i = 0; i < THREADS; i++) { 103 | if (pfds[i].revents & POLLIN) { 104 | int val; 105 | ssize_t n = read(pfds[i].fd, &val, sizeof(val)); 106 | if (n == 0) { 107 | printf("Client %d disconnected\n", i); 108 | close(pfds[i].fd); 109 | pfds[i].fd = -1; 110 | } else if (n == sizeof(val)) { 111 | if (val != 1) { 112 | printf("bug got %d from client %d\n", val, i); 113 | } else { 114 | printf("good value from client %d\n",i); 115 | } 116 | } else { 117 | perror("read"); 118 | } 119 | } 120 | } 121 | } 122 | 123 | for (int i = 0; i < THREADS; i++) { 124 | if (pfds[i].fd != -1) 125 | close(pfds[i].fd); 126 | } 127 | close(listen_fd); 128 | unlink(SOCKET_PATH); 129 | 130 | return 0; 131 | } 132 | -------------------------------------------------------------------------------- /kernel/src/lib/Flanterm/src/flanterm_backends/fb_private.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2022-2025 mintsuki and contributors. 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions are met: 5 | * 6 | * 1. Redistributions of source code must retain the above copyright notice, 7 | * this list of conditions and the following disclaimer. 8 | * 9 | * 2. Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the documentation 11 | * and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 17 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23 | * POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef FLANTERM_FB_PRIVATE_H 27 | #define FLANTERM_FB_PRIVATE_H 1 28 | 29 | #ifndef FLANTERM_IN_FLANTERM 30 | #error "Do not use fb_private.h. Use interfaces defined in fb.h only." 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #define FLANTERM_FB_FONT_GLYPHS 256 42 | 43 | struct flanterm_fb_char { 44 | uint32_t c; 45 | uint32_t fg; 46 | uint32_t bg; 47 | }; 48 | 49 | struct flanterm_fb_queue_item { 50 | size_t x, y; 51 | struct flanterm_fb_char c; 52 | }; 53 | 54 | struct flanterm_fb_context { 55 | struct flanterm_context term; 56 | 57 | void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c, size_t x, size_t y); 58 | 59 | size_t font_width; 60 | size_t font_height; 61 | size_t glyph_width; 62 | size_t glyph_height; 63 | 64 | size_t font_scale_x; 65 | size_t font_scale_y; 66 | 67 | size_t offset_x, offset_y; 68 | 69 | volatile uint32_t *framebuffer; 70 | size_t pitch; 71 | size_t width; 72 | size_t height; 73 | size_t bpp; 74 | 75 | uint8_t red_mask_size, red_mask_shift; 76 | uint8_t green_mask_size, green_mask_shift; 77 | uint8_t blue_mask_size, blue_mask_shift; 78 | 79 | size_t font_bits_size; 80 | uint8_t *font_bits; 81 | size_t font_bool_size; 82 | bool *font_bool; 83 | 84 | uint32_t ansi_colours[8]; 85 | uint32_t ansi_bright_colours[8]; 86 | uint32_t default_fg, default_bg; 87 | uint32_t default_fg_bright, default_bg_bright; 88 | 89 | size_t canvas_size; 90 | uint32_t *canvas; 91 | 92 | size_t grid_size; 93 | size_t queue_size; 94 | size_t map_size; 95 | 96 | struct flanterm_fb_char *grid; 97 | 98 | struct flanterm_fb_queue_item *queue; 99 | size_t queue_i; 100 | 101 | struct flanterm_fb_queue_item **map; 102 | 103 | uint32_t text_fg; 104 | uint32_t text_bg; 105 | size_t cursor_x; 106 | size_t cursor_y; 107 | 108 | uint32_t saved_state_text_fg; 109 | uint32_t saved_state_text_bg; 110 | size_t saved_state_cursor_x; 111 | size_t saved_state_cursor_y; 112 | 113 | size_t old_cursor_x; 114 | size_t old_cursor_y; 115 | }; 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | # Nuke built-in rules and variables. 2 | MAKEFLAGS += -rR 3 | .SUFFIXES: 4 | 5 | # Default user QEMU flags. These are appended to the QEMU command calls. 6 | QEMUFLAGS := -m 4G -d int -no-reboot -s -M q35 -smp 2 -enable-kvm -serial stdio -device qemu-xhci -device usb-kbd -device usb-mouse -cpu host,+invtsc 7 | 8 | override IMAGE_NAME := orange 9 | 10 | # Toolchain for building the 'limine' executable for the host. 11 | HOST_CC := cc 12 | HOST_CFLAGS := -g -O2 -pipe 13 | HOST_CPPFLAGS := 14 | HOST_LDFLAGS := 15 | HOST_LIBS := 16 | 17 | .PHONY: all 18 | all: $(IMAGE_NAME).iso 19 | 20 | .PHONY: all-hdd 21 | all-hdd: $(IMAGE_NAME).hdd 22 | 23 | .PHONY: run 24 | run: $(IMAGE_NAME).iso 25 | qemu-system-x86_64 \ 26 | -M q35 \ 27 | -cdrom $(IMAGE_NAME).iso \ 28 | -boot d \ 29 | $(QEMUFLAGS) 30 | 31 | .PHONY: run-uefi 32 | run-uefi: ovmf/ovmf-code-x86_64.fd $(IMAGE_NAME).iso 33 | qemu-system-x86_64 \ 34 | -M q35 \ 35 | -drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-x86_64.fd,readonly=on \ 36 | -cdrom $(IMAGE_NAME).iso \ 37 | -boot d \ 38 | $(QEMUFLAGS) 39 | 40 | .PHONY: run-hdd 41 | run-hdd: $(IMAGE_NAME).hdd 42 | qemu-system-x86_64 \ 43 | -M q35 \ 44 | -hda $(IMAGE_NAME).hdd \ 45 | $(QEMUFLAGS) 46 | 47 | .PHONY: run-hdd-uefi 48 | run-hdd-uefi: ovmf/ovmf-code-x86_64.fd $(IMAGE_NAME).hdd 49 | qemu-system-x86_64 \ 50 | -M q35 \ 51 | -drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-x86_64.fd,readonly=on \ 52 | -hda $(IMAGE_NAME).hdd \ 53 | $(QEMUFLAGS) 54 | 55 | ovmf/ovmf-code-x86_64.fd: 56 | mkdir -p ovmf 57 | curl -Lo $@ https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-code-x86_64.fd 58 | 59 | limine/limine: 60 | rm -rf limine 61 | git clone https://github.com/limine-bootloader/limine.git --branch=v9.x-binary --depth=1 62 | $(MAKE) -C limine \ 63 | CC="$(HOST_CC)" \ 64 | CFLAGS="$(HOST_CFLAGS)" \ 65 | CPPFLAGS="$(HOST_CPPFLAGS)" \ 66 | LDFLAGS="$(HOST_LDFLAGS)" \ 67 | LIBS="$(HOST_LIBS)" 68 | 69 | kernel-deps: 70 | ./kernel/get-deps . 71 | 72 | .PHONY: kernel 73 | kernel: kernel-deps 74 | rm -rf kernel/src/lib/uACPI/tests 75 | $(MAKE) -C kernel 76 | 77 | $(IMAGE_NAME).iso: limine/limine kernel 78 | rm -rf iso_root 79 | mkdir -p iso_root/boot 80 | cp -rf tools/base/* iso_root 81 | cp -v kernel/bin/kernel iso_root/boot/ 82 | mkdir -p iso_root/boot/limine 83 | cp -v tools/limine.conf limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/boot/limine/ 84 | mkdir -p iso_root/EFI/BOOT 85 | cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/ 86 | cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT/ 87 | xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \ 88 | -no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \ 89 | -apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \ 90 | -efi-boot-part --efi-boot-image --protective-msdos-label \ 91 | iso_root -o $(IMAGE_NAME).iso 92 | ./limine/limine bios-install $(IMAGE_NAME).iso 93 | rm -rf iso_root 94 | 95 | $(IMAGE_NAME).hdd: limine/limine kernel 96 | rm -f $(IMAGE_NAME).hdd 97 | dd if=/dev/zero bs=1M count=0 seek=64 of=$(IMAGE_NAME).hdd 98 | PATH=$$PATH:/usr/sbin:/sbin sgdisk $(IMAGE_NAME).hdd -n 1:2048 -t 1:ef00 -m 1 99 | ./limine/limine bios-install $(IMAGE_NAME).hdd 100 | mformat -i $(IMAGE_NAME).hdd@@1M 101 | mmd -i $(IMAGE_NAME).hdd@@1M ::/EFI ::/EFI/BOOT ::/boot ::/boot/limine 102 | mcopy -i $(IMAGE_NAME).hdd@@1M kernel/bin/kernel ::/boot 103 | mcopy -i $(IMAGE_NAME).hdd@@1M limine.conf limine/limine-bios.sys ::/boot/limine 104 | mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTX64.EFI ::/EFI/BOOT 105 | mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTIA32.EFI ::/EFI/BOOT 106 | 107 | .PHONY: clean 108 | clean: 109 | $(MAKE) -C kernel clean 110 | rm -rf iso_root $(IMAGE_NAME).iso $(IMAGE_NAME).hdd 111 | 112 | .PHONY: distclean 113 | distclean: clean 114 | $(MAKE) -C kernel distclean 115 | rm -rf kernel-deps limine ovmf 116 | -------------------------------------------------------------------------------- /kernel/src/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | std::uint16_t KERNEL_GOOD_TIMER = HPET_TIMER; 32 | 33 | static uacpi_interrupt_ret handle_power_button(uacpi_handle ctx) { 34 | Log::Display(LEVEL_MESSAGE_OK,"Got uacpi power_button !\n"); 35 | return UACPI_INTERRUPT_HANDLED; 36 | } 37 | 38 | extern "C" void main() { 39 | 40 | Other::ConstructorsInit(); 41 | asm volatile("cli"); 42 | 43 | drivers::serial serial(DEFAULT_SERIAL_PORT); 44 | Log::Init(); 45 | 46 | __wrmsr(0xC0000101,0); 47 | 48 | memory::pmm::_physical::init(); 49 | Log::Display(LEVEL_MESSAGE_OK,"PMM Initializied\n"); 50 | 51 | memory::heap::init(); 52 | Log::Display(LEVEL_MESSAGE_OK,"Heap initializied\n"); 53 | 54 | memory::paging::init(); 55 | Log::Display(LEVEL_MESSAGE_OK,"Paging initializied\n"); 56 | 57 | arch::x86_64::cpu::gdt::init(); 58 | Log::Display(LEVEL_MESSAGE_OK,"GDT initializied\n"); 59 | 60 | arch::x86_64::interrupts::idt::init(); 61 | Log::Display(LEVEL_MESSAGE_OK,"IDT initializied\n"); 62 | 63 | arch::x86_64::interrupts::pic::init(); 64 | Log::Display(LEVEL_MESSAGE_OK,"PIC initializied\n"); 65 | 66 | drivers::kvmclock::init(); 67 | drivers::acpi::init(); 68 | Log::Display(LEVEL_MESSAGE_OK,"ACPI initializied\n"); 69 | 70 | vfs::vfs::init(); 71 | Log::Display(LEVEL_MESSAGE_OK,"VFS initializied\n"); 72 | 73 | Log::Display(LEVEL_MESSAGE_INFO,"Loading initrd\n"); 74 | vfs::ustar::copy(); 75 | Log::Display(LEVEL_MESSAGE_OK,"USTAR parsed\n"); 76 | 77 | arch::x86_64::cpu::sse::init(); 78 | Log::Display(LEVEL_MESSAGE_OK,"SSE initializied\n"); 79 | 80 | arch::x86_64::cpu::mp::init(); 81 | arch::x86_64::cpu::mp::sync(0); 82 | Log::Display(LEVEL_MESSAGE_OK,"SMP initializied\n"); 83 | 84 | arch::x86_64::scheduling::init(); 85 | Log::Display(LEVEL_MESSAGE_OK,"Scheduling initializied\n"); 86 | 87 | arch::x86_64::syscall::init(); 88 | Log::Display(LEVEL_MESSAGE_OK,"Syscalls initializied\n"); 89 | 90 | sockets::init(); 91 | Log::Display(LEVEL_MESSAGE_OK,"Sockets initializied\n"); 92 | 93 | uacpi_status ret = uacpi_install_fixed_event_handler( 94 | UACPI_FIXED_EVENT_POWER_BUTTON, 95 | handle_power_button, UACPI_NULL 96 | ); 97 | 98 | char* argv[] = {0}; 99 | char* envp[] = {"TERM=linux",0}; 100 | 101 | Log::Display(LEVEL_MESSAGE_INFO,"Trying to sync cpus...\n"); 102 | arch::x86_64::cpu::mp::sync(1); 103 | 104 | drivers::tsc::sleep(50000); 105 | 106 | arch::x86_64::process_t* init = arch::x86_64::scheduling::create(); 107 | arch::x86_64::scheduling::loadelf(init,"/usr/bin/init",argv,envp,0); 108 | arch::x86_64::scheduling::wakeup(init); 109 | 110 | extern locks::spinlock* vfs_lock; 111 | extern locks::spinlock pmm_lock; 112 | 113 | Log::Display(LEVEL_MESSAGE_FAIL,"\e[1;1H\e[2J"); 114 | arch::x86_64::cpu::lapic::tick(arch::x86_64::cpu::data()->lapic_block); 115 | 116 | dmesg("Now we are in userspace..."); 117 | 118 | asm volatile("sti"); 119 | while(1) { 120 | 121 | asm volatile("hlt"); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /tools/diffs/binutils.diff: -------------------------------------------------------------------------------- 1 | diff -Naur binutils-2.38/bfd/config.bfd binutils-patched/bfd/config.bfd 2 | --- binutils-2.38/bfd/config.bfd 2022-01-22 15:14:07.000000000 +0300 3 | +++ binutils-patched/bfd/config.bfd 2025-05-20 13:53:59.007878617 +0300 4 | @@ -656,11 +656,21 @@ 5 | targ_selvecs= 6 | targ64_selvecs=x86_64_elf64_vec 7 | ;; 8 | + i[3-7]86-*-orange*) 9 | + targ_defvec=i386_elf32_vec 10 | + targ_selvecs= 11 | + targ64_selvecs=x86_64_elf64_vec 12 | + ;; 13 | #ifdef BFD64 14 | x86_64-*-cloudabi*) 15 | targ_defvec=x86_64_elf64_cloudabi_vec 16 | want64=true 17 | ;; 18 | + x86_64-*-orange*) 19 | + targ_defvec=x86_64_elf64_vec 20 | + targ_selvecs=i386_elf32_vec 21 | + want64=true 22 | + ;; 23 | x86_64-*-darwin*) 24 | targ_defvec=x86_64_mach_o_vec 25 | targ_selvecs="i386_mach_o_vec mach_o_le_vec mach_o_be_vec mach_o_fat_vec pef_vec pef_xlib_vec sym_vec" 26 | diff -Naur binutils-2.38/config.sub binutils-patched/config.sub 27 | --- binutils-2.38/config.sub 2022-01-22 15:14:07.000000000 +0300 28 | +++ binutils-patched/config.sub 2025-05-20 13:51:16.721951465 +0300 29 | @@ -1750,7 +1750,7 @@ 30 | | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ 31 | | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ 32 | | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ 33 | - | skyos* | haiku* | rdos* | toppers* | drops* | es* \ 34 | + | skyos* | orange* | haiku* | rdos* | toppers* | drops* | es* \ 35 | | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ 36 | | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ 37 | | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ 38 | diff -Naur binutils-2.38/gas/configure.tgt binutils-patched/gas/configure.tgt 39 | --- binutils-2.38/gas/configure.tgt 2022-01-22 15:14:08.000000000 +0300 40 | +++ binutils-patched/gas/configure.tgt 2025-05-20 13:55:11.117623594 +0300 41 | @@ -233,6 +233,7 @@ 42 | i386-*-knetbsd*-gnu | \ 43 | i386-*-netbsd* | \ 44 | i386-*-openbsd*) fmt=elf em=nbsd ;; 45 | + i386-*-orange*) fmt=elf em=gnu ;; 46 | i386-*-linux-*) fmt=elf em=linux 47 | case ${cpu}-${os} in 48 | x86_64*-linux-gnux32) arch=x86_64:32 ;; 49 | diff -Naur binutils-2.38/ld/configure.tgt binutils-patched/ld/configure.tgt 50 | --- binutils-2.38/ld/configure.tgt 2022-01-22 17:19:36.000000000 +0300 51 | +++ binutils-patched/ld/configure.tgt 2025-05-20 13:58:35.200562165 +0300 52 | @@ -403,6 +403,15 @@ 53 | ;; 54 | i[3-7]86-*-haiku*) targ_emul=elf_i386_haiku 55 | ;; 56 | +i[3-7]86-*-orange*) 57 | + targ_emul=elf_i386_orange 58 | + targ_extra_emuls=elf_i386 59 | + targ64_extra_emuls="elf_x86_64_orange elf_x86_64" 60 | + ;; 61 | +x86_64-*-orange*) 62 | + targ_emul=elf_x86_64_orange 63 | + targ_extra_emuls="elf_i386_orange elf_x86_64 elf_i386" 64 | + ;; 65 | i[3-7]86-*-vxworks*) targ_emul=elf_i386_vxworks 66 | ;; 67 | i[3-7]86-*-chaos) targ_emul=elf_i386_chaos 68 | diff -Naur binutils-2.38/ld/emulparams/elf_i386_orange.sh binutils-patched/ld/emulparams/elf_i386_orange.sh 69 | --- binutils-2.38/ld/emulparams/elf_i386_orange.sh 1970-01-01 03:00:00.000000000 +0300 70 | +++ binutils-patched/ld/emulparams/elf_i386_orange.sh 2025-05-20 13:58:57.848110210 +0300 71 | @@ -0,0 +1,2 @@ 72 | +source_sh ${srcdir}/emulparams/elf_i386.sh 73 | +TEXT_START_ADDR=0x08000000 74 | diff -Naur binutils-2.38/ld/emulparams/elf_x86_64_orange.sh binutils-patched/ld/emulparams/elf_x86_64_orange.sh 75 | --- binutils-2.38/ld/emulparams/elf_x86_64_orange.sh 1970-01-01 03:00:00.000000000 +0300 76 | +++ binutils-patched/ld/emulparams/elf_x86_64_orange.sh 2025-05-20 13:59:14.619516061 +0300 77 | @@ -0,0 +1 @@ 78 | +source_sh ${srcdir}/emulparams/elf_x86_64.sh 79 | diff -Naur binutils-2.38/ld/Makefile.am binutils-patched/ld/Makefile.am 80 | --- binutils-2.38/ld/Makefile.am 2022-01-22 15:14:09.000000000 +0300 81 | +++ binutils-patched/ld/Makefile.am 2025-05-20 14:00:18.033050595 +0300 82 | @@ -281,6 +281,7 @@ 83 | eelf_i386_be.c \ 84 | eelf_i386_fbsd.c \ 85 | eelf_i386_haiku.c \ 86 | + eelf_i386_orange.c \ 87 | eelf_i386_ldso.c \ 88 | eelf_i386_sol2.c \ 89 | eelf_i386_vxworks.c \ 90 | @@ -463,6 +464,7 @@ 91 | eelf_x86_64_cloudabi.c \ 92 | eelf_x86_64_fbsd.c \ 93 | eelf_x86_64_haiku.c \ 94 | + eelf_x86_64_orange.c \ 95 | eelf_x86_64_sol2.c \ 96 | ehppa64linux.c \ 97 | ei386pep.c \ 98 | -------------------------------------------------------------------------------- /kernel/include/etc/errno.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define EPERM 1 5 | #define ENOENT 2 6 | #define ESRCH 3 7 | #define EINTR 4 8 | #define EIO 5 9 | #define ENXIO 6 10 | #define E2BIG 7 11 | #define ENOEXEC 8 12 | #define EBADF 9 13 | #define ECHILD 10 14 | #define EAGAIN 11 15 | #define ENOMEM 12 16 | #define EACCES 13 17 | #define EFAULT 14 18 | #define ENOTBLK 15 19 | #define EBUSY 16 20 | #define EEXIST 17 21 | #define EXDEV 18 22 | #define ENODEV 19 23 | #define ENOTDIR 20 24 | #define EISDIR 21 25 | #define EINVAL 22 26 | #define ENFILE 23 27 | #define EMFILE 24 28 | #define ENOTTY 25 29 | #define ETXTBSY 26 30 | #define EFBIG 27 31 | #define ENOSPC 28 32 | #define ESPIPE 29 33 | #define EROFS 30 34 | #define EMLINK 31 35 | #define EPIPE 32 36 | #define EDOM 33 37 | #define ERANGE 34 38 | #define EDEADLK 35 39 | #define ENAMETOOLONG 36 40 | #define ENOLCK 37 41 | #define ENOSYS 38 42 | #define ENOTEMPTY 39 43 | #define ELOOP 40 44 | #define EWOULDBLOCK EAGAIN 45 | #define ENOMSG 42 46 | #define EIDRM 43 47 | #define ECHRNG 44 48 | #define EL2NSYNC 45 49 | #define EL3HLT 46 50 | #define EL3RST 47 51 | #define ELNRNG 48 52 | #define EUNATCH 49 53 | #define ENOCSI 50 54 | #define EL2HLT 51 55 | #define EBADE 52 56 | #define EBADR 53 57 | #define EXFULL 54 58 | #define ENOANO 55 59 | #define EBADRQC 56 60 | #define EBADSLT 57 61 | #define EDEADLOCK EDEADLK 62 | #define EBFONT 59 63 | #define ENOSTR 60 64 | #define ENODATA 61 65 | #define ETIME 62 66 | #define ENOSR 63 67 | #define ENONET 64 68 | #define ENOPKG 65 69 | #define EREMOTE 66 70 | #define ENOLINK 67 71 | #define EADV 68 72 | #define ESRMNT 69 73 | #define ECOMM 70 74 | #define EPROTO 71 75 | #define EMULTIHOP 72 76 | #define EDOTDOT 73 77 | #define EBADMSG 74 78 | #define EOVERFLOW 75 79 | #define ENOTUNIQ 76 80 | #define EBADFD 77 81 | #define EREMCHG 78 82 | #define ELIBACC 79 83 | #define ELIBBAD 80 84 | #define ELIBSCN 81 85 | #define ELIBMAX 82 86 | #define ELIBEXEC 83 87 | #define EILSEQ 84 88 | #define ERESTART 85 89 | #define ESTRPIPE 86 90 | #define EUSERS 87 91 | #define ENOTSOCK 88 92 | #define EDESTADDRREQ 89 93 | #define EMSGSIZE 90 94 | #define EPROTOTYPE 91 95 | #define ENOPROTOOPT 92 96 | #define EPROTONOSUPPORT 93 97 | #define ESOCKTNOSUPPORT 94 98 | #define EOPNOTSUPP 95 99 | #define ENOTSUP EOPNOTSUPP 100 | #define EPFNOSUPPORT 96 101 | #define EAFNOSUPPORT 97 102 | #define EADDRINUSE 98 103 | #define EADDRNOTAVAIL 99 104 | #define ENETDOWN 100 105 | #define ENETUNREACH 101 106 | #define ENETRESET 102 107 | #define ECONNABORTED 103 108 | #define ECONNRESET 104 109 | #define ENOBUFS 105 110 | #define EISCONN 106 111 | #define ENOTCONN 107 112 | #define ESHUTDOWN 108 113 | #define ETOOMANYREFS 109 114 | #define ETIMEDOUT 110 115 | #define ECONNREFUSED 111 116 | #define EHOSTDOWN 112 117 | #define EHOSTUNREACH 113 118 | #define EALREADY 114 119 | #define EINPROGRESS 115 120 | #define ESTALE 116 121 | #define EUCLEAN 117 122 | #define ENOTNAM 118 123 | #define ENAVAIL 119 124 | #define EISNAM 120 125 | #define EREMOTEIO 121 126 | #define EDQUOT 122 127 | #define ENOMEDIUM 123 128 | #define EMEDIUMTYPE 124 129 | #define ECANCELED 125 130 | #define ENOKEY 126 131 | #define EKEYEXPIRED 127 132 | #define EKEYREVOKED 128 133 | #define EKEYREJECTED 129 134 | #define EOWNERDEAD 130 135 | #define ENOTRECOVERABLE 131 136 | #define ERFKILL 132 137 | #define EHWPOISON 133 -------------------------------------------------------------------------------- /kernel/src/arch/x86_64/interrupts/asm/idt.asm: -------------------------------------------------------------------------------- 1 | %macro isr_err_stub 1 2 | isr_stub_%+%1: 3 | cli 4 | cmp byte [rsp + 8],0x08 5 | jz .cont 6 | swapgs 7 | .cont: 8 | 9 | push qword (%+%1) 10 | jmp asmException 11 | cli 12 | hlt 13 | %endmacro 14 | 15 | %macro isr_no_err_stub 1 16 | isr_stub_%+%1: 17 | cli 18 | cmp byte [rsp + 8],0x08 19 | jz .cont 20 | swapgs 21 | .cont: 22 | 23 | push qword 0 24 | push qword (%+%1) 25 | jmp asmException 26 | cli 27 | hlt 28 | %endmacro 29 | 30 | extern ignoreStubC 31 | global ignoreStub 32 | ignoreStub: 33 | push r15 34 | push r14 35 | push r13 36 | push r12 37 | push r11 38 | push r10 39 | push r9 40 | push r8 41 | push rbp 42 | push rdi 43 | push rsi 44 | push rdx 45 | push rcx 46 | push rbx 47 | push rax 48 | mov rax,cr3 49 | push rax 50 | call ignoreStubC 51 | pop rax 52 | mov cr3,rax 53 | pop rax 54 | pop rbx 55 | pop rcx 56 | pop rdx 57 | pop rsi 58 | pop rdi 59 | pop rbp 60 | pop r8 61 | pop r9 62 | pop r10 63 | pop r11 64 | pop r12 65 | pop r13 66 | pop r14 67 | pop r15 68 | iretq 69 | 70 | 71 | extern CPUKernelPanic 72 | asmException: 73 | push r15 74 | push r14 75 | push r13 76 | push r12 77 | push r11 78 | push r10 79 | push r9 80 | push r8 81 | push rbp 82 | push rdi 83 | push rsi 84 | push rdx 85 | push rcx 86 | push rbx 87 | push rax 88 | mov rax,cr3 89 | push rax 90 | mov rdi,rsp 91 | jmp CPUKernelPanic 92 | 93 | isr_no_err_stub 0 94 | isr_no_err_stub 1 95 | isr_no_err_stub 2 96 | isr_no_err_stub 3 97 | isr_no_err_stub 4 98 | isr_no_err_stub 5 99 | isr_no_err_stub 6 100 | isr_no_err_stub 7 101 | isr_err_stub 8 102 | isr_no_err_stub 9 103 | isr_err_stub 10 104 | isr_err_stub 11 105 | isr_err_stub 12 106 | isr_err_stub 13 107 | isr_err_stub 14 108 | isr_no_err_stub 15 109 | isr_no_err_stub 16 110 | isr_err_stub 17 111 | isr_no_err_stub 18 112 | isr_no_err_stub 19 113 | isr_no_err_stub 20 114 | isr_no_err_stub 21 115 | isr_no_err_stub 22 116 | isr_no_err_stub 23 117 | isr_no_err_stub 24 118 | isr_no_err_stub 25 119 | isr_no_err_stub 26 120 | isr_no_err_stub 27 121 | isr_no_err_stub 28 122 | isr_no_err_stub 29 123 | isr_err_stub 30 124 | isr_no_err_stub 31 125 | 126 | global isrTable 127 | isrTable: 128 | %assign i 0 129 | %rep 32 130 | dq isr_stub_%+i 131 | %assign i i+1 132 | %endrep 133 | 134 | %macro irq_stub 1 135 | irq_stub_%+%1: 136 | cli 137 | cmp byte [rsp + 8],0x08 138 | jz .cont 139 | swapgs 140 | .cont: 141 | 142 | push qword 0 143 | push qword (%+%1) 144 | jmp irqStub 145 | cli 146 | hlt 147 | %endmacro 148 | 149 | irq_stub 0 150 | irq_stub 1 151 | irq_stub 2 152 | irq_stub 3 153 | irq_stub 4 154 | irq_stub 5 155 | irq_stub 6 156 | irq_stub 7 157 | irq_stub 8 158 | irq_stub 9 159 | irq_stub 10 160 | irq_stub 11 161 | irq_stub 12 162 | irq_stub 13 163 | irq_stub 14 164 | irq_stub 15 165 | irq_stub 16 166 | irq_stub 17 167 | irq_stub 18 168 | irq_stub 19 169 | irq_stub 20 170 | irq_stub 21 171 | irq_stub 22 172 | irq_stub 23 173 | irq_stub 24 174 | irq_stub 25 175 | irq_stub 26 176 | irq_stub 27 177 | irq_stub 28 178 | irq_stub 29 179 | irq_stub 30 180 | irq_stub 31 181 | irq_stub 32 182 | 183 | global irqTable 184 | irqTable: 185 | %assign i 0 186 | %rep 32 187 | dq irq_stub_%+i 188 | %assign i i+1 189 | %endrep 190 | 191 | extern irqHandler 192 | irqStub: 193 | push r15 194 | push r14 195 | push r13 196 | push r12 197 | push r11 198 | push r10 199 | push r9 200 | push r8 201 | push rbp 202 | push rdi 203 | push rsi 204 | push rdx 205 | push rcx 206 | push rbx 207 | push rax 208 | mov rax,cr3 209 | push rax 210 | mov rdi,rsp 211 | xor rbp,rbp 212 | call irqHandler 213 | pop rax 214 | mov cr3,rax 215 | pop rax 216 | pop rbx 217 | pop rcx 218 | pop rdx 219 | pop rsi 220 | pop rdi 221 | pop rbp 222 | pop r8 223 | pop r9 224 | pop r10 225 | pop r11 226 | pop r12 227 | pop r13 228 | pop r14 229 | pop r15 230 | add rsp,16 231 | 232 | cmp byte [rsp + 8],0x08 233 | jz .cont2 234 | swapgs 235 | 236 | .cont2: 237 | iretq --------------------------------------------------------------------------------