├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── analyze.yml │ ├── doxygen.yml │ └── makefile.yml ├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── Doxyfile ├── Doxyfile_headers ├── Fennix.code-workspace ├── LICENSE ├── Makefile ├── Makefile.conf ├── README.md ├── Screenshot_Fennix.png ├── boot ├── BIOS │ ├── Makefile │ ├── boot.asm │ ├── print.inc │ └── second.asm ├── Makefile └── UEFI │ ├── Makefile │ └── src │ ├── FileLoader.c │ ├── FileLoader.h │ ├── Paging.c │ ├── VirtualMemory.c │ └── lynx.c ├── custom.css ├── doxygen-awesome.css ├── grub.cfg ├── include ├── assert.h ├── cputables.h ├── driver.h ├── interrupts.h ├── io.h ├── math.h ├── stb │ ├── stb_image.h │ └── stb_image_resize.h ├── stdarg.h ├── stdbool.h ├── stddef.h ├── stdint.h ├── stdio.h └── string.h ├── kernel ├── CrashHandler.cpp ├── Critical.cpp ├── Debug.c ├── Driver.cpp ├── Error.cpp ├── Kernel.cpp ├── Lock.cpp ├── Makefile ├── PCI.cpp ├── PCIDescriptors.cpp ├── StackGuard.c ├── Symbols.cpp ├── UBSAN.c ├── UserCrashHandler.cpp ├── arch │ ├── aarch64 │ │ ├── boot │ │ │ └── aarch64-boot.S │ │ └── cpu │ │ │ ├── acpi.hpp │ │ │ ├── apic.hpp │ │ │ ├── cpuid.h │ │ │ ├── gdt.h │ │ │ ├── idt.h │ │ │ └── smp.hpp │ ├── amd64 │ │ ├── LockAssembly.S │ │ ├── SystemCallsHelper.asm │ │ ├── boot │ │ │ ├── Limine.c │ │ │ └── limine.h │ │ └── cpu │ │ │ ├── ACPI.cpp │ │ │ ├── APIC.cpp │ │ │ ├── CPUID.c │ │ │ ├── DSDT.cpp │ │ │ ├── GDT.c │ │ │ ├── IDT.c │ │ │ ├── MADT.cpp │ │ │ ├── RandomNumberGenerator.c │ │ │ ├── SMP.cpp │ │ │ ├── SMPTrampolineAssembly.asm │ │ │ ├── VMDetect.c │ │ │ ├── acpi.hpp │ │ │ ├── apic.hpp │ │ │ ├── cpuid.h │ │ │ ├── fxsr.asm │ │ │ ├── gdt.h │ │ │ ├── idt.h │ │ │ └── smp.hpp │ └── i686 │ │ ├── LockAssembly.asm │ │ ├── SystemCallsHelper.asm │ │ ├── boot │ │ ├── Multiboot2.c │ │ └── i386-boot.S │ │ └── cpu │ │ ├── ACPI.cpp │ │ ├── APIC.cpp │ │ ├── CPUID.c │ │ ├── DSDT.cpp │ │ ├── GDT.c │ │ ├── IDT.c │ │ ├── MADT.cpp │ │ ├── RandomNumberGenerator.c │ │ ├── SMP.cpp │ │ ├── VMDetect.c │ │ ├── acpi.hpp │ │ ├── apic.hpp │ │ ├── cpuid.h │ │ ├── fxsr.asm │ │ ├── gdt.h │ │ ├── idt.h │ │ └── smp.hpp ├── boot │ └── BootScreen.cpp ├── cpu │ ├── acpi.hpp │ ├── apic.hpp │ ├── cpuid.h │ ├── fxsr.h │ ├── gdt.h │ ├── idt.h │ └── smp.hpp ├── cpuspeed.hpp ├── driver.hpp ├── drivers │ ├── disk.cpp │ ├── disk.h │ ├── display.cpp │ ├── keyboard.cpp │ ├── keyboard.hpp │ ├── mouse.cpp │ ├── mouse.hpp │ ├── network │ │ ├── AMDPCNET │ │ │ ├── AMDPCNET.cpp │ │ │ └── AMDPCNET.hpp │ │ ├── E1000 │ │ │ ├── E1000.cpp │ │ │ └── E1000.hpp │ │ ├── Intel8254x │ │ │ ├── Intel8254x.cpp │ │ │ └── Intel8254x.hpp │ │ ├── RTL8139 │ │ │ ├── RTL8139.cpp │ │ │ └── RTL8139.hpp │ │ ├── RTL8169 │ │ │ ├── RTL8169.cpp │ │ │ └── RTL8169.hpp │ │ └── VirtioNetwork │ │ │ ├── VirtioNetwork.cpp │ │ │ └── VirtioNetwork.hpp │ ├── serial.c │ ├── serial.h │ └── storage │ │ ├── ahci.cpp │ │ ├── ahci.h │ │ ├── floppy.cpp │ │ └── floppy.h ├── files │ ├── fennix000.bmp │ ├── fennix001.bmp │ ├── fennix002.bmp │ ├── fennix003.bmp │ ├── fennix004.bmp │ ├── fennix005.bmp │ ├── fennix006.bmp │ ├── fennix007.bmp │ ├── fennix008.bmp │ ├── fennix009.bmp │ ├── fennix010.bmp │ ├── fennix011.bmp │ ├── fennix012.bmp │ ├── fennix013.bmp │ ├── fennix014.bmp │ ├── fennix015.bmp │ ├── fennix016.bmp │ ├── fennix017.bmp │ ├── fennix018.bmp │ ├── fennix019.bmp │ ├── fennix020.bmp │ ├── fennix021.bmp │ └── fennix022.bmp ├── filestructures │ ├── elf.h │ └── file.cpp ├── filesystem │ ├── FileSystem.cpp │ ├── fs │ │ ├── ext2.cpp │ │ ├── fat.cpp │ │ ├── fb.cpp │ │ ├── initrd.cpp │ │ ├── null.cpp │ │ ├── random.cpp │ │ ├── serial.cpp │ │ ├── ustar.cpp │ │ └── zero.cpp │ └── mountpoints │ │ ├── devfs.cpp │ │ ├── drvfs.cpp │ │ ├── mountfs.cpp │ │ ├── netfs.cpp │ │ ├── procfs.cpp │ │ └── sysinfo.cpp ├── include │ ├── asm.h │ ├── atomic.hpp │ ├── bitmap.hpp │ ├── boot │ │ ├── gbp.h │ │ └── protocols │ │ │ ├── limine.h │ │ │ └── multiboot2.h │ ├── bootscreen.h │ ├── cpuid.h │ ├── critical.hpp │ ├── ctype.h │ ├── cwalk.h │ ├── debug.h │ ├── display.h │ ├── easyc.h │ ├── elf.h │ ├── err.h │ ├── events.hpp │ ├── filesystem.h │ ├── hashmap.hpp │ ├── heap.h │ ├── int.h │ ├── internal_task.h │ ├── ipc.hpp │ ├── limits.h │ ├── list.h │ ├── lock.h │ ├── msexec.h │ ├── printf.h │ ├── rand.h │ ├── smartptr.hpp │ ├── stdalign.h │ ├── string.h │ ├── symbols.hpp │ ├── sys.h │ ├── task.h │ ├── test.h │ ├── types.h │ ├── vector.hpp │ └── vm.h ├── interrupts │ ├── Interrputs.cpp │ ├── PIC.c │ └── pic.h ├── kernel.h ├── libs │ ├── ArithmeticOperations.c │ ├── Bitmap.cpp │ ├── String.c │ ├── converter.cpp │ ├── converter.h │ ├── cwalk.c │ ├── cxxabi.cpp │ └── printf.c ├── linker-aarch64.ld ├── linker-amd64.ld ├── linker-i686.ld ├── mem │ ├── HeapManager.cpp │ ├── PageTableHeapManager.cpp │ ├── PhysicalMemoryManager.cpp │ ├── StackHeapManager.cpp │ ├── VirtualMemoryManager.cpp │ ├── buddyalloc │ │ └── buddy_alloc.h │ ├── defaultalloc │ │ ├── defaultalloc.cpp │ │ └── defaultalloc.hpp │ ├── helpers │ │ ├── PageDirectoryEntry.cpp │ │ ├── PageFrameAllocator.cpp │ │ ├── PageMapIndexer.cpp │ │ └── PageTableManager.cpp │ ├── liballoc │ │ ├── liballoc.c │ │ ├── liballoc.h │ │ ├── liballoc_1_1.c │ │ └── liballoc_1_1.h │ └── xalloc │ │ ├── Xalloc.cpp │ │ └── Xalloc.hpp ├── network │ ├── AddressResolutionProtocol.cpp │ ├── DynamicHostConfigurationProtocol.cpp │ ├── Ethernet.cpp │ ├── InternetControlMessageProtocol.cpp │ ├── InternetProtocol.cpp │ ├── NetworkController.cpp │ ├── NetworkController.hpp │ ├── NetworkDebugger.cpp │ ├── NetworkTimeProtocol.cpp │ ├── TransmissionControlProtocol.cpp │ └── UserDatagramProtocol.cpp ├── pci.h ├── proc │ ├── Binary.cpp │ ├── Events.cpp │ ├── InterProcessCommunication.cpp │ ├── Monotasking.cpp │ ├── Multitasking.cpp │ ├── ProcessAPI.cpp │ ├── Task.cpp │ ├── binary.hpp │ ├── events.hpp │ ├── exec │ │ ├── elf.cpp │ │ ├── elf.hpp │ │ ├── exec.hpp │ │ ├── mz.cpp │ │ ├── mz.hpp │ │ ├── ne.cpp │ │ ├── ne.hpp │ │ ├── pe.cpp │ │ └── pe.hpp │ └── ipc.hpp ├── security │ ├── Security.cpp │ └── security.hpp ├── syscalls │ ├── Linux.cpp │ ├── Native.cpp │ ├── SystemCalls.cpp │ └── syscalls.hpp ├── sysrecovery │ ├── Recovery.cpp │ └── recovery.hpp ├── test.cpp ├── test.h ├── timer.h ├── timer │ ├── APICTimer.cpp │ ├── HPETTimer.cpp │ ├── PIT.c │ ├── TSC.cpp │ ├── Timer.c │ ├── apic_timer.h │ ├── hpet.h │ ├── pit.h │ └── tsc.h └── ubsan.h ├── libc ├── .vscode │ └── c_cpp_properties.json ├── FennixLibc.code-workspace ├── Makefile ├── crt │ ├── Makefile │ ├── crt0.c │ ├── crt1.c │ ├── crtbegin.c │ ├── crtend.c │ ├── crti.c │ └── crtn.c ├── include │ ├── alloc.h │ ├── assert.h │ ├── cdefs.h │ ├── convert.h │ ├── ctype.h │ ├── errno.h │ ├── fcntl.h │ ├── file.h │ ├── inttypes.h │ ├── io.h │ ├── math.h │ ├── print.h │ ├── stdarg.h │ ├── stdint.h │ ├── string.h │ ├── sys │ │ ├── time.h │ │ └── types.h │ ├── syscalls.h │ └── system.h ├── libg │ ├── Makefile │ └── libgstub.cpp ├── libgcc │ ├── ArithmeticOperations.c │ ├── Makefile │ ├── allocator.cpp │ └── cxa.cpp └── src │ ├── FennixStandardLibrary │ ├── alloc.c │ ├── convert.c │ ├── file.c │ ├── print.c │ └── system.c │ ├── Makefile │ ├── alloc │ ├── liballoc_1_1.c │ └── liballoc_1_1.h │ ├── main.c │ ├── printf.c │ ├── printf.h │ └── string │ ├── mem.c │ └── string.c ├── limine.cfg ├── lynx.cfg ├── resources ├── initrd │ ├── ascii │ ├── ascii_link │ ├── home │ │ └── default │ │ │ ├── .config │ │ │ └── .gitkeep │ │ │ ├── Apps │ │ │ ├── .gitignore │ │ │ └── .gitkeep │ │ │ ├── Desktop │ │ │ └── .gitkeep │ │ │ ├── Documents │ │ │ └── Sample File.txt │ │ │ ├── Downloads │ │ │ └── .gitkeep │ │ │ ├── Games │ │ │ ├── .gitignore │ │ │ └── .gitkeep │ │ │ ├── Music │ │ │ └── .gitkeep │ │ │ ├── Pictures │ │ │ └── Fennix.png │ │ │ └── Videos │ │ │ └── Fennix.mp4 │ ├── system │ │ ├── .gitignore │ │ ├── config │ │ │ └── kernel.cfg │ │ ├── drivers │ │ │ └── driver.cfg │ │ ├── fonts │ │ │ └── tamsyn-font-1.11 │ │ │ │ ├── LICENSE │ │ │ │ ├── README │ │ │ │ ├── Tamsyn10x20b.psf │ │ │ │ ├── Tamsyn10x20r.psf │ │ │ │ ├── Tamsyn5x9b.psf │ │ │ │ ├── Tamsyn5x9r.psf │ │ │ │ ├── Tamsyn6x12b.psf │ │ │ │ ├── Tamsyn6x12r.psf │ │ │ │ ├── Tamsyn7x13b.psf │ │ │ │ ├── Tamsyn7x13r.psf │ │ │ │ ├── Tamsyn7x14b.psf │ │ │ │ ├── Tamsyn7x14r.psf │ │ │ │ ├── Tamsyn8x15b.psf │ │ │ │ ├── Tamsyn8x15r.psf │ │ │ │ ├── Tamsyn8x16b.psf │ │ │ │ └── Tamsyn8x16r.psf │ │ ├── lib │ │ │ └── .gitkeep │ │ └── wallpapers │ │ │ ├── IMG_0199.JPG │ │ │ ├── IMG_0199_1000x1000.JPG │ │ │ ├── IMG_0199_1000x1000.TGA │ │ │ └── fennec.tga │ ├── test.txt │ ├── test_dir │ │ ├── .gitignore │ │ └── test.sh │ └── tmp │ │ └── .gitkeep └── modules │ └── .gitkeep ├── startup.nsh ├── tools ├── Makefile ├── ReadEthernet.c ├── e.cpp ├── initrd.c └── website │ ├── assets │ └── Background.png │ ├── css │ └── style.css │ ├── index.html │ └── js │ └── script.js └── userspace ├── Makefile ├── apps ├── Makefile ├── games │ ├── .gitignore │ ├── Makefile │ └── tictactoe │ │ ├── Makefile │ │ └── tictactoe.cpp ├── system │ ├── Makefile │ ├── drvmgr │ │ ├── Makefile │ │ └── drvmgr.cpp │ ├── fesktop │ │ ├── Makefile │ │ └── main.cpp │ ├── init │ │ ├── Makefile │ │ └── init.cpp │ ├── monoton │ │ ├── Makefile │ │ ├── cmds.hpp │ │ ├── cmds │ │ │ └── cat.cpp │ │ ├── cwalk.h │ │ ├── dumper.cpp │ │ ├── dumper.hpp │ │ ├── login.cpp │ │ ├── monoton.cpp │ │ └── monoton.hpp │ ├── reboot │ │ ├── Makefile │ │ ├── reboot.cpp │ │ └── reboot.hpp │ ├── shutdown │ │ ├── Makefile │ │ ├── shutdown.cpp │ │ └── shutdown.hpp │ ├── uiserver │ │ ├── Makefile │ │ └── main.cpp │ ├── usermodecrash_handler │ │ ├── Makefile │ │ ├── usermodecrash_handler.cpp │ │ └── usm.h │ └── wm │ │ ├── Makefile │ │ └── main.cpp └── user │ ├── Makefile │ ├── brainfuckcompiler │ ├── Makefile │ └── brainfuck.c │ └── texteditor │ ├── Makefile │ └── texteditor.c ├── drivers ├── Makefile ├── audio │ └── ac97 │ │ ├── Makefile │ │ ├── link.ld │ │ └── main.cpp ├── network │ └── rtl8139 │ │ ├── Makefile │ │ ├── link.ld │ │ └── main.cpp ├── peripheral │ ├── keyboard │ │ ├── Makefile │ │ ├── link.ld │ │ └── main.cpp │ └── mouse │ │ ├── Makefile │ │ ├── link.ld │ │ └── main.cpp └── video │ ├── bochs │ ├── Makefile │ ├── link.ld │ └── main.cpp │ └── virtio │ ├── Makefile │ ├── link.ld │ └── main.cpp └── libs ├── Makefile ├── algo ├── Makefile ├── algo.c └── algo.h ├── cargs ├── LICENSE.md ├── Makefile ├── cargs.c └── cargs.h ├── cwalk ├── LICENSE.md ├── Makefile ├── cwalk.c └── cwalk.h ├── drawlib └── main.cpp ├── fenlib ├── Makefile └── main.cpp ├── monoton ├── Makefile ├── monotonlib.cpp ├── monotonlib.h └── nanoprintf.h ├── proclib └── main.cpp └── scparse ├── Makefile ├── scparse.c └── scparse.h /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: EnderIce2 # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: EnderIce2 # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report / Crash 3 | about: Create a report to help find bugs 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshot or Video** 20 | If applicable, add screenshots or videos to help explain your problem. 21 | 22 | **Serial Port Output** 23 | Serial port output (file .log or .txt). 24 | 25 | **System Information** 26 | - CPU: 27 | - RAM: 28 | - GPU: 29 | - Motherboard: 30 | - Virtual Machine: 31 | 32 | **Additional context** 33 | Add any other context about the problem here. 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/doxygen.yml: -------------------------------------------------------------------------------- 1 | name: Doxygen Documentation 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | deploydoc: 11 | name: Deploy Documentation to GitHub Pages 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v3 16 | 17 | - name: Install Doxygen 18 | run: sudo apt-get install doxygen make -y 19 | 20 | - name: Generate Documentation 21 | run: make doxygen 22 | 23 | - name: Copy GitHub Pages Website 24 | run: cp -r tools/website/* doxygen-doc/ 25 | 26 | - name: Deploy documentation 27 | uses: JamesIves/github-pages-deploy-action@v4 28 | with: 29 | folder: doxygen-doc 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | iso_tmp_data 2 | boot/UEFI/gnu-efi 3 | boot/UEFI/include 4 | tools/* 5 | !tools/website 6 | !tools/Makefile 7 | !tools/*.c 8 | !tools/*.cpp 9 | initrd.tar.gz 10 | kernel/files/ter-powerline-v12n.psf 11 | kernel/files/zap-ext-light20.psf 12 | kernel/files/zap-ext-light24.psf 13 | kernel/files/zap-light16.psf 14 | doxygen-doc 15 | *.log 16 | *.drv 17 | *.o 18 | *.a 19 | *.so 20 | *.elf 21 | *.bin 22 | *.sym 23 | *.map 24 | *.fsys 25 | *.img 26 | *.iso 27 | *.EFI 28 | *.efi 29 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/kernel/include", 7 | "${workspaceFolder}/libc/include", 8 | "${workspaceFolder}/include", 9 | "${workspaceFolder}/boot/UEFI/gnu-efi/inc" 10 | ], 11 | "defines": [ 12 | "DEBUG", 13 | "KERNEL_NAME", 14 | "KERNEL_VERSION", 15 | "GIT_COMMIT", 16 | "GIT_COMMIT_SHORT", 17 | "UNIT_TESTS" 18 | ], 19 | "compilerPath": "${workspaceFolder}/tools/cross/bin/amd64-elf-gcc", 20 | "cStandard": "gnu17", 21 | "cppStandard": "gnu++20", 22 | "intelliSenseMode": "gcc-x64", 23 | "forcedInclude": [], 24 | "browse": { 25 | "path": [] 26 | }, 27 | "configurationProvider": "ms-vscode.makefile-tools" 28 | } 29 | ], 30 | "version": 4 31 | } -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "oshri22.asmb", 4 | "jeff-hykin.better-cpp-syntax", 5 | "aaron-bond.better-comments", 6 | "ms-vscode.cpptools-extension-pack", 7 | "ms-vscode.cpptools", 8 | "hars.cppsnippets", 9 | "amiralizadeh9480.cpp-helper", 10 | "austin.code-gnu-global", 11 | "icrawl.discord-vscode", 12 | "cschlosser.doxdocgen", 13 | "github.vscode-pull-request-github", 14 | "github.remotehub", 15 | "eamodio.gitlens", 16 | "ajshort.include-autocomplete", 17 | "kiteco.kite", 18 | "nico-castell.linux-desktop-file", 19 | "zixuanwang.linkerscript", 20 | "ms-vsliveshare.vsliveshare", 21 | "alpha1337k.makefile-boilerplate", 22 | "zenor.makefile-creator", 23 | "yzhang.markdown-all-in-one", 24 | "pkief.material-icon-theme", 25 | "shd101wyy.markdown-preview-enhanced", 26 | "ibm.output-colorizer", 27 | "juninhosilva.package-plus-plus", 28 | "christian-kohler.path-intellisense", 29 | "tabnine.tabnine-vscode", 30 | "wayou.vscode-todo-highlight", 31 | "gruntfuggly.todo-tree", 32 | "visualstudioexptteam.vscodeintellicode", 33 | "13xforever.language-x86-64-assembly" 34 | ] 35 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.errorSquiggles": "Enabled", 3 | "files.watcherExclude": { 4 | "**/tools/limine/**": true, 5 | "**/tools/binutils-gdb/**": true, 6 | "**/tools/gcc/**": true, 7 | "**/tools/build-gcc/**": true, 8 | "**/tools/build-binutils/**": true, 9 | "**/tools/cross/**": true, 10 | "**/tools/doxygen-doc/**": true, 11 | 12 | }, 13 | "cmake.configureOnOpen": false, 14 | "C_Cpp.autocompleteAddParentheses": true, 15 | "C_Cpp.codeAnalysis.clangTidy.enabled": true, 16 | "C_Cpp.clang_format_style": "Visual Studio", 17 | "C_Cpp.default.intelliSenseMode": "gcc-x64", 18 | "C_Cpp.default.cStandard": "c17", 19 | "C_Cpp.default.cppStandard": "c++20", 20 | "C_Cpp.intelliSenseMemoryLimit": 16384, 21 | "editor.smoothScrolling": true, 22 | "editor.cursorSmoothCaretAnimation": true, 23 | "files.associations": { 24 | "stddef.h": "c", 25 | "ubsan.h": "c", 26 | "io.h": "c", 27 | "serial.h": "c", 28 | "interrupts.h": "c", 29 | "types.h": "c", 30 | "heap.h": "c", 31 | "asm.h": "c", 32 | "cpuid.h": "c", 33 | "limits.h": "c", 34 | "lock.h": "c", 35 | "stdint.h": "c", 36 | "debug.h": "c", 37 | "limine.h": "c", 38 | "kernel.h": "c", 39 | "display.h": "c", 40 | "idt.h": "c", 41 | "string.h": "c", 42 | "sys.h": "c", 43 | "internal_task.h": "c", 44 | "cwalk.h": "c", 45 | "syscalls.h": "c" 46 | } 47 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Launch QEMU", 6 | "type": "shell", 7 | "isBackground": true, 8 | "linux": { 9 | "command": "make vscode_debug" 10 | } 11 | }, 12 | { 13 | "label": "Clean", 14 | "type": "shell", 15 | "linux": { 16 | "command": "make clean && killall qemu-system-x86_64" 17 | } 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /Fennix.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": { 8 | "files.associations": { 9 | "interrupts.h": "c", 10 | "rand.h": "c", 11 | "timer.h": "c", 12 | "display.h": "c", 13 | "loadpsf.h": "c", 14 | "syscalls.h": "c", 15 | "string.h": "c", 16 | "stdint.h": "c", 17 | "stdlib.h": "c", 18 | "stdio.h": "c", 19 | "inttypes.h": "c", 20 | "config.h": "c", 21 | "stddef.h": "c", 22 | "ctype.h": "c", 23 | "errno.h": "c", 24 | "stdarg.h": "c", 25 | "cdefs.h": "c", 26 | "d_event.h": "c", 27 | "z_zone.h": "c", 28 | "file.h": "c", 29 | "deh_main.h": "c", 30 | "deh_misc.h": "c", 31 | "time.h": "c", 32 | "print.h": "c", 33 | "*.tcc": "cpp", 34 | "heap.h": "c", 35 | "idt.h": "c", 36 | "stivale.h": "c", 37 | "cpuid.h": "c", 38 | "io.h": "c", 39 | "int.h": "c", 40 | "pit.h": "c", 41 | "types.h": "c", 42 | "efilib.h": "c", 43 | "efi.h": "c", 44 | "fileloader.h": "c", 45 | "assert.h": "c", 46 | "printf.h": "c", 47 | "convert.h": "c", 48 | "kernel.h": "c", 49 | "serial.h": "c", 50 | "xalloc.hpp": "c", 51 | "limine.h": "c", 52 | "ahci.h": "c", 53 | "floppy.h": "c", 54 | "pci.h": "c", 55 | "lock.h": "c", 56 | "pic.h": "c", 57 | "gdt.h": "c", 58 | "asm.h": "c", 59 | "task.h": "c", 60 | "vector.hpp": "c" 61 | }, 62 | "debug.allowBreakpointsEverywhere": true 63 | } 64 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 EnderIce2 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 | -------------------------------------------------------------------------------- /Makefile.conf: -------------------------------------------------------------------------------- 1 | # If the OS we are building should be compiled for debugging purposes. 2 | DEBUG = 1 3 | 4 | # Operating system name. 5 | OSNAME = FennixProject 6 | 7 | # OS architecture: amd64, i686, aarch64 8 | OSARCH = amd64 9 | 10 | # Kernel version. 11 | KERNEL_VERSION = alpha-0.0.1 12 | 13 | # Which bootloader to use. 14 | # Available bootloaders: 15 | # - lynx - Lynx Bootloader (still under development) 16 | # - other - Limine & GRUB Bootloader 17 | BOOTLOADER=other 18 | 19 | # The path of the cross compiler. 20 | # If you want to use your own cross compiler, 21 | # change it to the path of the compiler. 22 | COMPILER_PATH = tools/cross/bin 23 | 24 | # The path of the Limine bootloader. 25 | LIMINE_FOLDER = tools/limine 26 | 27 | # Qemu path. If you want to use the one you have installed in your system, 28 | # change it to /usr/bin/qemu-system- (do not include x86_64 or i386, it will be added automatically) 29 | QEMU_PATH = tools/cross/bin/qemu-system- 30 | 31 | # Enable unit testing. 32 | UNIT_TESTS = 0 33 | 34 | 35 | 36 | 37 | # make releated variables 38 | # DO NOT TOUCH! 39 | 40 | ifeq ($(OSARCH), amd64) 41 | COMPILER_ARCH = amd64-elf- 42 | QEMU_ARCH = x86_64 43 | else ifeq ($(OSARCH), i686) 44 | COMPILER_ARCH = i686-elf- 45 | QEMU_ARCH = i386 46 | else ifeq ($(OSARCH), aarch64) 47 | COMPILER_ARCH = aarch64-elf- 48 | QEMU_ARCH = aarch64 49 | endif 50 | -------------------------------------------------------------------------------- /Screenshot_Fennix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/Screenshot_Fennix.png -------------------------------------------------------------------------------- /boot/BIOS/Makefile: -------------------------------------------------------------------------------- 1 | 2 | NASM = /usr/bin/nasm 3 | 4 | build: 5 | $(NASM) boot.asm -f bin -o boot.bin 6 | $(NASM) second.asm -f bin -o second.bin 7 | cat boot.bin second.bin > loader.bin 8 | 9 | clean: 10 | rm -f boot.bin second.bin loader.bin 11 | -------------------------------------------------------------------------------- /boot/BIOS/boot.asm: -------------------------------------------------------------------------------- 1 | [ORG 0x7C00] 2 | [BITS 16] 3 | 4 | start: 5 | jmp 0x0000:Boot 6 | nop 7 | 8 | times 8-($-$$) db 0 9 | PrimaryVolumeDescriptor dd 0 10 | BootFileLocation dd 0 11 | BootFileLength dd 0 12 | Checksum dd 0 13 | Reserved times 40 db 0 14 | times 90-($-$$) db 0 15 | 16 | %include "print.inc" 17 | 18 | Boot: 19 | cli 20 | mov [BOOT_DISK], dl 21 | xor ax, ax 22 | mov ds, ax 23 | mov ss, ax 24 | mov sp, 0x9C00 25 | mov si, BootloaderText 26 | call Print 27 | call ReadDisk 28 | jmp EX_ADDRESS 29 | jmp $ 30 | 31 | ReadDisk: 32 | sti 33 | mov ah, 0x02 34 | mov bx, EX_ADDRESS 35 | mov al, 20 ; max 65 36 | mov dl, [BOOT_DISK] 37 | mov ch, 0x00 38 | mov dh, 0x00 39 | mov cl, 0x02 40 | int 0x13 41 | jc DiskError 42 | cli 43 | ret 44 | 45 | DiskError: 46 | cli 47 | mov si, DiskReadingErrorMessage 48 | call Print 49 | jmp $ 50 | 51 | BootloaderText db 'Lynx Bootloader', 0 52 | DiskReadingErrorMessage: db ' Disk Error', 0 53 | EX_ADDRESS equ 0x8000 54 | BOOT_DISK: db 0 55 | 56 | times 510-($-$$) db 0 57 | db 0x55 58 | db 0xAA 59 | -------------------------------------------------------------------------------- /boot/BIOS/print.inc: -------------------------------------------------------------------------------- 1 | Print: 2 | lodsb 3 | or al, al 4 | jz PrintDone 5 | mov ah, 0eh 6 | int 10h 7 | jmp Print 8 | PrintDone: 9 | ret 10 | -------------------------------------------------------------------------------- /boot/BIOS/second.asm: -------------------------------------------------------------------------------- 1 | ; TODO 2 | init: 3 | mov si, LoadingText 4 | call Print 5 | jmp $ 6 | 7 | %include "print.inc" 8 | 9 | LoadingText db ' Loading...', 0 10 | -------------------------------------------------------------------------------- /boot/Makefile: -------------------------------------------------------------------------------- 1 | 2 | GNUEFI_RELEASE_VERSION=3.0.14 3 | 4 | NASM = /usr/bin/nasm 5 | 6 | gnuefi: 7 | wget https://archive.org/download/gnu-efi-$(GNUEFI_RELEASE_VERSION).tar/gnu-efi-$(GNUEFI_RELEASE_VERSION).tar.bz2 8 | tar -xf gnu-efi-$(GNUEFI_RELEASE_VERSION).tar.bz2 -C UEFI 9 | rm gnu-efi-$(GNUEFI_RELEASE_VERSION).tar.bz2 10 | mv UEFI/gnu-efi-$(GNUEFI_RELEASE_VERSION) UEFI/gnu-efi 11 | cp -a ./UEFI/gnu-efi/inc/. ./UEFI/include 12 | make -C UEFI/gnu-efi 13 | 14 | build: 15 | $(info Compiling UEFI bootloader...) 16 | make -C BIOS build 17 | make -C UEFI build 18 | 19 | clean: 20 | make -C UEFI clean 21 | make -C BIOS clean 22 | -------------------------------------------------------------------------------- /boot/UEFI/Makefile: -------------------------------------------------------------------------------- 1 | include ../../Makefile.conf 2 | 3 | NAME=efi-loader.bin 4 | CC = gcc 5 | LD = ld 6 | OBJCOPY=objcopy 7 | 8 | C_SOURCES = $(shell find ./src -type f -name '*.c') 9 | OBJ = $(C_SOURCES:.c=.o) 10 | 11 | build: $(NAME) 12 | 13 | $(NAME): BOOTX64 14 | dd if=/dev/zero of=$(NAME) bs=512 count=93750 15 | mformat -i $(NAME) :: 16 | mmd -i $(NAME) ::/EFI 17 | mmd -i $(NAME) ::/EFI/BOOT 18 | mcopy -i $(NAME) BOOTX64.EFI ::/EFI/BOOT 19 | 20 | BOOTX64: $(OBJ) 21 | $(LD) -shared -Bsymbolic -Lgnu-efi/x86_64/lib -Lgnu-efi/x86_64/gnuefi -Tgnu-efi/gnuefi/elf_x86_64_efi.lds gnu-efi/x86_64/gnuefi/crt0-efi-x86_64.o $(OBJ) -o tmp.so -lgnuefi -lefi 22 | $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 tmp.so BOOTX64.EFI 23 | rm tmp.so 24 | 25 | %.o: %.c 26 | $(CC) -Ignu-efi/inc -Ignu-efi/inc/x86_64 -Ignu-efi/inc/protocol -fpic -ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -maccumulate-outgoing-args -c $< -o $@ 27 | 28 | clean: 29 | rm -f $(NAME) $(OBJ) BOOTX64.EFI 30 | -------------------------------------------------------------------------------- /boot/UEFI/src/FileLoader.c: -------------------------------------------------------------------------------- 1 | #include "FileLoader.h" 2 | 3 | // https://wiki.osdev.org/Loading_files_under_UEFI 4 | 5 | EFI_FILE *LoadFile(EFI_FILE *Directory, CHAR16 *Path, EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) 6 | { 7 | return NULL; 8 | } 9 | -------------------------------------------------------------------------------- /boot/UEFI/src/FileLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | EFI_FILE *LoadFile(EFI_FILE *Directory, CHAR16 *Path, EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable); 6 | -------------------------------------------------------------------------------- /boot/UEFI/src/Paging.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/boot/UEFI/src/Paging.c -------------------------------------------------------------------------------- /boot/UEFI/src/VirtualMemory.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/boot/UEFI/src/VirtualMemory.c -------------------------------------------------------------------------------- /boot/UEFI/src/lynx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "FileLoader.h" 5 | 6 | EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) 7 | { 8 | InitializeLib(ImageHandle, SystemTable); 9 | SystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL); 10 | Print(L"Lynx Bootloader © EnderIce2 2022\n"); 11 | EFI_FILE *Kernel = LoadFile(NULL, L"kernel.fsys", ImageHandle, SystemTable); 12 | 13 | if (Kernel == NULL) 14 | { 15 | Print(L"Kernel not found\n"); 16 | while (1) 17 | asm("hlt"); 18 | } 19 | 20 | while (1) 21 | asm("hlt"); 22 | return EFI_SUCCESS; 23 | } 24 | -------------------------------------------------------------------------------- /custom.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --primary-color: #00559f; 3 | --primary-dark-color: #1982d2; 4 | --primary-light-color: #4779ac; 5 | --primary-lighter-color: #191e21; 6 | --primary-lightest-color: #191a1c; 7 | 8 | --box-shadow: 0 2px 10px 0 rgba(0,0,0,.35); 9 | 10 | --odd-color: rgba(0,0,0,.1); 11 | 12 | --menu-selected-background: rgba(0,0,0,.4); 13 | 14 | --page-background-color: #1C1D1F; 15 | --page-foreground-color: #d2dbde; 16 | --page-secondary-foreground-color: #859399; 17 | --separator-color: #000000; 18 | --side-nav-background: #252628; 19 | 20 | --code-background: #2a2c2f; 21 | 22 | --tablehead-background: #2a2c2f; 23 | 24 | --blockquote-background: #1f2022; 25 | --blockquote-foreground: #77848a; 26 | 27 | --warning-color: #b61825; 28 | --warning-color-dark: #510a02; 29 | --warning-color-darker: #f5b1aa; 30 | --note-color: rgb(255, 183, 0); 31 | --note-color-dark: #9f7300; 32 | --note-color-darker: #fff6df; 33 | --deprecated-color: rgb(88, 90, 96); 34 | --deprecated-color-dark: #262e37; 35 | --deprecated-color-darker: #a0a5b0; 36 | --bug-color: rgb(248, 113, 0); 37 | --bug-color-dark: #812a00; 38 | --bug-color-darker: #ffd3be; 39 | } 40 | 41 | div.contents div.dyncontent img { 42 | filter: hue-rotate(180deg) invert(); 43 | } 44 | 45 | .iconfopen, .iconfclosed { 46 | filter: hue-rotate(180deg) invert(); 47 | } 48 | 49 | #nav-path li.navelem:after { 50 | text-shadow: 3px 0 0 var(--separator-color), 8px 0 6px rgba(0,0,0,0.4); 51 | } 52 | 53 | ::-webkit-scrollbar { 54 | width: 10px; 55 | } 56 | 57 | ::-webkit-scrollbar-track { 58 | background: rgb(40, 40, 40); 59 | } 60 | 61 | ::-webkit-scrollbar-thumb { 62 | background: #888; 63 | } 64 | 65 | ::-webkit-scrollbar-thumb:hover { 66 | background: #555; 67 | } -------------------------------------------------------------------------------- /grub.cfg: -------------------------------------------------------------------------------- 1 | set default=0 2 | set timeout=0 3 | 4 | menuentry "Fennix" { 5 | multiboot2 /kernel.fsys 6 | boot 7 | } -------------------------------------------------------------------------------- /include/assert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef syskernel 4 | #include 5 | #include 6 | 7 | START_EXTERNC 8 | 9 | #define assert(x) \ 10 | do \ 11 | { \ 12 | if (!(x)) \ 13 | while (1) \ 14 | ; \ 15 | } while (0) 16 | 17 | #else 18 | 19 | #define assert(x) \ 20 | do \ 21 | { \ 22 | if (!(x)) \ 23 | while (1) \ 24 | ; \ 25 | } while (0) 26 | 27 | #endif 28 | 29 | #define ASSERT(x) assert(x) 30 | 31 | // static_assert will throw a compile-time exception if assertion fails 32 | #define static_assert(x) \ 33 | switch (x) \ 34 | case 0: \ 35 | case (x): 36 | 37 | #ifdef syskernel 38 | END_EXTERNC 39 | #endif 40 | -------------------------------------------------------------------------------- /include/math.h: -------------------------------------------------------------------------------- 1 | #pragma once -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #ifndef __GNUC_VA_LIST 8 | #define __GNUC_VA_LIST 9 | typedef __builtin_va_list __gnuc_va_list; 10 | #endif 11 | #ifndef __va_list__ 12 | typedef __builtin_va_list va_list; 13 | #endif 14 | 15 | #define va_start(v, l) __builtin_va_start(v, l) 16 | #define va_end(v) __builtin_va_end(v) 17 | #define va_arg(v, l) __builtin_va_arg(v, l) 18 | 19 | #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L || __cplusplus + 0 >= 201103L 20 | #define va_copy(d, s) __builtin_va_copy(d, s) 21 | #endif 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __cplusplus 4 | 5 | #define bool _Bool 6 | 7 | #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L 8 | 9 | #define true ((_Bool)+1u) 10 | #define false ((_Bool)+0u) 11 | 12 | #else 13 | 14 | #define true 1 15 | #define false 0 16 | 17 | #endif 18 | 19 | #else 20 | 21 | #define _Bool bool 22 | 23 | #endif 24 | 25 | #define __bool_true_false_are_defined 1 26 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #undef NULL 4 | #ifdef __GNUG__ 5 | #define NULL __null 6 | #else 7 | #ifndef __cplusplus 8 | #define NULL ((void *)0) 9 | #else 10 | #define NULL 0 11 | #endif 12 | #endif 13 | 14 | #ifndef __SIZE_TYPE__ 15 | #define __SIZE_TYPE__ long unsigned int 16 | #endif 17 | typedef __SIZE_TYPE__ size_t; 18 | 19 | typedef long ssize_t; 20 | 21 | #ifndef __PTRDIFF_TYPE__ 22 | #define __PTRDIFF_TYPE__ long int 23 | #endif 24 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 25 | 26 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || (defined(__cplusplus) && __cplusplus >= 201103L) 27 | typedef struct 28 | { 29 | long long __max_align_ll __attribute__((__aligned__(__alignof__(long long)))); 30 | long double __max_align_ld __attribute__((__aligned__(__alignof__(long double)))); 31 | #ifdef __i386__ 32 | __float128 __max_align_f128 __attribute__((__aligned__(__alignof(__float128)))); 33 | #endif 34 | } max_align_t; 35 | 36 | #endif 37 | 38 | #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) 39 | -------------------------------------------------------------------------------- /include/stdio.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/include/stdio.h -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/include/string.h -------------------------------------------------------------------------------- /kernel/Critical.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace Critical 6 | { 7 | CriticalSectionData *Enter() 8 | { 9 | CriticalSectionData *Data = new CriticalSectionData; 10 | Data->EnableInterrupts = InterruptsEnabled(); 11 | Data->CriticalLock.AttemptingToGet = 0; 12 | Data->CriticalLock.Count = 0; 13 | Data->CriticalLock.CurrentHolder = 0; 14 | Data->CriticalLock.LockData = 0; 15 | Data->CriticalLock.LockName = 0; 16 | LOCK(Data->CriticalLock); 17 | CLI; 18 | return Data; 19 | } 20 | 21 | void Leave(CriticalSectionData *Data) 22 | { 23 | UNLOCK(Data->CriticalLock); 24 | if (Data->EnableInterrupts) 25 | STI; 26 | delete Data; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /kernel/Error.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cpu/smp.hpp" 4 | 5 | long SetError(long ErrorCode) 6 | { 7 | debug("Setting error code to %d", ErrorCode); 8 | return CurrentCPU->ErrorCode = ErrorCode; 9 | } 10 | 11 | long GetError() 12 | { 13 | debug("Getting error code %d", CurrentCPU->ErrorCode); 14 | return CurrentCPU->ErrorCode; 15 | } 16 | -------------------------------------------------------------------------------- /kernel/Lock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "drivers/serial.h" 5 | 6 | static int timeout = 0; 7 | 8 | // TODO: complete implementation 9 | extern "C" void deadlock_handler(LOCK *lock) 10 | { 11 | uint32_t x, y; 12 | x = CurrentDisplay->CurrentFont->GetFontSize().Width; 13 | y = CurrentDisplay->CurrentFont->GetFontSize().Height; 14 | CurrentDisplay->ResetPrintPosition(); 15 | CurrentDisplay->SetPrintColor(0x450402); 16 | printf("Potential deadlock in lock '%s' held by '%s'", lock->LockName, lock->CurrentHolder); 17 | CurrentDisplay->ResetPrintColor(); 18 | CurrentDisplay->SetPrintLocation(x, y); 19 | serial_write_text(COM1, (char *)"Potential deadlock in lock '"); 20 | serial_write_text(COM1, (char *)lock->LockName); 21 | serial_write_text(COM1, (char *)"' held by '"); 22 | serial_write_text(COM1, (char *)lock->CurrentHolder); 23 | serial_write_text(COM1, (char *)"'\nAttempting to get lock from "); 24 | serial_write_text(COM1, (char *)lock->AttemptingToGet); 25 | write_serial(COM1, '\n'); 26 | timeout++; 27 | if (timeout == 20) 28 | { 29 | timeout = 0; 30 | spinlock_unlock(&lock->LockData); 31 | lock->Count--; 32 | } 33 | } 34 | 35 | extern "C" unsigned long api_redirect_debug_write(int type, char *message, const char *file, int line, const char *function, ...) 36 | { 37 | return debug(message); 38 | } 39 | -------------------------------------------------------------------------------- /kernel/StackGuard.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef STACK_CHK_GUARD_VALUE 5 | #if UINTPTR_MAX == UINT32_MAX 6 | #define STACK_CHK_GUARD_VALUE 0x25F6CC8D 7 | #else 8 | #define STACK_CHK_GUARD_VALUE 0xBADFE2EC255A8572 9 | #endif 10 | #endif 11 | 12 | __attribute__((weak)) uintptr_t __stack_chk_guard = 0; 13 | 14 | __attribute__((weak)) uintptr_t __stack_chk_guard_init(void) 15 | { 16 | return STACK_CHK_GUARD_VALUE; 17 | } 18 | 19 | static void __attribute__((constructor, no_stack_protector)) __construct_stk_chk_guard() 20 | { 21 | if (__stack_chk_guard == 0) 22 | __stack_chk_guard = __stack_chk_guard_init(); 23 | } 24 | 25 | // https://opensource.apple.com/source/xnu/xnu-1504.7.4/libkern/stack_protector.c.auto.html 26 | // static void __guard_setup(void) __attribute__((constructor)); 27 | 28 | // static void __guard_setup(void) 29 | // { 30 | // read_random(__stack_chk_guard, sizeof(__stack_chk_guard)); 31 | // } 32 | 33 | __attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void) 34 | { 35 | panic("Stack smashing detected!", false); 36 | CPU_STOP; 37 | } 38 | 39 | // https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c 40 | __attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void) 41 | { 42 | panic("Buffer overflow detected!", false); 43 | CPU_STOP; 44 | } 45 | -------------------------------------------------------------------------------- /kernel/arch/aarch64/boot/aarch64-boot.S: -------------------------------------------------------------------------------- 1 | // https://wiki.osdev.org/Raspberry_Pi_Bare_Bones 2 | 3 | .section ".text.boot" 4 | 5 | .global _start 6 | .org 0x80000 7 | _start: 8 | ldr x5, =_start 9 | mov sp, x5 10 | 11 | ldr x5, =_kernel_data_end 12 | ldr w6, =_kernel_bss_size 13 | 1: cbz w6, 2f 14 | str xzr, [x5], #8 15 | sub w6, w6, #1 16 | cbnz w6, 1b 17 | 2: bl kernel_main_aarch64 18 | halt: 19 | wfe 20 | b halt 21 | -------------------------------------------------------------------------------- /kernel/arch/aarch64/cpu/acpi.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /kernel/arch/aarch64/cpu/apic.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /kernel/arch/aarch64/cpu/cpuid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | EXTERNC bool cpu_feature(enum CPU_FEATURE feature); 6 | -------------------------------------------------------------------------------- /kernel/arch/aarch64/cpu/gdt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define GDT_KERNEL_DATA 0x0 4 | #define GDT_KERNEL_CODE 0x0 5 | #define GDT_USER_DATA 0x0 6 | #define GDT_USER_CODE 0x0 7 | -------------------------------------------------------------------------------- /kernel/arch/aarch64/cpu/idt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | EXTERNC void SetKernelPageTableAddress(void *Address); -------------------------------------------------------------------------------- /kernel/arch/aarch64/cpu/smp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "../kernel.h" 5 | #include "acpi.hpp" 6 | #include "idt.h" 7 | 8 | #define CPU_DATA_CHECKSUM 0xdeadda7a 9 | 10 | struct CPUData 11 | { 12 | uint64_t ID; 13 | CR3 PageTable; 14 | GlobalDescriptorTableDescriptor GDT; 15 | InterruptDescriptorTableDescriptor IDT; 16 | TaskStateSegment TSS; 17 | 18 | PCB *CurrentProcess; 19 | TCB *CurrentThread; 20 | 21 | long ErrorCode; 22 | bool IsActive; 23 | long Checksum; 24 | 25 | uint8_t Stack[STACK_SIZE] __attribute__((aligned(PAGE_SIZE))); 26 | } __attribute__((packed)); 27 | 28 | namespace SymmetricMultiprocessing 29 | { 30 | class SMP 31 | { 32 | public: 33 | SMP(); 34 | ~SMP(); 35 | }; 36 | } 37 | 38 | extern SymmetricMultiprocessing::SMP *smp; 39 | 40 | #define MAX_CPU 256 41 | 42 | int GetCurrentCPUID(); 43 | 44 | CPUData *GetCurrentCPU(); 45 | 46 | CPUData *GetCPU(uint64_t id); 47 | 48 | #define CurrentCPU GetCurrentCPU() 49 | -------------------------------------------------------------------------------- /kernel/arch/amd64/LockAssembly.S: -------------------------------------------------------------------------------- 1 | # https://en.wikipedia.org/wiki/Spinlock 2 | 3 | .text 4 | .global spinlock_lock 5 | .global spinlock_unlock 6 | 7 | # spinlock_lock(uint32_t *lock) 8 | spinlock_lock: 9 | xorq %rax,%rax 10 | lock btsl $0,(%rdi) 11 | jc spin 12 | ret 13 | spin: 14 | incq %rax 15 | cmpq $0x10000000,%rax 16 | je deadlock 17 | pause 18 | testl $1,(%rdi) 19 | jnz spin 20 | jmp spinlock_lock 21 | 22 | # spinlock_unlock(uint32_t *lock) 23 | spinlock_unlock: 24 | lock btrl $0,(%rdi) 25 | ret 26 | 27 | # deadlock_handler(LOCK *lock) 28 | .extern deadlock_handler 29 | 30 | deadlock: 31 | pushq %rdi 32 | pushq %rdi 33 | xorq %rax,%rax 34 | call deadlock_handler 35 | popq %rdi 36 | popq %rdi 37 | jmp spin 38 | 39 | .global spinlock_check_and_lock 40 | 41 | # spinlock_check_and_lock(uint32_t *lock); 42 | spinlock_check_and_lock: 43 | xorl %eax,%eax 44 | lock btsl $0,(%rdi) 45 | setcb %al 46 | ret 47 | 48 | .global spinlock_with_timeout 49 | 50 | # spinlock_with_timeout(uint32_t *lock, uint64_t iterations); 51 | spinlock_with_timeout: 52 | xorq %rax,%rax 53 | spin_timeout: 54 | incq %rax 55 | lock btsl $0,(%rdi) 56 | setcb %bl 57 | cmpb $0,%bl 58 | je got_lock 59 | cmpq %rsi,%rax 60 | je timed_out 61 | pause 62 | jmp spin_timeout 63 | got_lock: 64 | movq $1,%rax 65 | ret 66 | timed_out: 67 | xorq %rax,%rax 68 | ret 69 | -------------------------------------------------------------------------------- /kernel/arch/amd64/SystemCallsHelper.asm: -------------------------------------------------------------------------------- 1 | ; https://supercip971.github.io/02-wingos-syscalls.html 2 | 3 | ; +---+--------------------+ 4 | ; | r | Register(s) | 5 | ; +---+--------------------+ 6 | ; | a | %eax, %ax, %al | 7 | ; | b | %ebx, %bx, %bl | 8 | ; | c | %ecx, %cx, %cl | 9 | ; | d | %edx, %dx, %dl | 10 | ; | S | %esi, %si | 11 | ; | D | %edi, %di | 12 | ; +---+--------------------+ 13 | 14 | [BITS 64] 15 | ALIGN 4096 16 | extern syscall_handler 17 | global syscall_handle 18 | syscall_handle: 19 | swapgs 20 | mov [gs:0x8], rsp 21 | ; mov rsp, [gs:0x0] 22 | 23 | push qword 0x1b ; user data 24 | push qword [gs:0x8] ; saved stack 25 | push r11 ; saved rflags 26 | push qword 0x23 ; user code 27 | push rcx ; current IP 28 | 29 | cld 30 | push rax 31 | push rbx 32 | push rcx 33 | push rdx 34 | push rsi 35 | push rdi 36 | push rbp 37 | push r8 38 | push r9 39 | push r10 40 | push r11 41 | push r12 42 | push r13 43 | push r14 44 | push r15 45 | 46 | mov rdi, rsp 47 | mov rbp, 0 48 | call syscall_handler 49 | 50 | pop r15 51 | pop r14 52 | pop r13 53 | pop r12 54 | pop r11 55 | pop r10 56 | pop r9 57 | pop r8 58 | pop rbp 59 | pop rdi 60 | pop rsi 61 | pop rdx 62 | pop rcx 63 | pop rbx 64 | 65 | mov rsp, [gs:0x8] 66 | swapgs 67 | sti 68 | o64 sysret 69 | -------------------------------------------------------------------------------- /kernel/arch/amd64/boot/limine.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | EXTERNC bool init_limine(GlobalBootParams *params, bool Second); 6 | -------------------------------------------------------------------------------- /kernel/arch/amd64/cpu/cpuid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | /* DEPRECATED: You should use the header that comes with GCC instead. */ 7 | 8 | enum cpuid_requests 9 | { 10 | CPUID_GETVENDORSTRING, 11 | CPUID_GETFEATURES, 12 | CPUID_GETTLB, 13 | CPUID_GETSERIAL, 14 | 15 | CPUID_INTELEXTENDED = 0x80000000, 16 | CPUID_INTELFEATURES, 17 | CPUID_INTELBRANDSTRING, 18 | CPUID_INTELBRANDSTRINGMORE, 19 | CPUID_INTELBRANDSTRINGEND, 20 | }; 21 | 22 | // https://wiki.osdev.org/CPUID 23 | 24 | static inline int cpuid_string(int code, int where[4]) 25 | { 26 | asm volatile("cpuid" 27 | : "=a"(*where), "=b"(*(where + 0)), 28 | "=d"(*(where + 1)), "=c"(*(where + 2)) 29 | : "a"(code)); 30 | return (int)where[0]; 31 | } 32 | 33 | /** 34 | * @brief Check if the specified CPU feature is supported. 35 | * 36 | * @param feature The CPU feature to check. 37 | * @return bool 38 | */ 39 | EXTERNC bool cpu_feature(enum CPU_FEATURE feature); 40 | EXTERNC char *cpu_get_info(); 41 | -------------------------------------------------------------------------------- /kernel/arch/amd64/cpu/fxsr.asm: -------------------------------------------------------------------------------- 1 | [bits 64] 2 | 3 | [global _amd64_fxsave] 4 | _amd64_fxsave: 5 | fxsave [rdi] 6 | ret 7 | 8 | [global _amd64_fxrstor] 9 | _amd64_fxrstor: 10 | fxrstor [rdi] 11 | ret 12 | -------------------------------------------------------------------------------- /kernel/arch/amd64/cpu/gdt.h: -------------------------------------------------------------------------------- 1 | #ifndef __FENNIX_KERNEL_GDT_H__ 2 | #define __FENNIX_KERNEL_GDT_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define GDT_KERNEL_CODE offsetof(GlobalDescriptorTableEntries, Code) 8 | #define GDT_KERNEL_DATA offsetof(GlobalDescriptorTableEntries, Data) 9 | #define GDT_USER_DATA (offsetof(GlobalDescriptorTableEntries, UserData) | 3) 10 | #define GDT_USER_CODE (offsetof(GlobalDescriptorTableEntries, UserCode) | 3) 11 | #define GDT_TSS (offsetof(GlobalDescriptorTableEntries, TaskStateSegment) | 3) 12 | 13 | extern GlobalDescriptorTableDescriptor gdt; 14 | extern TaskStateSegment *tss; 15 | EXTERNC void init_gdt(); 16 | EXTERNC void init_tss(); 17 | EXTERNC void CreateNewTSS(int CPUCore); 18 | 19 | #endif // !__FENNIX_KERNEL_GDT_H__ 20 | -------------------------------------------------------------------------------- /kernel/arch/amd64/cpu/idt.h: -------------------------------------------------------------------------------- 1 | #ifndef __FENNIX_KERNEL_IDT_H__ 2 | #define __FENNIX_KERNEL_IDT_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "cpuid.h" 9 | 10 | extern InterruptDescriptorTableDescriptor idtr; 11 | 12 | EXTERNC void SetKernelPageTableAddress(void *Address); 13 | EXTERNC void set_idt_entry(uint8_t idt, void (*handler)(), uint64_t ist, uint64_t ring); 14 | EXTERNC void init_idt(); 15 | 16 | #endif // !__FENNIX_KERNEL_IDT_H__ 17 | -------------------------------------------------------------------------------- /kernel/arch/amd64/cpu/smp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "../kernel.h" 5 | #include "acpi.hpp" 6 | #include "idt.h" 7 | 8 | #define CPU_DATA_CHECKSUM 0xdeadda7a 9 | 10 | struct CPUData 11 | { 12 | uint64_t ID; 13 | ACPI::MADT::LocalAPIC LAPIC; 14 | CR3 PageTable; 15 | GlobalDescriptorTableDescriptor GDT; 16 | InterruptDescriptorTableDescriptor IDT; 17 | TaskStateSegment TSS; 18 | 19 | PCB *CurrentProcess; 20 | TCB *CurrentThread; 21 | 22 | long ErrorCode; 23 | bool IsActive; 24 | long Checksum; 25 | 26 | uint8_t Stack[STACK_SIZE] __attribute__((aligned(PAGE_SIZE))); 27 | } __attribute__((packed)); 28 | 29 | namespace SymmetricMultiprocessing 30 | { 31 | class SMP 32 | { 33 | public: 34 | SMP(); 35 | ~SMP(); 36 | }; 37 | } 38 | 39 | extern SymmetricMultiprocessing::SMP *smp; 40 | 41 | #define MAX_CPU 256 42 | 43 | int GetCurrentCPUID(); 44 | 45 | CPUData *GetCurrentCPU(); 46 | 47 | CPUData *GetCPU(uint64_t id); 48 | 49 | #define CurrentCPU GetCurrentCPU() 50 | -------------------------------------------------------------------------------- /kernel/arch/i686/LockAssembly.asm: -------------------------------------------------------------------------------- 1 | [bits 64] 2 | ; https://en.wikipedia.org/wiki/Spinlock 3 | section .text 4 | global spinlock_lock 5 | global spinlock_unlock 6 | 7 | ; spinlock_lock(uint32_t *lock) 8 | spinlock_lock: 9 | xor rax, rax 10 | lock bts dword [rdi], 0 11 | jc spin 12 | ret 13 | spin: 14 | inc rax 15 | cmp rax, 0x10000000 16 | je deadlock 17 | pause 18 | test dword [rdi], 1 19 | jnz spin 20 | jmp spinlock_lock 21 | 22 | ; spinlock_unlock(uint32_t *lock) 23 | spinlock_unlock: 24 | lock btr dword [rdi], 0 25 | ret 26 | 27 | ; deadlock_handler(LOCK *lock) 28 | extern deadlock_handler 29 | 30 | deadlock: 31 | push rdi 32 | push rdi 33 | xor rax, rax 34 | call deadlock_handler 35 | pop rdi 36 | pop rdi 37 | jmp spin 38 | 39 | global spinlock_check_and_lock 40 | 41 | ; spinlock_check_and_lock(uint32_t *lock); 42 | spinlock_check_and_lock: 43 | xor eax, eax 44 | lock bts dword [rdi], 0 45 | setc al 46 | ret 47 | 48 | global spinlock_with_timeout 49 | 50 | ; spinlock_with_timeout(uint32_t *lock, uint64_t iterations); 51 | spinlock_with_timeout: 52 | xor rax, rax 53 | spin_timeout: 54 | inc rax 55 | lock bts dword [rdi], 0 56 | setc bl 57 | cmp bl, 0 58 | je got_lock 59 | cmp rax, rsi 60 | je timed_out 61 | pause 62 | jmp spin_timeout 63 | got_lock: 64 | mov rax, 1 65 | ret 66 | timed_out: 67 | xor rax, rax 68 | ret 69 | -------------------------------------------------------------------------------- /kernel/arch/i686/SystemCallsHelper.asm: -------------------------------------------------------------------------------- 1 | ; https://supercip971.github.io/02-wingos-syscalls.html 2 | 3 | ; +---+--------------------+ 4 | ; | r | Register(s) | 5 | ; +---+--------------------+ 6 | ; | a | %eax, %ax, %al | 7 | ; | b | %ebx, %bx, %bl | 8 | ; | c | %ecx, %cx, %cl | 9 | ; | d | %edx, %dx, %dl | 10 | ; | S | %esi, %si | 11 | ; | D | %edi, %di | 12 | ; +---+--------------------+ 13 | 14 | [BITS 64] 15 | ALIGN 4096 16 | extern syscall_handler 17 | global syscall_handle 18 | syscall_handle: 19 | swapgs 20 | mov [gs:0x8], rsp 21 | ; mov rsp, [gs:0x0] 22 | 23 | push qword 0x1b ; user data 24 | push qword [gs:0x8] ; saved stack 25 | push r11 ; saved rflags 26 | push qword 0x23 ; user code 27 | push rcx ; current IP 28 | 29 | cld 30 | push rax 31 | push rbx 32 | push rcx 33 | push rdx 34 | push rsi 35 | push rdi 36 | push rbp 37 | push r8 38 | push r9 39 | push r10 40 | push r11 41 | push r12 42 | push r13 43 | push r14 44 | push r15 45 | 46 | mov rdi, rsp 47 | mov rbp, 0 48 | call syscall_handler 49 | 50 | pop r15 51 | pop r14 52 | pop r13 53 | pop r12 54 | pop r11 55 | pop r10 56 | pop r9 57 | pop r8 58 | pop rbp 59 | pop rdi 60 | pop rsi 61 | pop rdx 62 | pop rcx 63 | pop rbx 64 | 65 | mov rsp, [gs:0x8] 66 | swapgs 67 | sti 68 | o64 sysret 69 | -------------------------------------------------------------------------------- /kernel/arch/i686/cpu/cpuid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | /* DEPRECATED: You should use the header that comes with GCC instead. */ 7 | 8 | enum cpuid_requests 9 | { 10 | CPUID_GETVENDORSTRING, 11 | CPUID_GETFEATURES, 12 | CPUID_GETTLB, 13 | CPUID_GETSERIAL, 14 | 15 | CPUID_INTELEXTENDED = 0x80000000, 16 | CPUID_INTELFEATURES, 17 | CPUID_INTELBRANDSTRING, 18 | CPUID_INTELBRANDSTRINGMORE, 19 | CPUID_INTELBRANDSTRINGEND, 20 | }; 21 | 22 | // https://wiki.osdev.org/CPUID 23 | 24 | static inline int cpuid_string(int code, int where[4]) 25 | { 26 | #if defined(__amd64__) || defined(__i386__) 27 | asm volatile("cpuid" 28 | : "=a"(*where), "=b"(*(where + 0)), 29 | "=d"(*(where + 1)), "=c"(*(where + 2)) 30 | : "a"(code)); 31 | #endif 32 | return (int)where[0]; 33 | } 34 | 35 | /** 36 | * @brief Check if the specified CPU feature is supported. 37 | * 38 | * @param feature The CPU feature to check. 39 | * @return bool 40 | */ 41 | EXTERNC bool cpu_feature(enum CPU_FEATURE feature); 42 | EXTERNC char *cpu_get_info(); 43 | -------------------------------------------------------------------------------- /kernel/arch/i686/cpu/fxsr.asm: -------------------------------------------------------------------------------- 1 | [bits 32] 2 | 3 | [global _i686_fxsave] 4 | _i686_fxsave: 5 | fxsave [edi] 6 | ret 7 | 8 | [global _i686_fxrstor] 9 | _i686_fxrstor: 10 | fxrstor [edi] 11 | ret 12 | -------------------------------------------------------------------------------- /kernel/arch/i686/cpu/gdt.h: -------------------------------------------------------------------------------- 1 | #ifndef __FENNIX_KERNEL_GDT_H__ 2 | #define __FENNIX_KERNEL_GDT_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define GDT_KERNEL_CODE offsetof(GlobalDescriptorTableEntries, Code) 8 | #define GDT_KERNEL_DATA offsetof(GlobalDescriptorTableEntries, Data) 9 | #define GDT_USER_DATA (offsetof(GlobalDescriptorTableEntries, UserData) | 3) 10 | #define GDT_USER_CODE (offsetof(GlobalDescriptorTableEntries, UserCode) | 3) 11 | #define GDT_TSS (offsetof(GlobalDescriptorTableEntries, TaskStateSegment) | 3) 12 | 13 | extern GlobalDescriptorTableDescriptor gdt; 14 | extern TaskStateSegment *tss; 15 | EXTERNC void init_gdt(); 16 | EXTERNC void init_tss(); 17 | EXTERNC void CreateNewTSS(int CPUCore); 18 | 19 | #endif // !__FENNIX_KERNEL_GDT_H__ 20 | -------------------------------------------------------------------------------- /kernel/arch/i686/cpu/idt.h: -------------------------------------------------------------------------------- 1 | #ifndef __FENNIX_KERNEL_IDT_H__ 2 | #define __FENNIX_KERNEL_IDT_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "cpuid.h" 9 | 10 | extern InterruptDescriptorTableDescriptor idtr; 11 | 12 | EXTERNC void SetKernelPageTableAddress(void *Address); 13 | EXTERNC void set_idt_entry(uint8_t idt, void (*handler)(), uint64_t ist, uint64_t ring); 14 | EXTERNC void init_idt(); 15 | 16 | #endif // !__FENNIX_KERNEL_IDT_H__ 17 | -------------------------------------------------------------------------------- /kernel/arch/i686/cpu/smp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "../kernel.h" 5 | #include "acpi.hpp" 6 | #include "idt.h" 7 | 8 | #define CPU_DATA_CHECKSUM 0xdeadda7a 9 | 10 | struct CPUData 11 | { 12 | uint64_t ID; 13 | ACPI::MADT::LocalAPIC LAPIC; 14 | CR3 PageTable; 15 | GlobalDescriptorTableDescriptor GDT; 16 | InterruptDescriptorTableDescriptor IDT; 17 | TaskStateSegment TSS; 18 | 19 | PCB *CurrentProcess; 20 | TCB *CurrentThread; 21 | 22 | long ErrorCode; 23 | unsigned int Checksum = CPU_DATA_CHECKSUM; 24 | 25 | uint8_t Stack[STACK_SIZE] __attribute__((aligned(PAGE_SIZE))); 26 | } __attribute__((packed)); 27 | 28 | namespace SymmetricMultiprocessing 29 | { 30 | class SMP 31 | { 32 | public: 33 | SMP(); 34 | ~SMP(); 35 | }; 36 | } 37 | 38 | extern SymmetricMultiprocessing::SMP *smp; 39 | 40 | #define MAX_CPU 256 41 | extern CPUData CPUs[]; 42 | 43 | int GetCurrentCPUID(); 44 | 45 | static CPUData *GetCurrentCPU() 46 | { 47 | uint64_t ret = GetCurrentCPUID(); 48 | 49 | if (CPUs[ret].Checksum != CPU_DATA_CHECKSUM) 50 | { 51 | // TODO: i think somehow i messed this up somehere... i'll figure it out later... but now i will return the first cpu 52 | err("CPU %d data is corrupted!", ret); 53 | return &CPUs[0]; 54 | } 55 | return &CPUs[ret]; 56 | } 57 | 58 | static CPUData *GetCPU(uint64_t id) { return &CPUs[id]; } 59 | 60 | #define CurrentCPU GetCurrentCPU() 61 | -------------------------------------------------------------------------------- /kernel/cpu/acpi.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__amd64__) 4 | #include "../arch/amd64/cpu/acpi.hpp" 5 | #elif defined(__i386__) 6 | #include "../arch/i686/cpu/acpi.hpp" 7 | #elif defined(__aarch64__) 8 | #include "../arch/aarch64/cpu/acpi.hpp" 9 | #endif 10 | -------------------------------------------------------------------------------- /kernel/cpu/apic.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__amd64__) 4 | #include "../arch/amd64/cpu/apic.hpp" 5 | #elif defined(__i386__) 6 | #include "../arch/i686/cpu/apic.hpp" 7 | #elif defined(__aarch64__) 8 | #include "../arch/aarch64/cpu/apic.hpp" 9 | #endif 10 | -------------------------------------------------------------------------------- /kernel/cpu/cpuid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__amd64__) 4 | #include "../arch/amd64/cpu/cpuid.h" 5 | #elif defined(__i386__) 6 | #include "../arch/i686/cpu/cpuid.h" 7 | #elif defined(__aarch64__) 8 | #include "../arch/aarch64/cpu/cpuid.h" 9 | #endif 10 | -------------------------------------------------------------------------------- /kernel/cpu/fxsr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__amd64__) 4 | extern "C" void _amd64_fxsave(char *Buffer); 5 | extern "C" void _amd64_fxrstor(char *Buffer); 6 | void _fxsave(char *Buffer) { _amd64_fxsave(Buffer); } 7 | void _fxrstor(char *Buffer) { _amd64_fxrstor(Buffer); } 8 | #elif defined(__i386__) 9 | extern "C" void _i686_fxsave(char *Buffer); 10 | extern "C" void _i686_fxrstor(char *Buffer); 11 | void _fxsave(char *Buffer) { _i686_fxsave(Buffer); } 12 | void _fxrstor(char *Buffer) { _i686_fxrstor(Buffer); } 13 | #elif defined(__aarch64__) 14 | void _fxsave(char *Buffer) {} 15 | void _fxrstor(char *Buffer) {} 16 | #endif 17 | -------------------------------------------------------------------------------- /kernel/cpu/gdt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__amd64__) 4 | #include "../arch/amd64/cpu/gdt.h" 5 | #elif defined(__i386__) 6 | #include "../arch/i686/cpu/gdt.h" 7 | #elif defined(__aarch64__) 8 | #include "../arch/aarch64/cpu/gdt.h" 9 | #endif 10 | -------------------------------------------------------------------------------- /kernel/cpu/idt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__amd64__) 4 | #include "../arch/amd64/cpu/idt.h" 5 | #elif defined(__i386__) 6 | #include "../arch/i686/cpu/idt.h" 7 | #elif defined(__aarch64__) 8 | #include "../arch/aarch64/cpu/idt.h" 9 | #endif 10 | -------------------------------------------------------------------------------- /kernel/cpu/smp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__amd64__) 4 | #include "../arch/amd64/cpu/smp.hpp" 5 | #elif defined(__i386__) 6 | #include "../arch/i686/cpu/smp.hpp" 7 | #elif defined(__aarch64__) 8 | #include "../arch/aarch64/cpu/smp.hpp" 9 | #endif 10 | -------------------------------------------------------------------------------- /kernel/cpuspeed.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "timer.h" 6 | 7 | extern "C" unsigned long readTSC(); 8 | 9 | namespace CPUSpeed 10 | { 11 | class cpuspeed 12 | { 13 | private: 14 | unsigned long CurrentTSC, FinalTSC = 0; 15 | 16 | public: 17 | uint64_t GetCPUSpeedHz() { return FinalTSC / 2000 / 10; } 18 | uint64_t GetCPUSpeedKHz() { return FinalTSC / 2000 / 100; } 19 | uint64_t GetCPUSpeedMHz() { return FinalTSC / 2000 / 1000; } 20 | 21 | cpuspeed() 22 | { 23 | EnterCriticalSection; 24 | for (int i = 0; i < 200; i++) 25 | { 26 | CurrentTSC = tsc(); 27 | msleep(1); // This should be changed to a more accurate method. 28 | FinalTSC += tsc() - CurrentTSC; 29 | } 30 | LeaveCriticalSection; 31 | } 32 | ~cpuspeed() {} 33 | }; 34 | } -------------------------------------------------------------------------------- /kernel/driver.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Driver 7 | { 8 | class KernelDriver 9 | { 10 | private: 11 | void *DrvMgrProc; 12 | void *DrvMgrThrd; 13 | 14 | public: 15 | uint64_t LoadKernelDriverFromFile(FileSystem::FileSystemNode *Node); 16 | KernelDriver(); 17 | ~KernelDriver(); 18 | }; 19 | } 20 | 21 | extern Driver::KernelDriver *kdrv; 22 | -------------------------------------------------------------------------------- /kernel/drivers/keyboard.cpp: -------------------------------------------------------------------------------- 1 | #include "keyboard.hpp" 2 | 3 | #include "../kernel.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | PS2Keyboard::PS2KeyboardDriver *ps2keyboard = nullptr; 11 | 12 | namespace PS2Keyboard 13 | { 14 | static uint8_t LastSC; 15 | 16 | extern "C" 17 | { 18 | InterruptHandler(PS2KeyboardInterruptHandler) 19 | { 20 | uint8_t scanCode = inb(0x60); 21 | LastSC = scanCode; 22 | if (scanCode == 0x3B) 23 | ShowRecoveryScreen = true; 24 | } 25 | } 26 | 27 | uint8_t PS2KeyboardDriver::GetLastScanCode() { return LastSC; } 28 | 29 | uint8_t PS2KeyboardDriver::WaitScanCode() 30 | { 31 | LastSC = 0x0; 32 | while (!LastSC) 33 | HLT; 34 | return LastSC; 35 | } 36 | 37 | PS2KeyboardDriver::PS2KeyboardDriver() 38 | { 39 | RegisterInterrupt(PS2KeyboardInterruptHandler, IRQ1, true); 40 | 41 | while (inb(0x64) & 0x1) 42 | inb(0x60); 43 | 44 | outb(0x64, 0xAE); 45 | outb(0x64, 0x20); 46 | uint8_t ret = (inb(0x60) | 1) & ~0x10; 47 | outb(0x64, 0x60); 48 | outb(0x60, ret); 49 | outb(0x60, 0xF4); 50 | } 51 | 52 | PS2KeyboardDriver::~PS2KeyboardDriver() 53 | { 54 | warn("Unloading default keyboard driver is not supported."); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /kernel/drivers/keyboard.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace PS2Keyboard 4 | { 5 | class PS2KeyboardDriver 6 | { 7 | public: 8 | unsigned char GetLastScanCode(); 9 | unsigned char WaitScanCode(); 10 | PS2KeyboardDriver(); 11 | ~PS2KeyboardDriver(); 12 | }; 13 | } 14 | 15 | extern PS2Keyboard::PS2KeyboardDriver *ps2keyboard; 16 | -------------------------------------------------------------------------------- /kernel/drivers/mouse.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace PS2Mouse 5 | { 6 | enum MouseButton 7 | { 8 | MouseNone, 9 | Right, 10 | Middle, 11 | Left 12 | }; 13 | 14 | struct MouseInfo 15 | { 16 | MouseButton Buttons; 17 | long X; 18 | long Y; 19 | }; 20 | 21 | class PS2MouseDriver 22 | { 23 | private: 24 | enum Config 25 | { 26 | READ_CONFIG = 0x20, 27 | WRITE_CONFIG = 0x60 28 | }; 29 | 30 | enum Ports 31 | { 32 | DATA = 0x60, 33 | STATUS = 0x64, 34 | COMMAND = 0x64, 35 | }; 36 | 37 | enum State 38 | { 39 | OUTPUT_FULL = (1 << 0), 40 | INPUT_FULL = (1 << 1), 41 | MOUSE_BYTE = (1 << 5) 42 | }; 43 | 44 | void WaitRead() 45 | { 46 | uint64_t Timeout = 100000; 47 | while (Timeout--) 48 | if (inb(Ports::STATUS) & State::OUTPUT_FULL) 49 | return; 50 | } 51 | 52 | void WaitWrite() 53 | { 54 | uint64_t Timeout = 100000; 55 | while (Timeout--) 56 | if ((inb(Ports::STATUS) & State::INPUT_FULL) == 0) 57 | return; 58 | } 59 | 60 | void Write(uint16_t Port, uint8_t Value) 61 | { 62 | WaitWrite(); 63 | outb(Port, Value); 64 | } 65 | 66 | uint8_t Read() 67 | { 68 | WaitRead(); 69 | return inb(Ports::DATA); 70 | } 71 | 72 | public: 73 | MouseInfo GetMouseInfo(); 74 | PS2MouseDriver(); 75 | ~PS2MouseDriver(); 76 | }; 77 | } 78 | 79 | extern PS2Mouse::PS2MouseDriver *ps2mouse; 80 | -------------------------------------------------------------------------------- /kernel/drivers/network/AMDPCNET/AMDPCNET.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../../network/NetworkController.hpp" 6 | #include "../../../pci.h" 7 | 8 | namespace AMDPCNET 9 | { 10 | class NetworkInterfaceController : public NetworkInterfaceManager::DeviceInterface, public DriverInterrupts::Register 11 | { 12 | private: 13 | struct BARData 14 | { 15 | uint8_t Type; 16 | uint16_t IOBase; 17 | uint32_t MemoryBase; 18 | }; 19 | 20 | char *RXBuffer; 21 | int TXCurrent; 22 | InternetProtocol4 IP; 23 | uint32_t CurrentPacket; 24 | BARData BAR; 25 | 26 | void WriteRAP32(uint32_t Value); 27 | void WriteRAP16(uint16_t Value); 28 | uint32_t ReadCSR32(uint32_t CSR); 29 | uint16_t ReadCSR16(uint16_t CSR); 30 | void WriteCSR32(uint32_t CSR, uint32_t Value); 31 | void WriteCSR16(uint16_t CSR, uint16_t Value); 32 | 33 | public: 34 | MediaAccessControl GetMAC(); 35 | InternetProtocol4 GetIP(); 36 | void SetIP(InternetProtocol4 IP); 37 | 38 | NetworkInterfaceController(PCI::PCIDeviceHeader *PCIBaseAddress); 39 | ~NetworkInterfaceController(); 40 | 41 | void Send(uint8_t *Data, uint64_t Length); 42 | void Receive(); 43 | 44 | void HandleInterrupt(); 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /kernel/drivers/network/Intel8254x/Intel8254x.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../../network/NetworkController.hpp" 6 | #include "../../../pci.h" 7 | 8 | namespace Intel8254x 9 | { 10 | class NetworkInterfaceController : public NetworkInterfaceManager::DeviceInterface, public DriverInterrupts::Register 11 | { 12 | private: 13 | struct BARData 14 | { 15 | uint8_t Type; 16 | uint16_t IOBase; 17 | uint32_t MemoryBase; 18 | }; 19 | 20 | InternetProtocol4 IP; 21 | BARData BAR; 22 | 23 | public: 24 | MediaAccessControl GetMAC(); 25 | InternetProtocol4 GetIP(); 26 | void SetIP(InternetProtocol4 IP); 27 | 28 | NetworkInterfaceController(PCI::PCIDeviceHeader *PCIBaseAddress); 29 | ~NetworkInterfaceController(); 30 | 31 | void Send(uint8_t *Data, uint64_t Length); 32 | void Receive(); 33 | 34 | virtual void HandleInterrupt(); 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /kernel/drivers/network/RTL8169/RTL8169.cpp: -------------------------------------------------------------------------------- 1 | #include "RTL8169.hpp" 2 | 3 | /* https://wiki.osdev.org/RTL8169 */ 4 | 5 | namespace RTL8169 6 | { 7 | MediaAccessControl NetworkInterfaceController::GetMAC() 8 | { 9 | return MediaAccessControl(); 10 | } 11 | 12 | InternetProtocol4 NetworkInterfaceController::GetIP() 13 | { 14 | return IP; 15 | } 16 | 17 | void NetworkInterfaceController::SetIP(InternetProtocol4 IP) 18 | { 19 | this->IP = IP; 20 | } 21 | 22 | NetworkInterfaceController::NetworkInterfaceController(PCI::PCIDeviceHeader *PCIBaseAddress) : DriverInterrupts::Register(((PCI::PCIHeader0 *)PCIBaseAddress)->InterruptLine + IRQ0) 23 | { 24 | if (PCIBaseAddress->VendorID != 0x10EC && PCIBaseAddress->DeviceID != 0x8169) 25 | { 26 | netdbg("Not a RTL-8169 network card"); 27 | return; 28 | } 29 | netdbg("Found %s network card", PCI::GetDeviceName(PCIBaseAddress->VendorID, PCIBaseAddress->DeviceID)); 30 | memcpy(this->Name, "RTL-8169 Network Driver", sizeof(this->Name)); 31 | 32 | uint32_t PCIBAR = ((PCI::PCIHeader0 *)PCIBaseAddress)->BAR0; 33 | BAR.Type = PCIBAR & 1; 34 | BAR.IOBase = PCIBAR & (~3); 35 | BAR.MemoryBase = PCIBAR & (~15); 36 | netdbg("BAR Type: %d - BAR IOBase: %#x - BAR MemoryBase: %#x", BAR.Type, BAR.IOBase, BAR.MemoryBase); 37 | 38 | this->MAC = this->GetMAC(); 39 | } 40 | 41 | NetworkInterfaceController::~NetworkInterfaceController() 42 | { 43 | } 44 | 45 | void NetworkInterfaceController::Send(uint8_t *Data, uint64_t Length) 46 | { 47 | } 48 | 49 | void NetworkInterfaceController::Receive() 50 | { 51 | } 52 | 53 | void NetworkInterfaceController::HandleInterrupt() 54 | { 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /kernel/drivers/network/RTL8169/RTL8169.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../../network/NetworkController.hpp" 6 | #include "../../../pci.h" 7 | 8 | namespace RTL8169 9 | { 10 | class NetworkInterfaceController : public NetworkInterfaceManager::DeviceInterface, public DriverInterrupts::Register 11 | { 12 | private: 13 | struct BARData 14 | { 15 | uint8_t Type; 16 | uint16_t IOBase; 17 | uint32_t MemoryBase; 18 | }; 19 | 20 | char *RXBuffer; 21 | int TXCurrent; 22 | InternetProtocol4 IP; 23 | uint32_t CurrentPacket; 24 | BARData BAR; 25 | 26 | public: 27 | MediaAccessControl GetMAC(); 28 | InternetProtocol4 GetIP(); 29 | void SetIP(InternetProtocol4 IP); 30 | 31 | NetworkInterfaceController(PCI::PCIDeviceHeader *PCIBaseAddress); 32 | ~NetworkInterfaceController(); 33 | 34 | void Send(uint8_t *Data, uint64_t Length); 35 | void Receive(); 36 | 37 | virtual void HandleInterrupt(); 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /kernel/drivers/network/VirtioNetwork/VirtioNetwork.cpp: -------------------------------------------------------------------------------- 1 | #include "VirtioNetwork.hpp" 2 | 3 | namespace VirtioNetwork 4 | { 5 | MediaAccessControl NetworkInterfaceController::GetMAC() 6 | { 7 | return MediaAccessControl(); 8 | } 9 | 10 | InternetProtocol4 NetworkInterfaceController::GetIP() 11 | { 12 | return IP; 13 | } 14 | 15 | void NetworkInterfaceController::SetIP(InternetProtocol4 IP) 16 | { 17 | this->IP = IP; 18 | } 19 | 20 | NetworkInterfaceController::NetworkInterfaceController(PCI::PCIDeviceHeader *PCIBaseAddress) : DriverInterrupts::Register(((PCI::PCIHeader0 *)PCIBaseAddress)->InterruptLine + IRQ0) 21 | { 22 | if (PCIBaseAddress->VendorID != 0x1AF4 && PCIBaseAddress->DeviceID != 0x1000 && PCIBaseAddress->DeviceID != 0x1041) 23 | { 24 | netdbg("Not a Virtio network card"); 25 | return; 26 | } 27 | netdbg("Found %s network card", PCI::GetDeviceName(PCIBaseAddress->VendorID, PCIBaseAddress->DeviceID)); 28 | uint32_t PCIBAR = ((PCI::PCIHeader0 *)PCIBaseAddress)->BAR0; 29 | BAR.Type = PCIBAR & 1; 30 | BAR.IOBase = PCIBAR & (~3); 31 | BAR.MemoryBase = PCIBAR & (~15); 32 | netdbg("BAR Type: %d - BAR IOBase: %#x - BAR MemoryBase: %#x", BAR.Type, BAR.IOBase, BAR.MemoryBase); 33 | } 34 | 35 | NetworkInterfaceController::~NetworkInterfaceController() 36 | { 37 | } 38 | 39 | void NetworkInterfaceController::Send(uint8_t *Data, uint64_t Length) 40 | { 41 | } 42 | 43 | void NetworkInterfaceController::Receive() 44 | { 45 | } 46 | 47 | void NetworkInterfaceController::HandleInterrupt() 48 | { 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /kernel/drivers/network/VirtioNetwork/VirtioNetwork.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../../network/NetworkController.hpp" 6 | #include "../../../pci.h" 7 | 8 | namespace VirtioNetwork 9 | { 10 | class NetworkInterfaceController : public NetworkInterfaceManager::DeviceInterface, public DriverInterrupts::Register 11 | { 12 | private: 13 | struct BARData 14 | { 15 | uint8_t Type; 16 | uint16_t IOBase; 17 | uint32_t MemoryBase; 18 | }; 19 | 20 | char *RXBuffer; 21 | int TXCurrent; 22 | InternetProtocol4 IP; 23 | uint32_t CurrentPacket; 24 | BARData BAR; 25 | 26 | public: 27 | MediaAccessControl GetMAC(); 28 | InternetProtocol4 GetIP(); 29 | void SetIP(InternetProtocol4 IP); 30 | 31 | NetworkInterfaceController(PCI::PCIDeviceHeader *PCIBaseAddress); 32 | ~NetworkInterfaceController(); 33 | 34 | void Send(uint8_t *Data, uint64_t Length); 35 | void Receive(); 36 | 37 | virtual void HandleInterrupt(); 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /kernel/drivers/serial.c: -------------------------------------------------------------------------------- 1 | #include "serial.h" 2 | #include 3 | #include 4 | 5 | NEWLOCK(serial_lock); 6 | 7 | // Source from: https://wiki.osdev.org/Serial_Ports 8 | 9 | int init_serial(int serial_port) 10 | { 11 | LOCK(serial_lock); 12 | outb(serial_port + 7, 0x55); 13 | if (inb(serial_port + 7) != 0x55) 14 | { 15 | UNLOCK(serial_lock); 16 | return -1; 17 | } 18 | 19 | outb(serial_port + 1, 0x00); 20 | outb(serial_port + 3, SERIAL_ENABLE_DLAB); 21 | outb(serial_port + 0, 0x01); 22 | outb(serial_port + 1, SERIAL_RATE_38400_HI); 23 | outb(serial_port + 3, 0x03); 24 | outb(serial_port + 2, 0xC7); 25 | outb(serial_port + 4, 0x0B); 26 | 27 | if (inb(serial_port + 0) != 0xAE) 28 | { 29 | UNLOCK(serial_lock); 30 | return -1; 31 | } 32 | 33 | outb(serial_port + 4, 0x0F); 34 | UNLOCK(serial_lock); 35 | return 0; 36 | } 37 | 38 | int is_transmit_empty(int serial_port) { return inb(serial_port + 5) & SERIAL_BUFFER_EMPTY; } 39 | 40 | int serial_received(int serial_port) { return inb(serial_port + 5) & 1; } 41 | 42 | char read_serial(int serial_port) 43 | { 44 | while (serial_received(serial_port) == 0) 45 | ; 46 | return inb(serial_port); 47 | } 48 | 49 | void write_serial(int serial_port, char a) 50 | { 51 | while (is_transmit_empty(serial_port) == 0) 52 | ; 53 | outb(serial_port, a); 54 | } 55 | 56 | void serial_write_text(int serial_port, char *text) 57 | { 58 | // LOCK(serial_lock); 59 | for (long unsigned i = 0; i < (strlen(text)); i++) 60 | write_serial(serial_port, text[i]); 61 | // UNLOCK(serial_lock); 62 | } 63 | -------------------------------------------------------------------------------- /kernel/drivers/serial.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | START_EXTERNC 6 | 7 | #define COM1 0x3F8 8 | #define COM2 0x2F8 9 | #define COM3 0x3E8 10 | #define COM4 0x2E8 11 | #define SERIAL_ENABLE_DLAB 0x80 12 | #define SERIAL_RATE_38400_LO 0x03 13 | #define SERIAL_RATE_38400_HI 0x00 14 | #define SERIAL_BUFFER_EMPTY 0x20 15 | 16 | /** 17 | * @brief Initialize the serial port 18 | * 19 | * @param serial_port 20 | * @return 0 or -1 if the serial port is faulty. 21 | */ 22 | int init_serial(int serial_port); 23 | int serial_received(int serial_port); 24 | char read_serial(int serial_port); 25 | int is_transmit_empty(int serial_port); 26 | void write_serial(int serial_port, char a); 27 | /** 28 | * @brief Sends a text to the serial port (Used by the debug system, don't use this!!) 29 | * 30 | * @param serial_port 31 | * @param text 32 | */ 33 | void serial_write_text(int serial_port, char *text); 34 | 35 | END_EXTERNC 36 | -------------------------------------------------------------------------------- /kernel/files/fennix000.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix000.bmp -------------------------------------------------------------------------------- /kernel/files/fennix001.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix001.bmp -------------------------------------------------------------------------------- /kernel/files/fennix002.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix002.bmp -------------------------------------------------------------------------------- /kernel/files/fennix003.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix003.bmp -------------------------------------------------------------------------------- /kernel/files/fennix004.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix004.bmp -------------------------------------------------------------------------------- /kernel/files/fennix005.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix005.bmp -------------------------------------------------------------------------------- /kernel/files/fennix006.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix006.bmp -------------------------------------------------------------------------------- /kernel/files/fennix007.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix007.bmp -------------------------------------------------------------------------------- /kernel/files/fennix008.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix008.bmp -------------------------------------------------------------------------------- /kernel/files/fennix009.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix009.bmp -------------------------------------------------------------------------------- /kernel/files/fennix010.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix010.bmp -------------------------------------------------------------------------------- /kernel/files/fennix011.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix011.bmp -------------------------------------------------------------------------------- /kernel/files/fennix012.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix012.bmp -------------------------------------------------------------------------------- /kernel/files/fennix013.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix013.bmp -------------------------------------------------------------------------------- /kernel/files/fennix014.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix014.bmp -------------------------------------------------------------------------------- /kernel/files/fennix015.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix015.bmp -------------------------------------------------------------------------------- /kernel/files/fennix016.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix016.bmp -------------------------------------------------------------------------------- /kernel/files/fennix017.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix017.bmp -------------------------------------------------------------------------------- /kernel/files/fennix018.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix018.bmp -------------------------------------------------------------------------------- /kernel/files/fennix019.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix019.bmp -------------------------------------------------------------------------------- /kernel/files/fennix020.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix020.bmp -------------------------------------------------------------------------------- /kernel/files/fennix021.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix021.bmp -------------------------------------------------------------------------------- /kernel/files/fennix022.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/kernel/files/fennix022.bmp -------------------------------------------------------------------------------- /kernel/filestructures/elf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | -------------------------------------------------------------------------------- /kernel/filestructures/file.cpp: -------------------------------------------------------------------------------- 1 | #include "elf.h" 2 | 3 | -------------------------------------------------------------------------------- /kernel/filesystem/fs/ext2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../../drivers/disk.h" 3 | #include "../../drivers/serial.h" 4 | 5 | uint32_t _ext2_lite_min(uint32_t a, uint32_t b) 6 | { 7 | if (a < b) 8 | { 9 | return a; 10 | } 11 | return b; 12 | } 13 | 14 | namespace FileSystem 15 | { 16 | #define EXT2_MAGIC 0xEF53 17 | EXT2::SuperBlock sb; 18 | 19 | ReadFSFunction(EXT2_Read) 20 | { 21 | return Size; 22 | } 23 | 24 | WriteFSFunction(EXT2_Write) 25 | { 26 | return Size; 27 | } 28 | 29 | FileSystemOpeations ext2 = { 30 | .Name = "EXT2", 31 | .Read = EXT2_Read, 32 | .Write = EXT2_Write}; 33 | 34 | EXT2::EXT2(void *partition) 35 | { 36 | DiskManager::Partition::Part *Partition = (DiskManager::Partition::Part *)partition; 37 | uint8_t *buffer = (uint8_t *)RequestPage(); 38 | Partition->Read(2, 2, buffer); 39 | memcpy(&sb, buffer, sizeof(SuperBlock)); 40 | FreePage(buffer); 41 | 42 | if (sb.Magic == EXT2_MAGIC) // FIXME: ext4 is detected as ext2! 43 | { 44 | debug("EXT2 Name: \"%s\" Last Mounted In: \"%s\"", sb.VolumeName, sb.LastMounted); 45 | // TODO: Implement reading and writing files 46 | char CleandVolumeName[16] = {'\0'}; 47 | for (size_t i = 0; i < strlen(sb.VolumeName); i++) 48 | if (sb.VolumeName[i] == '/') 49 | CleandVolumeName[i] = '_'; 50 | else 51 | CleandVolumeName[i] = sb.VolumeName[i]; 52 | 53 | mountfs->MountFileSystem(&ext2, 0666, CleandVolumeName); 54 | } 55 | } 56 | 57 | EXT2::~EXT2() { warn("Destroyed"); } 58 | } 59 | -------------------------------------------------------------------------------- /kernel/filesystem/fs/fb.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "../../drivers/disk.h" 6 | #include "../../drivers/serial.h" 7 | 8 | namespace FileSystem 9 | { 10 | uint64_t fbAddress; 11 | uint64_t fbSize; 12 | uint32_t fbWidth, fbHeight; 13 | uint32_t fbPixelsPerScanLine; 14 | 15 | ReadFSFunction(FB_Read) 16 | { 17 | uint64_t X = Offset; 18 | uint64_t Y = Size; 19 | if (X >= fbWidth || Y >= fbHeight) 20 | Buffer = 0; 21 | Buffer = (uint8_t *)((uint64_t)(((uint32_t *)fbAddress)[X + (Y * fbPixelsPerScanLine)])); 22 | return fbSize; 23 | } 24 | 25 | WriteFSFunction(FB_Write) 26 | { 27 | uint64_t X = Offset; 28 | uint64_t Y = Size; 29 | if (X >= fbWidth || Y >= fbHeight) 30 | return 0; 31 | ((uint32_t *)fbAddress)[X + (Y * fbPixelsPerScanLine)] = (uint32_t)((uint64_t)Buffer); 32 | return fbSize; 33 | } 34 | 35 | FileSystemOpeations fb = { 36 | .Name = "Framebuffer", 37 | .Read = FB_Read, 38 | .Write = FB_Write}; 39 | 40 | void FB::SetFrameBufferData(uint64_t Address, uint64_t Size, uint32_t Width, uint32_t Height, uint32_t PixelsPerScanLine) 41 | { 42 | fbAddress = Address; 43 | fbSize = Size; 44 | fbWidth = Width; 45 | fbHeight = Height; 46 | fbPixelsPerScanLine = PixelsPerScanLine; 47 | } 48 | 49 | FB::FB() { devfs->AddFileSystem(&fb, 0666, "fb", FileSystem::NodeFlags::FS_PIPE); } 50 | 51 | FB::~FB() { warn("Destroyed"); } 52 | } 53 | -------------------------------------------------------------------------------- /kernel/filesystem/fs/initrd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace FileSystem 4 | { 5 | ReadFSFunction(Initrd_Read) 6 | { 7 | return 0; 8 | } 9 | 10 | Initrd::Initrd(uint64_t Address) 11 | { 12 | InitrdHeader *Header = (InitrdHeader *)Address; 13 | // TODO: Implement this function 14 | } 15 | 16 | Initrd::~Initrd() 17 | { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /kernel/filesystem/fs/null.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace FileSystem 4 | { 5 | ReadFSFunction(Null_Read) 6 | { 7 | if (Size < 1) 8 | return 0; 9 | memset(Buffer, 0x0, Size); 10 | return Size; 11 | } 12 | 13 | WriteFSFunction(Null_Write) { return Size; } 14 | 15 | FileSystemOpeations null = { 16 | .Name = "Null", 17 | .Read = Null_Read, 18 | .Write = Null_Write}; 19 | 20 | Null::Null() { devfs->AddFileSystem(&null, 0666, "null", NodeFlags::FS_CHARDEVICE); } 21 | 22 | Null::~Null() { warn("Destroyed"); } 23 | } 24 | -------------------------------------------------------------------------------- /kernel/filesystem/fs/random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace FileSystem 5 | { 6 | ReadFSFunction(Random_Read) 7 | { 8 | uint64_t s = 0; 9 | while (s < Size) 10 | { 11 | ((uint8_t *)Buffer)[s] = (rand64()) % 0xFF; 12 | Offset++; 13 | s++; 14 | } 15 | return Size; 16 | } 17 | 18 | WriteFSFunction(Random_Write) { return Size; } 19 | 20 | FileSystemOpeations random = { 21 | .Name = "Random", 22 | .Read = &Random_Read, 23 | .Write = &Random_Write}; 24 | 25 | Random::Random() { devfs->AddFileSystem(&random, 0444, "random", NodeFlags::FS_CHARDEVICE); } 26 | 27 | Random::~Random() { warn("Destroyed"); } 28 | } 29 | -------------------------------------------------------------------------------- /kernel/filesystem/fs/zero.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace FileSystem 4 | { 5 | ReadFSFunction(Zero_Read) 6 | { 7 | memset(Buffer, 0, Size); 8 | return 0; 9 | } 10 | 11 | WriteFSFunction(Zero_Write) { return Size; } 12 | 13 | FileSystemOpeations zero = { 14 | .Name = "Zero", 15 | .Read = Zero_Read, 16 | .Write = Zero_Write}; 17 | 18 | Zero::Zero() { devfs->AddFileSystem(&zero, 0666, "zero", NodeFlags::FS_CHARDEVICE); } 19 | 20 | Zero::~Zero() { warn("Destroyed"); } 21 | } 22 | -------------------------------------------------------------------------------- /kernel/filesystem/mountpoints/devfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace FileSystem 6 | { 7 | FileSystemNode *DeviceRootNode = nullptr; 8 | static uint64_t DeviceNodeIndexNodeCount = 0; 9 | 10 | FileSystemNode *Device::AddFileSystem(FileSystemOpeations *Operator, uint64_t Mode, string Name, int Flags) 11 | { 12 | trace("Adding %s to device file system", Name); 13 | // char *FullPath = new char[256]; 14 | // strcpy(FullPath, "/system/dev/"); 15 | // strcat(FullPath, Name); 16 | // FileSystemNode *newNode = vfs->Create(nullptr, FullPath); 17 | // delete[] FullPath; 18 | 19 | // FileSystemNode *newNode = vfs->Create(DeviceRootNode, Name); 20 | 21 | FileSystemNode *newNode = new FileSystemNode; 22 | strcpy(newNode->Name, Name); 23 | newNode->IndexNode = DeviceNodeIndexNodeCount++; 24 | newNode->Mode = Mode; 25 | newNode->Operator = Operator; 26 | newNode->Flags = Flags; 27 | DeviceRootNode->Children.push_back(newNode); 28 | return newNode; 29 | } 30 | 31 | Device::Device() 32 | { 33 | trace("Initializing device file system..."); 34 | DeviceRootNode = vfs->Create(nullptr, "/system/dev"); 35 | DeviceRootNode->Flags = NodeFlags::FS_DIRECTORY; 36 | DeviceRootNode->Mode = 0755; 37 | BS->IncreaseProgres(); 38 | } 39 | 40 | Device::~Device() 41 | { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /kernel/filesystem/mountpoints/drvfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace FileSystem 6 | { 7 | FileSystemNode *DriverRootNode = nullptr; 8 | static uint64_t DriverNodeIndexNodeCount = 0; 9 | 10 | FileSystemNode *Driver::AddDriver(struct FileSystemOpeations *Operator, uint64_t Mode, string Name, int Flags) 11 | { 12 | trace("Adding %s to file system", Name); 13 | // FileSystemNode *newNode = vfs->Create(DriverRootNode, Name); 14 | FileSystemNode *newNode = new FileSystemNode; 15 | strcpy(newNode->Name, Name); 16 | newNode->IndexNode = DriverNodeIndexNodeCount++; 17 | newNode->Mode = Mode; 18 | newNode->Operator = Operator; 19 | newNode->Flags = Flags; 20 | DriverRootNode->Children.push_back(newNode); 21 | return newNode; 22 | } 23 | 24 | Driver::Driver() 25 | { 26 | trace("Initializing driver file system..."); 27 | DriverRootNode = vfs->Create(nullptr, "/system/drv"); 28 | DriverRootNode->Flags = NodeFlags::FS_DIRECTORY; 29 | DriverRootNode->Mode = 0755; 30 | BS->IncreaseProgres(); 31 | } 32 | 33 | Driver::~Driver() 34 | { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /kernel/filesystem/mountpoints/mountfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include "../drivers/disk.h" 7 | 8 | namespace FileSystem 9 | { 10 | FileSystemNode *MountRootNode = nullptr; 11 | static uint64_t MountNodeIndexNodeCount = 0; 12 | 13 | FileSystemNode *Mount::MountFileSystem(FileSystemOpeations *Operator, uint64_t Mode, string Name) 14 | { 15 | if (isempty((char *)Name)) 16 | { 17 | warn("Tried to mount file system with empty name!"); 18 | sprintf_((char *)Name, "mount%lu", MountNodeIndexNodeCount); 19 | } 20 | trace("Adding %s to mounted file systems", Name); 21 | // FileSystemNode *newNode = vfs->Create(MountRootNode, Name); 22 | 23 | FileSystemNode *newNode = new FileSystemNode; 24 | strcpy(newNode->Name, Name); 25 | newNode->IndexNode = MountNodeIndexNodeCount++; 26 | newNode->Mode = Mode; 27 | newNode->Operator = Operator; 28 | newNode->Flags = NodeFlags::FS_MOUNTPOINT; 29 | MountRootNode->Children.push_back(newNode); 30 | return newNode; 31 | } 32 | 33 | void Mount::DetectAndMountFS(void *drive) 34 | { 35 | foreach (auto partition in((DiskManager::Partition::Drive *)drive)->Partitions) 36 | { 37 | debug("Mounting File Systems for Partition %d...", partition->Index); 38 | new EXT2(partition); 39 | new FAT(partition); 40 | /* ... */ 41 | } 42 | } 43 | 44 | Mount::Mount() 45 | { 46 | trace("Mounting file systems..."); 47 | MountRootNode = vfs->Create(nullptr, "/system/mnt"); 48 | MountRootNode->Flags = NodeFlags::FS_DIRECTORY; 49 | MountRootNode->Mode = 0755; 50 | BS->IncreaseProgres(); 51 | } 52 | 53 | Mount::~Mount() 54 | { 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /kernel/filesystem/mountpoints/netfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace FileSystem 6 | { 7 | FileSystemNode *NetworkRootNode = nullptr; 8 | static uint64_t NetworkNodeIndexNodeCount = 0; 9 | 10 | FileSystemNode *Network::AddNetworkCard(struct FileSystemOpeations *Operator, uint64_t Mode, string Name, int Flags) 11 | { 12 | trace("Adding %s to file system", Name); 13 | // FileSystemNode *newNode = vfs->Create(NetworkRootNode, Name); 14 | 15 | FileSystemNode *newNode = new FileSystemNode; 16 | strcpy(newNode->Name, Name); 17 | newNode->IndexNode = NetworkNodeIndexNodeCount++; 18 | newNode->Mode = Mode; 19 | newNode->Operator = Operator; 20 | newNode->Flags = Flags; 21 | NetworkRootNode->Children.push_back(newNode); 22 | return newNode; 23 | } 24 | 25 | Network::Network() 26 | { 27 | trace("Initializing network file system..."); 28 | NetworkRootNode = vfs->Create(nullptr, "/system/net"); 29 | NetworkRootNode->Flags = NodeFlags::FS_DIRECTORY; 30 | NetworkRootNode->Mode = 0755; 31 | BS->IncreaseProgres(); 32 | } 33 | 34 | Network::~Network() 35 | { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /kernel/filesystem/mountpoints/procfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace FileSystem 6 | { 7 | FileSystemNode *ProcessRootNode = nullptr; 8 | 9 | Process::Process() 10 | { 11 | trace("Initializing process file system"); 12 | ProcessRootNode = vfs->Create(nullptr, "/system/prc"); 13 | ProcessRootNode->Flags = NodeFlags::FS_DIRECTORY; 14 | ProcessRootNode->Mode = 0755; 15 | BS->IncreaseProgres(); 16 | } 17 | 18 | Process::~Process() 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /kernel/include/atomic.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !__has_extension(c_atomic) 4 | #define _Atomic(T) T 5 | #endif 6 | 7 | #define builtin_atomic(name) __atomic_##name##_n 8 | 9 | namespace 10 | { 11 | enum MemoryBorder 12 | { 13 | Relaxed = __ATOMIC_RELAXED, 14 | Acquire = __ATOMIC_ACQUIRE, 15 | Release = __ATOMIC_RELEASE, 16 | AcqRel = __ATOMIC_ACQ_REL, 17 | SeqCst = __ATOMIC_SEQ_CST 18 | }; 19 | template 20 | class atomic 21 | { 22 | _Atomic(T) value; 23 | 24 | public: 25 | atomic(T Init) : value(Init) {} 26 | T load(MemoryBorder order = MemoryBorder::SeqCst) 27 | { 28 | return builtin_atomic(load)(&value, order); 29 | } 30 | void store(T v, MemoryBorder order = MemoryBorder::SeqCst) 31 | { 32 | return builtin_atomic(store)(&value, v, order); 33 | } 34 | T exchange(T v, MemoryBorder order = MemoryBorder::SeqCst) 35 | { 36 | return builtin_atomic(exchange)(&value, v, order); 37 | } 38 | bool compare_exchange(T &expected, T desired, MemoryBorder order = MemoryBorder::SeqCst) 39 | { 40 | return __atomic_compare_exchange_n(&value, &expected, desired, true, order, order); 41 | } 42 | }; 43 | } 44 | #undef builtin_atomic 45 | -------------------------------------------------------------------------------- /kernel/include/bitmap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Bitmap 5 | { 6 | public: 7 | size_t Size; 8 | uint8_t *Buffer; 9 | bool operator[](uint64_t index); 10 | bool Set(uint64_t index, bool value); 11 | bool Get(uint64_t index); 12 | }; 13 | -------------------------------------------------------------------------------- /kernel/include/bootscreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BootScreen 5 | { 6 | class Screen 7 | { 8 | private: 9 | bool KernelLogo; 10 | int curProg = 0; 11 | 12 | public: 13 | void DrawVendorLogo(void *BGRT, bool DrawKernelLogo = true); 14 | void Progress(int Value); 15 | void IncreaseProgres(); 16 | void FadeLogo(); 17 | Screen(); 18 | ~Screen(); 19 | }; 20 | } 21 | 22 | extern BootScreen::Screen *BS; -------------------------------------------------------------------------------- /kernel/include/critical.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #pragma GCC diagnostic ignored "-Wsubobject-linkage" 5 | 6 | namespace Critical 7 | { 8 | struct CriticalSectionData 9 | { 10 | bool EnableInterrupts; 11 | LOCK CriticalLock; 12 | }; 13 | 14 | CriticalSectionData *Enter(); 15 | void Leave(CriticalSectionData *Data); 16 | } 17 | 18 | #define EnterCriticalSection Critical::CriticalSectionData *CriticalSectionData = Critical::Enter() 19 | #define LeaveCriticalSection Critical::Leave(CriticalSectionData) 20 | -------------------------------------------------------------------------------- /kernel/include/ctype.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define toupper(c) ((c)-0x20 * (((c) >= 'a') && ((c) <= 'z'))) 4 | #define tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z'))) 5 | -------------------------------------------------------------------------------- /kernel/include/easyc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | 5 | #define foreach for 6 | #define in : 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /kernel/include/err.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum ErrorCodes 4 | { 5 | ERR_SUCCESS = 0, 6 | ERR_INVALID_ARGUMENT, 7 | ERR_INVALID_HANDLE, 8 | ERR_INVALID_OPERATION, 9 | ERR_INVALID_ADDRESS, 10 | ERR_INVALID_MEMORY, 11 | ERR_INVALID_MEMORY_SIZE, 12 | ERR_INVALID_MEMORY_ACCESS, 13 | ERR_INVALID_MEMORY_OPERATION 14 | }; 15 | 16 | long SetError(long ErrorCode); 17 | long GetError(); 18 | -------------------------------------------------------------------------------- /kernel/include/events.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /kernel/include/ipc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace InterProcessCommunication 6 | { 7 | typedef unsigned int IPCPort; 8 | 9 | enum IPCOperationType 10 | { 11 | IPCOperationNone, 12 | IPCOperationWrite, 13 | IPCOperationRead 14 | }; 15 | 16 | enum IPCErrorCode 17 | { 18 | IPCUnknown, 19 | IPCSuccess, 20 | IPCNotListening, 21 | IPCTimeout, 22 | IPCInvalidPort, 23 | IPCPortInUse, 24 | IPCPortNotRegistered 25 | }; 26 | 27 | typedef struct 28 | { 29 | int ID; 30 | int Length; 31 | void *Buffer; 32 | bool Listening; 33 | IPCOperationType Type; 34 | IPCErrorCode Error; 35 | LOCK Lock; 36 | } IPCHandle; 37 | 38 | typedef struct 39 | { 40 | int ID; 41 | int Length; 42 | IPCOperationType Type; 43 | IPCErrorCode Error; 44 | void *Buffer; 45 | 46 | // Reserved 47 | IPCHandle *HandleBuffer; 48 | } __attribute__((packed)) IPCSyscallHandle; 49 | 50 | struct IPCError 51 | { 52 | uint64_t ErrorCode; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /kernel/include/rand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | EXTERNC uint16_t rand16(); 5 | EXTERNC uint32_t rand32(); 6 | EXTERNC uint64_t rand64(); 7 | void changeseed(uint64_t seed); 8 | -------------------------------------------------------------------------------- /kernel/include/stdalign.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __cplusplus 4 | 5 | #define alignas _Alignas 6 | #define alignof _Alignof 7 | 8 | #endif -------------------------------------------------------------------------------- /kernel/include/string.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | int isdigit(int c); 10 | int isspace(int c); 11 | int isempty(char *str); 12 | unsigned int isdelim(char c, char *delim); 13 | 14 | void *memcpy(void *__restrict__ dest, const void *__restrict__ src, size_t n); 15 | void *memset(void *dest, int data, size_t nbytes); 16 | void *memmove(void *dest, const void *src, size_t n); 17 | int memcmp(const void *vl, const void *vr, size_t n); 18 | long unsigned strlen(const char s[]); 19 | int strncmp(const char *s1, const char *s2, unsigned long n); 20 | char *strcat(char *destination, const char *source); 21 | char *strcpy(char *destination, const char *source); 22 | char *strncpy(char *destination, const char *source, unsigned long num); 23 | int strcmp(const char *l, const char *r); 24 | char *strstr(const char *haystack, const char *needle); 25 | char *strdup(const char *String); 26 | char *strchr(const char *String, int Char); 27 | char *strrchr(const char *String, int Char); 28 | int strncasecmp(const char *lhs, const char *rhs, long unsigned int Count); 29 | int strcasecmp(const char *lhs, const char *rhs); 30 | char *strtok(char *__restrict__ src, const char *__restrict__ delim); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /kernel/include/symbols.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace KernelSymbols 5 | { 6 | class Symbols 7 | { 8 | public: 9 | struct SymbolTable 10 | { 11 | uint64_t Address; 12 | char *FunctionName; 13 | }; 14 | 15 | Symbols(); 16 | ~Symbols(); 17 | string GetSymbolFromAddress(uint64_t Address); 18 | }; 19 | } 20 | 21 | extern KernelSymbols::Symbols *SymTbl; 22 | -------------------------------------------------------------------------------- /kernel/include/sys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | EXTERNC void crash(string message, bool clear); 6 | void TriggerUserModeCrash(TrapFrame *regs); 7 | EXTERNC void isrcrash(TrapFrame *regs); 8 | 9 | #define panic(m, clear) crash(m, clear) 10 | -------------------------------------------------------------------------------- /kernel/include/vm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | EXTERNC bool CheckRunningUnderVM(); 5 | -------------------------------------------------------------------------------- /kernel/interrupts/pic.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define PIC1 0x20 /* IO base address for master PIC */ 4 | #define PIC2 0xA0 /* IO base address for slave PIC */ 5 | #define PIC1_COMMAND PIC1 6 | #define PIC1_DATA (PIC1 + 1) 7 | #define PIC2_COMMAND PIC2 8 | #define PIC2_DATA (PIC2 + 1) 9 | #define PIC_EOI 0x20 /* End-of-interrupt command code */ 10 | 11 | #define ICW1_ICW4 0x01 /* ICW4 (not) needed */ 12 | #define ICW1_SINGLE 0x02 /* Single (cascade) mode */ 13 | #define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */ 14 | #define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */ 15 | #define ICW1_INIT 0x10 /* Initialization - required! */ 16 | 17 | #define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */ 18 | #define ICW4_AUTO 0x02 /* Auto (normal) EOI */ 19 | #define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */ 20 | #define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */ 21 | #define ICW4_SFNM 0x10 /* Special fully nested (not) */ 22 | 23 | EXTERNC void PIC_disable(); 24 | EXTERNC void PIC_sendEOI(unsigned char irq); 25 | void PIC_remap(int offset1, int offset2); 26 | void IRQ_set_mask(unsigned char IRQline); 27 | void IRQ_clear_mask(unsigned char IRQline); 28 | -------------------------------------------------------------------------------- /kernel/kernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "arch/amd64/boot/limine.h" 6 | #ifdef __cplusplus 7 | #include "mem/xalloc/Xalloc.hpp" 8 | #endif 9 | 10 | typedef struct _SysFlags 11 | { 12 | /** 13 | * @brief Debug mode "debug" 14 | */ 15 | bool fennecsarethebest; 16 | /** 17 | * @brief The root filesystem "rootfs=hda0 or something like that" 18 | */ 19 | char rootfs[512]; // TODO: more info about the disk 20 | /** 21 | * @brief No gpu driver 22 | */ 23 | bool nogpu; 24 | /** 25 | * @brief No hpet timer 26 | */ 27 | bool nohpet; 28 | /** 29 | * @brief Enter in emergency mode TODO: 30 | */ 31 | bool emergency; 32 | /** 33 | * @brief Do not mount any filesystem or partition 34 | */ 35 | bool nomount; 36 | /** 37 | * @brief Do not initialize the boot loading screen 38 | */ 39 | bool noloadingscreen; 40 | /** 41 | * @brief Set tasking mode to monotasking 42 | * 43 | */ 44 | bool monotasking; 45 | } SysFlags; 46 | 47 | extern uint8_t kernel_stack[STACK_SIZE]; 48 | 49 | extern GlobalBootParams earlyparams; 50 | extern GlobalBootParams *bootparams; 51 | extern SysFlags *sysflags; 52 | extern bool ShowRecoveryScreen; 53 | extern bool FadeScreenNow; 54 | #ifdef __cplusplus 55 | extern Xalloc::AllocatorV1 *UserAllocator; 56 | #endif 57 | 58 | EXTERNC void limine_initializator(); 59 | 60 | void KernelTask(); 61 | -------------------------------------------------------------------------------- /kernel/libs/Bitmap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool Bitmap::operator[](uint64_t index) 4 | { 5 | return Get(index); 6 | } 7 | 8 | bool Bitmap::Get(uint64_t index) 9 | { 10 | if (index > Size * 8) 11 | return false; 12 | uint64_t byteIndex = index / 8; 13 | uint8_t bitIndex = index % 8; 14 | uint8_t bitIndexer = 0b10000000 >> bitIndex; 15 | if ((Buffer[byteIndex] & bitIndexer) > 0) 16 | return true; 17 | return false; 18 | } 19 | 20 | bool Bitmap::Set(uint64_t index, bool value) 21 | { 22 | if (index > Size * 8) 23 | return false; 24 | uint64_t byteIndex = index / 8; 25 | uint8_t bitIndex = index % 8; 26 | uint8_t bitIndexer = 0b10000000 >> bitIndex; 27 | Buffer[byteIndex] &= ~bitIndexer; 28 | if (value) 29 | Buffer[byteIndex] |= bitIndexer; 30 | return true; 31 | } -------------------------------------------------------------------------------- /kernel/libs/converter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | START_EXTERNC 6 | 7 | const char *u64ToString(uint64_t value); 8 | const char *i64ToString(int64_t value); 9 | const char *u64ToHexString(uint64_t value); 10 | const char *u32ToHexString(uint32_t value); 11 | const char *u16ToHexString(uint16_t value); 12 | const char *u8ToHexString(uint8_t value); 13 | // const char *ToString(double value, uint8_t decimalPlaces); 14 | // const char *ToString(double value); 15 | 16 | END_EXTERNC 17 | -------------------------------------------------------------------------------- /kernel/linker-aarch64.ld: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | 3 | SECTIONS 4 | { 5 | . = 0x80000; 6 | 7 | _kernel_start = .; 8 | 9 | .text.boot : 10 | { 11 | *(.text.boot) 12 | } 13 | 14 | .text : 15 | { 16 | KEEP(*(.text.boot)) 17 | *(.text) 18 | } 19 | . = ALIGN(4096); 20 | _kernel_text_end = .; 21 | 22 | .rodata : 23 | { 24 | *(.rodata) 25 | } 26 | . = ALIGN(4096); 27 | _kernel_rodata_end = .; 28 | 29 | .data : 30 | { 31 | *(.data) 32 | } 33 | _kernel_data_end = .; 34 | 35 | .bss : 36 | { 37 | bss = .; 38 | *(.bss) 39 | } 40 | . = ALIGN(4096); 41 | _kernel_bss_end = .; 42 | _kernel_bss_size = _kernel_bss_end - _kernel_data_end; 43 | _kernel_end = .; 44 | 45 | 46 | /DISCARD/ : 47 | { 48 | *(.eh_frame) 49 | *(.note .note.*) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /kernel/linker-amd64.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT(elf64-x86-64) 2 | OUTPUT_ARCH(i386:x86-64) 3 | 4 | ENTRY(kernel_entry) 5 | 6 | PHDRS 7 | { 8 | null PT_NULL FLAGS(0) ; /* Null segment */ 9 | text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */ 10 | rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */ 11 | data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */ 12 | } 13 | 14 | SECTIONS 15 | { 16 | . = 0xffffffff80000000; 17 | 18 | _kernel_start = .; 19 | .text : 20 | { 21 | *(.text .text.*) 22 | } :text 23 | _kernel_text_end = ALIGN(CONSTANT(MAXPAGESIZE)); 24 | . += CONSTANT(MAXPAGESIZE); 25 | 26 | .rodata : 27 | { 28 | *(.rodata .rodata.*) 29 | } :rodata 30 | _kernel_rodata_end = ALIGN(CONSTANT(MAXPAGESIZE)); 31 | . += CONSTANT(MAXPAGESIZE); 32 | 33 | .data : 34 | { 35 | *(.data .data.*) 36 | } :data 37 | 38 | .bss : 39 | { 40 | *(COMMON) 41 | *(.bss .bss.*) 42 | } :data 43 | . += CONSTANT(MAXPAGESIZE); 44 | _kernel_end = ALIGN(CONSTANT(MAXPAGESIZE)); 45 | 46 | /DISCARD/ : 47 | { 48 | *(.eh_frame) 49 | *(.note .note.*) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /kernel/linker-i686.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT(elf32-i386) 2 | OUTPUT_ARCH(i386) 3 | 4 | ENTRY(_start) 5 | 6 | SECTIONS 7 | { 8 | . = 0x100000; 9 | 10 | .multiboot.data : 11 | { 12 | *(.multiboot.data) 13 | } 14 | 15 | .multiboot.text : 16 | { 17 | *(.multiboot.text) 18 | } 19 | 20 | . += 0xC0000000; 21 | _kernel_start = .; 22 | 23 | .text ALIGN(4K) : AT(ADDR(.text) - 0xC0000000) 24 | { 25 | *(.text) 26 | } 27 | _kernel_text_end = .; 28 | 29 | .rodata ALIGN(4K) : AT(ADDR(.rodata) - 0xC0000000) 30 | { 31 | *(.rodata) 32 | } 33 | _kernel_rodata_end = .; 34 | 35 | .data ALIGN(4K) : AT(ADDR(.data) - 0xC0000000) 36 | { 37 | *(.data) 38 | } 39 | _kernel_data_end = .; 40 | 41 | .bss ALIGN(4K) : AT(ADDR(.bss) - 0xC0000000) 42 | { 43 | *(COMMON) 44 | *(.bss) 45 | *(.bootstrap_stack) 46 | } 47 | _kernel_end = .; 48 | 49 | /DISCARD/ : 50 | { 51 | *(.eh_frame) 52 | *(.note .note.*) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /kernel/mem/PhysicalMemoryManager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../kernel.h" 3 | 4 | using namespace PMM; 5 | using namespace VMM; 6 | 7 | void init_pmm() 8 | { 9 | trace("initializing pmm"); 10 | uint64_t kernelSize = (uint64_t)&_kernel_end - (uint64_t)&_kernel_start; 11 | // uint64_t kernelPages = (uint64_t)kernelSize / 4096 + 1; 12 | uint64_t fbBase = earlyparams.Framebuffer.BaseAddress; 13 | uint64_t fbSize = earlyparams.Framebuffer.BufferSize + 0x1000; 14 | KernelAllocator = PageFrameAllocator(); 15 | KernelAllocator.ReadMemoryMap(); 16 | // KernelAllocator.LockPages(&_kernel_start, kernelPages); 17 | 18 | debug("RAM SIZE: %dGB", TO_GB(earlyparams.mem.Size)); 19 | debug("Kernel Start: %016p - End: %016p - Size: %d (%dKB)", &_kernel_start, &_kernel_end, kernelSize, TO_KB(kernelSize)); 20 | debug("Framebuffer Base: %016p - Framebuffer Size: %d (%dKB)", fbBase, fbSize, TO_KB(fbSize)); 21 | debug("RAM-> Free: %dGB (%dMB) - Used: %dGB (%dMB) - Reserved: %dGB (%dMB)", 22 | TO_GB(GetFreeMemory()), TO_MB(GetFreeMemory()), 23 | TO_GB(GetUsedMemory()), TO_MB(GetUsedMemory()), 24 | TO_GB(GetReservedMemory()), TO_MB(GetReservedMemory())); 25 | } 26 | -------------------------------------------------------------------------------- /kernel/mem/StackHeapManager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../kernel.h" 4 | 5 | using namespace PMM; 6 | using namespace VMM; 7 | 8 | NEWLOCK(stack_lock); 9 | 10 | StackHeap::StackHeap *KernelStackAllocator = nullptr; 11 | 12 | namespace StackHeap 13 | { 14 | 15 | uint64_t HeapBase = KERNEL_STACK_HEAP_BASE; 16 | 17 | void *StackHeap::AllocateStack(bool User) 18 | { 19 | // TODO: fix stack allocator 20 | 21 | // if (HeapBase >= KERNEL_STACK_HEAP_END) 22 | // { 23 | // warn("Stack heap is full."); 24 | void *Address = (void *)((uint64_t)KernelAllocator.RequestPage()); 25 | if (User) 26 | KernelPageTableManager.MapMemory((void *)(Address), (void *)(Address), PTFlag::RW | PTFlag::US); 27 | debug("New stack allocated at %#lx", Address); 28 | return Address; 29 | // } 30 | // uint64_t ReturnHeap = HeapBase; 31 | // KernelPageTableManager.MapMemory((void *)(ReturnHeap), KernelAllocator.RequestPage(), RW); 32 | // memcpy((void *)ReturnHeap, 0, STACK_SIZE); 33 | // HeapBase += STACK_SIZE; 34 | // trace("New stack allocated at %#lx", (void *)ReturnHeap); 35 | // return (PageTable *)ReturnHeap; 36 | } 37 | 38 | void StackHeap::FreeStack(void *Address) 39 | { 40 | KernelAllocator.FreePage(Address); 41 | } 42 | 43 | StackHeap::StackHeap() { trace("Initialized."); } 44 | StackHeap::~StackHeap() { err("StackHeap destructor called"); } 45 | } -------------------------------------------------------------------------------- /kernel/mem/defaultalloc/defaultalloc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Heap 5 | { 6 | struct HeapSegHdr 7 | { 8 | uint64_t Length; 9 | HeapSegHdr *Next; 10 | HeapSegHdr *Last; 11 | bool IsFree; 12 | void CombineForward(); 13 | void CombineBackward(); 14 | HeapSegHdr *Split(uint64_t SplitLength); 15 | } __attribute__((aligned(16))); 16 | } 17 | 18 | #define defPREFIX(func) defk##func 19 | 20 | void InitHeap(void *HeapAddress, uint64_t PageCount); 21 | 22 | extern void defPREFIX(free)(void *Address); 23 | extern void *defPREFIX(malloc)(uint64_t Size); 24 | extern void *defPREFIX(calloc)(uint64_t n, uint64_t Size); 25 | extern void *defPREFIX(realloc)(void *Address, uint64_t Size); 26 | -------------------------------------------------------------------------------- /kernel/mem/helpers/PageDirectoryEntry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace VMM; 4 | 5 | void PageDirectoryEntry::AddFlag(uint64_t Flag) { this->Value.raw |= Flag; } 6 | 7 | void PageDirectoryEntry::RemoveFlags(uint64_t Flag) { this->Value.raw &= ~Flag; } 8 | 9 | void PageDirectoryEntry::ClearFlags() { this->Value.raw = 0; } 10 | 11 | void PageDirectoryEntry::SetFlag(uint64_t Flag, bool Enabled) 12 | { 13 | this->Value.raw &= ~Flag; 14 | if (Enabled) 15 | this->Value.raw |= Flag; 16 | } 17 | 18 | uint64_t PageDirectoryEntry::GetFlag() { return this->Value.raw; } 19 | 20 | bool PageDirectoryEntry::GetFlag(uint64_t Flag) { return (this->Value.raw & Flag) > 0 ? true : false; } 21 | 22 | uint64_t PageDirectoryEntry::GetAddress() { return (this->Value.raw & 0x000FFFFFFFFFF000) >> 12; } 23 | 24 | void PageDirectoryEntry::SetAddress(uint64_t Address) 25 | { 26 | Address &= 0x000000FFFFFFFFFF; 27 | this->Value.raw &= 0xFFF0000000000FFF; 28 | this->Value.raw |= (Address << 12); 29 | } 30 | -------------------------------------------------------------------------------- /kernel/mem/helpers/PageMapIndexer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace VMM; 4 | 5 | PageMapIndexer::PageMapIndexer(uint64_t VirtualAddress) 6 | { 7 | PDP_i = (VirtualAddress & ((uint64_t)0x1FF << 39)) >> 39; 8 | PD_i = (VirtualAddress & ((uint64_t)0x1FF << 30)) >> 30; 9 | PT_i = (VirtualAddress & ((uint64_t)0x1FF << 21)) >> 21; 10 | P_i = (VirtualAddress & ((uint64_t)0x1FF << 12)) >> 12; 11 | } 12 | -------------------------------------------------------------------------------- /kernel/mem/helpers/PageTableManager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace VMM; 4 | 5 | PageTableManager::PageTableManager(PageTable *PML4Address) 6 | { 7 | this->PML4 = PML4Address; 8 | } 9 | -------------------------------------------------------------------------------- /kernel/mem/liballoc/liballoc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | /** This is a boundary tag which is prepended to the 11 | * page or section of a page which we have allocated. It is 12 | * used to identify valid memory blocks that the 13 | * application is trying to free. 14 | */ 15 | struct boundary_tag 16 | { 17 | unsigned int magic; //< It's a kind of ... 18 | unsigned int size; //< Requested size. 19 | unsigned int real_size; //< Actual size. 20 | int index; //< Location in the page table. 21 | 22 | struct boundary_tag *split_left; //< Linked-list info for broken pages. 23 | struct boundary_tag *split_right; //< The same. 24 | 25 | struct boundary_tag *next; //< Linked list info. 26 | struct boundary_tag *prev; //< Linked list info. 27 | }; 28 | 29 | void *liballoc_malloc(size_t); //< The standard function. 30 | void *liballoc_realloc(void *, size_t); //< The standard function. 31 | void *liballoc_calloc(size_t, size_t); //< The standard function. 32 | void liballoc_free(void *); //< The standard function. 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /kernel/mem/liballoc/liballoc_1_1.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBALLOC_H 2 | #define _LIBALLOC_H 3 | 4 | #define libPREFIX(func) libk##func 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | extern void *libPREFIX(malloc)(size_t); ///< The standard function. 13 | extern void *libPREFIX(realloc)(void *, size_t); ///< The standard function. 14 | extern void *libPREFIX(calloc)(size_t, size_t); ///< The standard function. 15 | extern void libPREFIX(free)(void *); ///< The standard function. 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /kernel/network/InternetControlMessageProtocol.cpp: -------------------------------------------------------------------------------- 1 | #include "NetworkController.hpp" 2 | 3 | namespace NetworkICMPv4 4 | { 5 | ICMPv4::ICMPv4(NetworkInterfaceManager::DeviceInterface *Interface) { this->Interface = Interface; } 6 | ICMPv4::~ICMPv4() {} 7 | 8 | void ICMPv4::Send(/* ???? */) 9 | { 10 | fixme("Unimplemented"); 11 | } 12 | 13 | void ICMPv4::Receive(ICMPPacket *Packet) 14 | { 15 | if (Packet->Header.Type == ICMPv4Type::TYPE_ECHO) 16 | { 17 | // TODO: This probably doesn't work 18 | netdbg("ICMPv4: Echo Request"); 19 | Packet->Header.Type = ICMPv4Type::TYPE_ECHO_REPLY; 20 | Packet->Header.Code = 0x0; 21 | Packet->Header.Checksum = CalculateChecksum((uint16_t *)Packet, sizeof(ICMPHeader)); 22 | this->Interface->Send((uint8_t *)Packet, sizeof(ICMPHeader) + 0); 23 | } 24 | else 25 | { 26 | netdbg("ICMPv4: Unknown type %d", Packet->Header.Type); 27 | } 28 | } 29 | } 30 | 31 | namespace NetworkICMPv6 32 | { 33 | ICMPv6::ICMPv6(NetworkInterfaceManager::DeviceInterface *Interface) { this->Interface = Interface; } 34 | ICMPv6::~ICMPv6() {} 35 | 36 | void ICMPv6::Send(uint8_t *Data, uint64_t Length) { fixme("Unimplemented"); } 37 | void ICMPv6::Receive(uint8_t *Data) { fixme("Unimplemented"); } 38 | } 39 | -------------------------------------------------------------------------------- /kernel/network/NetworkTimeProtocol.cpp: -------------------------------------------------------------------------------- 1 | #include "NetworkController.hpp" 2 | 3 | namespace NetworkNTP 4 | { 5 | NTP::NTP(NetworkUDP::Socket *Socket) : NetworkUDP::UDPEvents() 6 | { 7 | this->Socket = Socket; 8 | } 9 | 10 | NTP::~NTP() 11 | { 12 | } 13 | 14 | void ReadTime() 15 | { 16 | fixme("ReadTime()"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /kernel/network/TransmissionControlProtocol.cpp: -------------------------------------------------------------------------------- 1 | #include "NetworkController.hpp" 2 | 3 | namespace NetworkTCP 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /kernel/proc/Events.cpp: -------------------------------------------------------------------------------- 1 | #include "events.hpp" 2 | -------------------------------------------------------------------------------- /kernel/proc/InterProcessCommunication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ipc.hpp" 3 | 4 | InterProcessCommunication::IPC *ipc = nullptr; 5 | 6 | namespace InterProcessCommunication 7 | { 8 | IPCHandle *IPC::RegisterHandle(IPCPort Port) 9 | { 10 | if (Port == 0) 11 | return nullptr; 12 | 13 | PCB *pcb = SysGetCurrentProcess(); 14 | 15 | if (pcb->IPCHandles->Get((int)Port) != 0) 16 | return nullptr; 17 | 18 | IPCHandle *handle = new IPCHandle; 19 | handle->ID = -1; 20 | handle->Buffer = nullptr; 21 | handle->Length = 0; 22 | handle->Type = IPCOperationNone; 23 | handle->Listening = 0; 24 | handle->Error = IPCUnknown; 25 | pcb->IPCHandles->AddNode(Port, (uint64_t)handle); 26 | return handle; 27 | } 28 | 29 | IPCHandle *IPC::Wait(IPCPort port) 30 | { 31 | return nullptr; 32 | } 33 | 34 | IPCError IPC::Read(int PID, IPCPort port, void *buf, int size) 35 | { 36 | return IPCError{IPCUnknown}; 37 | } 38 | 39 | IPCError IPC::Write(int PID, IPCPort port, void *buf, int size) 40 | { 41 | return IPCError{IPCUnknown}; 42 | } 43 | 44 | void IPCServiceStub() 45 | { 46 | trace("IPC Service Started."); 47 | SysSetThreadPriority(1); 48 | // TODO: do something useful here, like, IPC event viewer or smth... 49 | while (1) 50 | ; 51 | } 52 | 53 | IPC::IPC() 54 | { 55 | IPCProc = SysCreateProcess("IPC Service", CBElevation::System); 56 | SysCreateThread(IPCProc, (uint64_t)IPCServiceStub, 0, 0); 57 | } 58 | 59 | IPC::~IPC() 60 | { 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /kernel/proc/Task.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../drivers/serial.h" 8 | 9 | using namespace Tasking; 10 | 11 | void StartTasking(uint64_t Address, TaskingMode Mode) 12 | { 13 | CLI; 14 | trace("Initializing Syscalls..."); 15 | init_syscalls(); 16 | BS->IncreaseProgres(); 17 | trace("Starting tasking mode %d", Mode); 18 | switch (Mode) 19 | { 20 | case TaskingMode::Mono: 21 | { 22 | monot = new MonoTasking(Address); 23 | BS->IncreaseProgres(); 24 | break; 25 | } 26 | case TaskingMode::Multi: 27 | { 28 | mt = new Multitasking; 29 | mt->CreateThread(mt->CreateProcess(nullptr, (char *)"kernel", CBElevation::Kernel), Address, 0, 0); 30 | MultitaskingSchedulerEnabled = true; 31 | BS->IncreaseProgres(); 32 | break; 33 | } 34 | default: 35 | { 36 | STI; 37 | throw; 38 | break; 39 | } 40 | } 41 | STI; 42 | } 43 | -------------------------------------------------------------------------------- /kernel/proc/binary.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | enum BinType 7 | { 8 | BIN_TYPE_UNKNOWN, 9 | BIN_TYPE_ELF, 10 | BIN_TYPE_PE, 11 | BIN_TYPE_NE, 12 | BIN_TYPE_MZ, 13 | }; 14 | 15 | BinType GetBinaryType(const char *Path); 16 | PCB *ExecuteBinary(const char *Path, uint64_t Arg0, uint64_t Arg1, CBElevation Elevation); 17 | -------------------------------------------------------------------------------- /kernel/proc/events.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | -------------------------------------------------------------------------------- /kernel/proc/exec/elf.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "exec.hpp" 6 | 7 | RetStructData ExecuteELF(const char *Path, CBElevation Elevation, VMM::PageTableManager ptm); 8 | -------------------------------------------------------------------------------- /kernel/proc/exec/exec.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct RetStructData 4 | { 5 | __UINT64_TYPE__ Offset; 6 | __UINT64_TYPE__ Entry; 7 | }; 8 | -------------------------------------------------------------------------------- /kernel/proc/exec/mz.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "exec.hpp" 6 | 7 | RetStructData ExecuteMZ(const char *Path, CBElevation Elevation, VMM::PageTableManager ptm); 8 | -------------------------------------------------------------------------------- /kernel/proc/exec/ne.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "exec.hpp" 6 | 7 | RetStructData ExecuteNE(const char *Path, CBElevation Elevation, VMM::PageTableManager ptm); 8 | -------------------------------------------------------------------------------- /kernel/proc/exec/pe.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "exec.hpp" 6 | 7 | RetStructData ExecutePE(const char *Path, CBElevation Elevation, VMM::PageTableManager ptm); 8 | -------------------------------------------------------------------------------- /kernel/proc/ipc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace InterProcessCommunication 6 | { class IPC 7 | { 8 | private: 9 | PCB *IPCProc; 10 | 11 | public: 12 | IPC(); 13 | ~IPC(); 14 | 15 | IPCHandle *RegisterHandle(IPCPort Port); 16 | IPCHandle *Wait(IPCPort port); 17 | IPCError Read(int pid, IPCPort port, void *buf, int size); 18 | IPCError Write(int pid, IPCPort port, void *buf, int size); 19 | }; 20 | } 21 | 22 | extern InterProcessCommunication::IPC *ipc; 23 | -------------------------------------------------------------------------------- /kernel/security/security.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../syscalls/syscalls.hpp" 4 | 5 | uint64_t CreateToken(); 6 | void TrustToken(uint64_t Token, bool Process, uint64_t ID, /* enum TokenTrustLevel */ int TrustLevel); 7 | bool CanSyscall(SyscallsRegs *regs); 8 | -------------------------------------------------------------------------------- /kernel/syscalls/syscalls.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // #define DEBUG_SYSCALLS 1 6 | 7 | #ifdef DEBUG_SYSCALLS 8 | #define syscldbg(m, ...) debug(m, ##__VA_ARGS__) 9 | #else 10 | #define syscldbg(m, ...) 11 | #endif 12 | 13 | typedef struct _SyscallsRegs 14 | { 15 | uint64_t r15, r14, r13, r12, r11, r10, r9, r8; 16 | uint64_t rbp, rdi, rsi, rdx, rcx, rbx, rax; 17 | uint64_t int_num, error_code, rip, cs, rflags, rsp, ss; 18 | } SyscallsRegs; 19 | 20 | uint64_t HandleFennixSyscalls(SyscallsRegs *regs); 21 | uint64_t HandleLinuxSyscalls(SyscallsRegs *regs); 22 | -------------------------------------------------------------------------------- /kernel/sysrecovery/Recovery.cpp: -------------------------------------------------------------------------------- 1 | #include "recovery.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../drivers/keyboard.hpp" 9 | #include "../cpu/acpi.hpp" 10 | 11 | namespace SystemRecovery 12 | { 13 | Recovery::Recovery() 14 | { 15 | trace("Recovery mode triggered."); 16 | CLI; 17 | CurrentDisplay->Clear(0x101010); 18 | printf("%s - %s | Recovery Mode", KERNEL_NAME, KERNEL_VERSION); 19 | /* ... do stuff ... */ 20 | uint8_t sc = 0; 21 | while (sc != 1) // esc 22 | { 23 | CLI; 24 | sc = ps2keyboard->GetLastScanCode(); 25 | STI; 26 | } 27 | printf("\nRebooting..."); 28 | #if defined(__amd64__) || defined(__i386__) 29 | dsdt->reboot(); 30 | #endif 31 | } 32 | 33 | Recovery::~Recovery() 34 | { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /kernel/sysrecovery/recovery.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace SystemRecovery 4 | { 5 | class Recovery 6 | { 7 | public: 8 | Recovery(); 9 | ~Recovery(); 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /kernel/test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void do_libs_test(); 4 | void do_mem_bitmap_print(); 5 | void do_mem_test(); 6 | extern "C" void do_interrupts_mem_test(); 7 | void do_tasking_test(); 8 | void do_stacktrace_test(); 9 | void do_network_test(); -------------------------------------------------------------------------------- /kernel/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef __FENNIX_KERNEL_TIMER_H__ 2 | #define __FENNIX_KERNEL_TIMER_H__ 3 | 4 | #include 5 | 6 | struct ActiveTimers 7 | { 8 | bool APIC; 9 | bool HPET; 10 | bool PIT; 11 | bool TSC; 12 | }; 13 | 14 | extern struct ActiveTimers active_timers; 15 | 16 | extern volatile uint64_t ticks; 17 | EXTERNC void sleep(uint64_t Seconds); 18 | EXTERNC void msleep(uint64_t Miliseconds); 19 | EXTERNC void usleep(uint64_t Microseconds); 20 | EXTERNC void nsleep(uint64_t Nanoseconds); 21 | EXTERNC uint32_t get_timer_clock(); 22 | EXTERNC uint64_t counter(); 23 | EXTERNC void TimerOneShot(uint32_t Vector, uint64_t Miliseconds); 24 | EXTERNC void init_timer(); 25 | 26 | #endif // !__FENNIX_KERNEL_TIMER_H__ 27 | -------------------------------------------------------------------------------- /kernel/timer/HPETTimer.cpp: -------------------------------------------------------------------------------- 1 | #include "hpet.h" 2 | #include 3 | #include "../cpu/acpi.hpp" 4 | #include 5 | 6 | bool HPET_initialized = false; 7 | struct HPET *hpet; 8 | static uint32_t clk = 0; 9 | 10 | uint32_t get_clk() 11 | { 12 | return clk; 13 | } 14 | 15 | uint64_t hpet_read_counter() 16 | { 17 | return mminq(&hpet->main_counter_value); 18 | } 19 | 20 | void hpet_uwait(uint64_t Microseconds) 21 | { 22 | uint64_t target = hpet_read_counter() + (Microseconds * 1000000000) / clk; 23 | while (hpet_read_counter() < target) 24 | ; 25 | } 26 | 27 | void hpet_mwait(uint64_t Miliseconds) 28 | { 29 | hpet_uwait(Miliseconds * 10000); 30 | } 31 | 32 | void hpet_wait(uint64_t Seconds) 33 | { 34 | hpet_uwait(Seconds * 1000000); 35 | } 36 | 37 | void init_HPET() 38 | { 39 | #if defined(__amd64__) || defined(__i386__) 40 | trace("Initializing HPET timer"); 41 | if (!acpi->HPET) 42 | { 43 | warn("HPET timer is not supported"); 44 | return; 45 | } 46 | MapMemory(NULL, (void *)acpi->HPET->address.Address, (void *)acpi->HPET->address.Address, RW | PCD); 47 | hpet = (HPET *)(acpi->HPET->address.Address); 48 | debug("%s timer is at address %016p", acpi->HPET->header.OEMID, (void *)acpi->HPET->address.Address); 49 | clk = hpet->general_capabilities >> 32; 50 | mmoutq(&hpet->general_configuration, 0); 51 | mmoutq(&hpet->main_counter_value, 0); 52 | mmoutq(&hpet->general_configuration, 1); 53 | HPET_initialized = true; 54 | #endif 55 | } 56 | 57 | void HPET_oneshot(uint32_t Vector, uint64_t Miliseconds) 58 | { 59 | err("HPET One-Shot is not implemented!"); 60 | } 61 | 62 | void disable_HPET() 63 | { 64 | HPET_initialized = false; 65 | } 66 | -------------------------------------------------------------------------------- /kernel/timer/TSC.cpp: -------------------------------------------------------------------------------- 1 | #include "tsc.h" 2 | #include "../cpu/cpuid.h" 3 | #include 4 | 5 | void TSC_sleep(uint64_t Nanoseconds) 6 | { 7 | if (cpu_feature(CPUID_FEAT_RDX_TSC)) 8 | { 9 | // TODO: Calibrate the TSC timer 10 | static int once = 0; 11 | if (!once++) 12 | warn("Sleeping using TSC is not fully supported."); 13 | uint64_t start = tsc(); 14 | while (tsc() - start < Nanoseconds) 15 | ; 16 | } 17 | else 18 | { 19 | warn("RDTSC is not supported."); 20 | } 21 | } 22 | 23 | void TSC_oneshot(uint32_t Vector, uint64_t Miliseconds) 24 | { 25 | err("TSC One-Shot is not implemented!"); 26 | } 27 | -------------------------------------------------------------------------------- /kernel/timer/apic_timer.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern bool APICTimer_initialized; 4 | extern uint64_t apic_timer_ticks; 5 | 6 | EXTERNC uint64_t apictimer_read_counter(); 7 | EXTERNC uint64_t apictimer_read_clock(); 8 | EXTERNC void apictimer_nwait(uint64_t Nanoseconds); 9 | EXTERNC void apictimer_uwait(uint64_t Microseconds); 10 | EXTERNC void apictimer_mwait(uint64_t Miliseconds); 11 | EXTERNC void apictimer_wait(uint64_t Seconds); 12 | EXTERNC void init_APICTimer(); 13 | EXTERNC void APIC_oneshot(uint32_t Vector, uint64_t Miliseconds); 14 | -------------------------------------------------------------------------------- /kernel/timer/hpet.h: -------------------------------------------------------------------------------- 1 | #ifndef __FENNIX_KERNEL_HPET_H__ 2 | #define __FENNIX_KERNEL_HPET_H__ 3 | 4 | #include 5 | 6 | struct HPET 7 | { 8 | uint64_t general_capabilities; 9 | uint64_t reserved; 10 | uint64_t general_configuration; 11 | uint64_t reserved2; 12 | uint64_t general_int_status; 13 | uint64_t reserved3; 14 | uint64_t reserved4[24]; 15 | uint64_t main_counter_value; 16 | uint64_t reserved5; 17 | }; 18 | 19 | extern bool HPET_initialized; 20 | EXTERNC uint32_t get_clk(); 21 | EXTERNC uint64_t hpet_read_counter(); 22 | EXTERNC void hpet_uwait(uint64_t Microseconds); 23 | EXTERNC void hpet_mwait(uint64_t Miliseconds); 24 | EXTERNC void hpet_wait(uint64_t Seconds); 25 | EXTERNC void init_HPET(); 26 | EXTERNC void HPET_oneshot(uint32_t Vector, uint64_t Miliseconds); 27 | EXTERNC void disable_HPET(); 28 | 29 | #endif // !__FENNIX_KERNEL_HPET_H__ -------------------------------------------------------------------------------- /kernel/timer/pit.h: -------------------------------------------------------------------------------- 1 | #ifndef __FENNIX_KERNEL_APIC_PIT_H__ 2 | #define __FENNIX_KERNEL_APIC_PIT_H__ 3 | 4 | #include 5 | 6 | #define PIT_COUNTER0 0x40 7 | #define PIT_CMD 0x43 8 | 9 | #define CMD_MODE0 0x00 10 | #define CMD_MODE1 0x02 11 | #define CMD_MODE2 0x04 12 | #define CMD_MODE3 0x06 13 | #define CMD_MODE4 0x08 14 | #define CMD_MODE5 0x0a 15 | #define CMD_COUNTER0 0x00 16 | #define CMD_COUNTER1 0x40 17 | #define CMD_COUNTER2 0x80 18 | #define CMD_READBACK 0xc0 19 | #define CMD_LATCH 0x00 20 | #define CMD_RW_LOW 0x10 21 | #define CMD_RW_HI 0x20 22 | #define CMD_RW_BOTH 0x30 23 | #define CMD_BINARY 0x00 24 | #define CMD_BCD 0x01 25 | 26 | extern bool PIC_initialized; 27 | uint32_t get_freq(); 28 | void init_pit(); 29 | void pit_wait(uint32_t miliseconds); 30 | uint64_t pit_get_uptime(); 31 | void pit_oneshot(uint32_t Vector, uint64_t Miliseconds); 32 | 33 | #endif // !__FENNIX_KERNEL_APIC_PIT_H__ -------------------------------------------------------------------------------- /kernel/timer/tsc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | EXTERNC void TSC_sleep(uint64_t Nanoseconds); 5 | EXTERNC void TSC_oneshot(uint32_t Vector, uint64_t Miliseconds); 6 | -------------------------------------------------------------------------------- /kernel/ubsan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct source_location 6 | { 7 | const char *file; 8 | uint32_t line; 9 | uint32_t column; 10 | }; 11 | 12 | struct type_descriptor 13 | { 14 | uint16_t kind; 15 | uint16_t info; 16 | char name[]; 17 | }; 18 | 19 | struct type_mismatch_v1_data 20 | { 21 | struct source_location location; 22 | struct type_descriptor *type; 23 | uint8_t alignment; 24 | uint8_t type_check_kind; 25 | }; 26 | 27 | struct out_of_bounds_info 28 | { 29 | struct source_location location; 30 | struct type_descriptor left_type; 31 | struct type_descriptor right_type; 32 | }; 33 | 34 | struct overflow_data 35 | { 36 | struct source_location location; 37 | struct type_descriptor *type; 38 | }; 39 | 40 | struct negative_vla_data 41 | { 42 | struct source_location location; 43 | struct type_descriptor *type; 44 | }; 45 | 46 | struct invalid_value_data 47 | { 48 | struct source_location location; 49 | struct type_descriptor *type; 50 | }; 51 | 52 | struct nonnull_return_data 53 | { 54 | struct source_location location; 55 | }; 56 | 57 | struct nonnull_arg_data 58 | { 59 | struct source_location location; 60 | }; 61 | 62 | struct unreachable_data 63 | { 64 | struct source_location location; 65 | }; 66 | 67 | struct invalid_builtin_data 68 | { 69 | struct source_location location; 70 | uint8_t kind; 71 | }; 72 | 73 | struct array_out_of_bounds_data 74 | { 75 | struct source_location location; 76 | struct type_descriptor *array_type; 77 | struct type_descriptor *index_type; 78 | }; 79 | 80 | struct shift_out_of_bounds_data 81 | { 82 | struct source_location location; 83 | struct type_descriptor *left_type; 84 | struct type_descriptor *right_type; 85 | }; 86 | -------------------------------------------------------------------------------- /libc/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/../include", 7 | "${workspaceFolder}/include" 8 | ], 9 | "defines": [ 10 | "DEBUG", 11 | "KERNEL_NAME", 12 | "KERNEL_VERSION" 13 | ], 14 | "compilerPath": "${workspaceFolder}/../tools/cross/bin/x86_64-elf-gcc", 15 | "cStandard": "gnu17", 16 | "cppStandard": "gnu++20", 17 | "intelliSenseMode": "gcc-x64", 18 | "forcedInclude": [], 19 | "browse": { 20 | "path": [] 21 | }, 22 | "configurationProvider": "ms-vscode.makefile-tools" 23 | } 24 | ], 25 | "version": 4 26 | } -------------------------------------------------------------------------------- /libc/FennixLibc.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ] 7 | } -------------------------------------------------------------------------------- /libc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | build: 3 | make -C crt build 4 | make -C src build 5 | make -C libgcc build 6 | make -C libg build 7 | 8 | clean: 9 | make -C crt clean 10 | make -C src clean 11 | make -C libgcc clean 12 | make -C libg clean 13 | -------------------------------------------------------------------------------- /libc/crt/Makefile: -------------------------------------------------------------------------------- 1 | include ../../Makefile.conf 2 | 3 | C_SOURCES = $(shell find ./ -type f -name '*.c') 4 | S_SOURCES = $(shell find ./ -type f -name '*.s') 5 | ASM_SOURCES = $(shell find ./ -type f -name '*.asm') 6 | OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.s=.o} 7 | 8 | ifeq ($(OSARCH), amd64) 9 | ASM_ARCH := elf64 10 | else ifeq ($(OSARCH), i686) 11 | ASM_ARCH := elf32 12 | endif 13 | 14 | build: $(OBJ) 15 | mv $^ ../../resources/initrd/system/lib/ 16 | 17 | %.o: %.c 18 | $(CC) -nostdlib -std=c17 -c $< -o $@ 19 | 20 | %.o: %.asm 21 | $(NASM) $< -f $(ASM_ARCH) -o $@ 22 | 23 | %.bin: %.s 24 | $(NASM) $< -f $(ASM_ARCH) -o $@ 25 | 26 | clean: 27 | rm -f ../../resources/initrd/system/lib/*.o 28 | -------------------------------------------------------------------------------- /libc/crt/crt0.c: -------------------------------------------------------------------------------- 1 | extern int main(int argc, char *argv[], char *envp[]); 2 | 3 | void _start() 4 | { 5 | // long argc = 0; 6 | // long argv = 0; 7 | // long envp = 0; 8 | 9 | // __asm__ __volatile__( 10 | // "pushq %%r11\n" 11 | // "pushq %%rcx\n" 12 | // "syscall\n" 13 | // "popq %%rcx\n" 14 | // "popq %%r11\n" 15 | // : "=a"(argc) 16 | // : "a"(8) 17 | // : "memory"); 18 | // __asm__ __volatile__( 19 | // "pushq %%r11\n" 20 | // "pushq %%rcx\n" 21 | // "syscall\n" 22 | // "popq %%rcx\n" 23 | // "popq %%r11\n" 24 | // : "=a"(argv) 25 | // : "a"(9) 26 | // : "memory"); 27 | // __asm__ __volatile__( 28 | // "pushq %%r11\n" 29 | // "pushq %%rcx\n" 30 | // "syscall\n" 31 | // "popq %%rcx\n" 32 | // "popq %%r11\n" 33 | // : "=a"(envp) 34 | // : "a"(10) 35 | // : "memory"); 36 | 37 | // int mainret = main((int)argc, (char **)argv, (char **)envp); 38 | 39 | register long arg1 __asm__("rdi"); 40 | register long arg2 __asm__("rsi"); 41 | int mainret = main((int)arg1, (char **)arg2, (char **)0); 42 | 43 | unsigned long syscall_return = 0; 44 | __asm__ __volatile__( 45 | "pushq %%r11\n" 46 | "pushq %%rcx\n" 47 | "syscall\n" 48 | "popq %%rcx\n" 49 | "popq %%r11\n" 50 | : "=a"(syscall_return) 51 | : "a"(1), "b"(mainret) 52 | : "memory"); 53 | 54 | while (1) 55 | ; 56 | } 57 | -------------------------------------------------------------------------------- /libc/crt/crt1.c: -------------------------------------------------------------------------------- 1 | // TODO: https://stackoverflow.com/a/2724377/9352057 2 | 3 | extern int main(int argc, char *argv[], char *envp[]); 4 | extern void __cxa_finalize(void *f); 5 | 6 | void _start() 7 | { 8 | // long argc = 0; 9 | // long argv = 0; 10 | // long envp = 0; 11 | 12 | // __asm__ __volatile__( 13 | // "pushq %%r11\n" 14 | // "pushq %%rcx\n" 15 | // "syscall\n" 16 | // "popq %%rcx\n" 17 | // "popq %%r11\n" 18 | // : "=a"(argc) 19 | // : "a"(8) 20 | // : "memory"); 21 | // __asm__ __volatile__( 22 | // "pushq %%r11\n" 23 | // "pushq %%rcx\n" 24 | // "syscall\n" 25 | // "popq %%rcx\n" 26 | // "popq %%r11\n" 27 | // : "=a"(argv) 28 | // : "a"(9) 29 | // : "memory"); 30 | // __asm__ __volatile__( 31 | // "pushq %%r11\n" 32 | // "pushq %%rcx\n" 33 | // "syscall\n" 34 | // "popq %%rcx\n" 35 | // "popq %%r11\n" 36 | // : "=a"(envp) 37 | // : "a"(10) 38 | // : "memory"); 39 | 40 | // int mainret = main((int)argc, (char **)argv, (char **)envp); 41 | 42 | register long arg1 __asm__("rdi"); 43 | register long arg2 __asm__("rsi"); 44 | int mainret = main((int)arg1, (char **)arg2, (char **)0); 45 | 46 | __cxa_finalize(0); 47 | unsigned long syscall_return = 0; 48 | __asm__ __volatile__( 49 | "pushq %%r11\n" 50 | "pushq %%rcx\n" 51 | "syscall\n" 52 | "popq %%rcx\n" 53 | "popq %%r11\n" 54 | : "=a"(syscall_return) 55 | : "a"(1), "b"(mainret) 56 | : "memory"); 57 | 58 | while (1) 59 | ; 60 | } 61 | -------------------------------------------------------------------------------- /libc/crt/crtbegin.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/libc/crt/crtbegin.c -------------------------------------------------------------------------------- /libc/crt/crtend.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/libc/crt/crtend.c -------------------------------------------------------------------------------- /libc/crt/crti.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/libc/crt/crti.c -------------------------------------------------------------------------------- /libc/crt/crtn.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/libc/crt/crtn.c -------------------------------------------------------------------------------- /libc/include/alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef _FSL_ALLOCATE_H 2 | #define _FSL_ALLOCATE_H 3 | 4 | #include 5 | #include 6 | 7 | E void *malloc(size_t); 8 | E void *realloc(void *, size_t); 9 | E void *calloc(size_t, size_t); 10 | E void free(void *); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /libc/include/assert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // TODO: assert should call abort(); 4 | 5 | /** 6 | * @brief Evaluate assertion 7 | * 8 | */ 9 | #define assert(x) \ 10 | do \ 11 | { \ 12 | if (!(x)) \ 13 | while (1) \ 14 | ; \ 15 | } while (0) 16 | 17 | #define ASSERT(x) assert(x) 18 | 19 | // static_assert will throw a compile-time exception if assertion fails 20 | #define static_assert(x) \ 21 | switch (x) \ 22 | case 0: \ 23 | case (x): 24 | -------------------------------------------------------------------------------- /libc/include/cdefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define NO_RETURN __attribute__((__noreturn__)) 4 | #define NO_THROW __attribute__((__nothrow__)) 5 | #define PURE __attribute__((__pure__)) 6 | #define NONNULL(params) __attribute__((__nonnull__ params)) 7 | #define RESTRICT __restrict 8 | 9 | #define ArgumentPack() __builtin_va_arg_pack() 10 | #define ArgumentPackLength() __builtin_va_arg_pack_len() 11 | 12 | #ifdef __cplusplus 13 | 14 | #define E extern "C" 15 | #define SEC \ 16 | extern "C" \ 17 | { 18 | #define EEC \ 19 | } 20 | 21 | #else 22 | 23 | #define E extern 24 | #define SEC // Start Extern C 25 | #define EEC // End Extern C 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /libc/include/convert.h: -------------------------------------------------------------------------------- 1 | #ifndef _FSL_CONVERT_H 2 | #define _FSL_CONVERT_H 3 | 4 | #include 5 | 6 | /** 7 | * @brief Returns the absolute value of an integer. 8 | * 9 | * @param i Integral value. 10 | * @return Absolute value of i. 11 | */ 12 | E int abs(int i); 13 | 14 | /** 15 | * @brief Exchange values of two objects 16 | * 17 | * @param x 18 | * @param y 19 | * @return void 20 | */ 21 | E void swap(char *x, char *y); 22 | 23 | /** 24 | * @brief 25 | * 26 | * @param Buffer 27 | * @param i 28 | * @param j 29 | * @return char* 30 | */ 31 | E char *reverse(char *Buffer, int i, int j); 32 | 33 | /** 34 | * @brief Convert string to integer. 35 | * 36 | * @param String String to convert to integer. 37 | * @return Converted integral number as an int value. 38 | */ 39 | E int atoi(const char *String); 40 | 41 | /** 42 | * @brief Convert string to double. 43 | * 44 | * @param String String to convert to double. 45 | * @return Converted floating point as a double value. 46 | */ 47 | E double atof(const char *String); 48 | 49 | /** 50 | * @brief Convert integer to string. 51 | * 52 | * @param Value Value to be converted to a string. 53 | * @param Buffer Array in memory where to store the resulting null-terminated string. 54 | * @param Base Numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary. 55 | * @return A pointer to the resulting null-terminated string. 56 | */ 57 | E char *itoa(int Value, char *Buffer, int Base); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /libc/include/ctype.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * @brief Convert lowercase letter to uppercase 5 | * 6 | */ 7 | #define toupper(c) ((c)-0x20 * (((c) >= 'a') && ((c) <= 'z'))) 8 | 9 | /** 10 | * @brief Convert uppercase letter to lowercase 11 | * 12 | */ 13 | #define tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z'))) 14 | -------------------------------------------------------------------------------- /libc/include/errno.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define EPERM 1 /* Operation not permitted */ 4 | #define ENOENT 2 /* No such file or directory */ 5 | #define ESRCH 3 /* No such process */ 6 | #define EINTR 4 /* Interrupted system call */ 7 | #define EIO 5 /* I/O error */ 8 | #define ENXIO 6 /* No such device or address */ 9 | #define E2BIG 7 /* Argument list too long */ 10 | #define ENOEXEC 8 /* Exec format error */ 11 | #define EBADF 9 /* Bad file number */ 12 | #define ECHILD 10 /* No child processes */ 13 | #define EAGAIN 11 /* Try again */ 14 | #define ENOMEM 12 /* Out of memory */ 15 | #define EACCES 13 /* Permission denied */ 16 | #define EFAULT 14 /* Bad address */ 17 | #define ENOTBLK 15 /* Block device required */ 18 | #define EBUSY 16 /* Device or resource busy */ 19 | #define EEXIST 17 /* File exists */ 20 | #define EXDEV 18 /* Cross-device link */ 21 | #define ENODEV 19 /* No such device */ 22 | #define ENOTDIR 20 /* Not a directory */ 23 | #define EISDIR 21 /* Is a directory */ 24 | #define EINVAL 22 /* Invalid argument */ 25 | #define ENFILE 23 /* File table overflow */ 26 | #define EMFILE 24 /* Too many open files */ 27 | #define ENOTTY 25 /* Not a typewriter */ 28 | #define ETXTBSY 26 /* Text file busy */ 29 | #define EFBIG 27 /* File too large */ 30 | #define ENOSPC 28 /* No space left on device */ 31 | #define ESPIPE 29 /* Illegal seek */ 32 | #define EROFS 30 /* Read-only file system */ 33 | #define EMLINK 31 /* Too many links */ 34 | #define EPIPE 32 /* Broken pipe */ 35 | #define EDOM 33 /* Math argument out of domain of func */ 36 | #define ERANGE 34 /* Math result not representable */ 37 | 38 | #define errno (void *)0 -------------------------------------------------------------------------------- /libc/include/fcntl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /libc/include/inttypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /libc/include/math.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /libc/include/print.h: -------------------------------------------------------------------------------- 1 | #ifndef _FSL_PRINT_H 2 | #define _FSL_PRINT_H 3 | 4 | #include 5 | #include 6 | 7 | E FILE *fslin; 8 | E FILE *fslout; 9 | E FILE *fslerr; 10 | 11 | E int fprintf(FILE *Stream, const char *Format, ...); 12 | E int sprintf(char *s, const char *format, ...); 13 | E int printf(const char *Format, ...); 14 | E int vfprintf(FILE *Stream, const char *Format, va_list Args); 15 | E int vprintf(const char *Format, va_list Args); 16 | E int snprintf(char *String, size_t Length, const char *Format, ...); 17 | E int vsnprintf(char *String, size_t Length, const char *Format, va_list Args); 18 | E int sscanf(const char *String, const char *Format, ...); 19 | E int fputs(const char *String, FILE *Stream); 20 | E int puts(const char *String); 21 | E int fputc(int Char, FILE *Stream); 22 | E int putchar(int Char); 23 | E int fflush(FILE *Stream); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /libc/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #ifndef __GNUC_VA_LIST 8 | #define __GNUC_VA_LIST 9 | typedef __builtin_va_list __gnuc_va_list; 10 | #endif 11 | #ifndef __va_list__ 12 | typedef __builtin_va_list va_list; 13 | #endif 14 | 15 | #define va_start(v, l) __builtin_va_start(v, l) 16 | #define va_end(v) __builtin_va_end(v) 17 | #define va_arg(v, l) __builtin_va_arg(v, l) 18 | 19 | #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L || __cplusplus + 0 >= 201103L 20 | #define va_copy(d, s) __builtin_va_copy(d, s) 21 | #endif 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif -------------------------------------------------------------------------------- /libc/include/string.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | E void *memcpy(void *__restrict__ dest, const void *__restrict__ src, size_t n); 7 | E void *memset(void *dest, int data, size_t nbytes); 8 | E void *memmove(void *dest, const void *src, size_t n); 9 | E int memcmp(const void *vl, const void *vr, size_t n); 10 | 11 | E int strncmp(const char *s1, const char *s2, long unsigned int n); 12 | E long unsigned strlen(const char s[]); 13 | E char *strcat(char *destination, const char *source); 14 | E char *strcpy(char *destination, const char *source); 15 | E char *strncpy(char *destination, const char *source, unsigned long num); 16 | E int strcmp(const char *l, const char *r); 17 | E char *strstr(const char *haystack, const char *needle); 18 | E char *strdup(const char *String); 19 | E char *strchr(const char *String, int Char); 20 | E char *strrchr(const char *String, int Char); 21 | E int strncasecmp(const char *lhs, const char *rhs, long unsigned int Count); 22 | E int strcasecmp(const char *lhs, const char *rhs); 23 | 24 | E int isdigit(int Char); 25 | E int isspace(int Char); 26 | -------------------------------------------------------------------------------- /libc/include/sys/time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /libc/include/sys/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /libc/include/system.h: -------------------------------------------------------------------------------- 1 | #ifndef _FSL_SYSTEM_H 2 | #define _FSL_SYSTEM_H 3 | 4 | #include 5 | 6 | /** 7 | * @brief Write to the system debugger. 8 | * 9 | * @param Format 10 | * @param ... 11 | * @return void 12 | */ 13 | E void WriteSysDebugger(const char *Format, ...); 14 | 15 | /** 16 | * @brief Sleep for a given number of microseconds. 17 | * 18 | * @param Microseconds 19 | * @return void 20 | */ 21 | E void usleep(unsigned long Microseconds); 22 | 23 | /** 24 | * @brief Execute a command in the system shell. 25 | * 26 | * @param Command 27 | * @return int 28 | */ 29 | E int system(const char *Command); 30 | 31 | /** 32 | * @brief Exit the program with a status code. 33 | * 34 | * @param Status 35 | * @return void 36 | */ 37 | E void Exit(int Status) NO_THROW NO_RETURN; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libc/libg/Makefile: -------------------------------------------------------------------------------- 1 | include ../../Makefile.conf 2 | 3 | NAME=g 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../resources/initrd/system/lib/ 8 | 9 | CC = ../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../include/*))) 16 | INCLUDE_DIR = ../../include 17 | HEADERS2 = $(sort $(dir $(wildcard ../include/*))) 18 | INCLUDE2_DIR = ../include 19 | 20 | LDFLAGS := 21 | CFLAGS := -fPIC -I$(INCLUDE_DIR) -I$(INCLUDE2_DIR) 22 | 23 | build: $(OBJECT_NAME) 24 | 25 | $(OBJECT_NAME): $(OBJ) 26 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 27 | %.o: %.c $(HEADERS) $(HEADERS2) 28 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 29 | 30 | %.o: %.cpp $(HEADERS) $(HEADERS2) 31 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 32 | 33 | clean: 34 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 35 | -------------------------------------------------------------------------------- /libc/libg/libgstub.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/libc/libg/libgstub.cpp -------------------------------------------------------------------------------- /libc/libgcc/Makefile: -------------------------------------------------------------------------------- 1 | include ../../Makefile.conf 2 | 3 | NAME=gcc 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../resources/initrd/system/lib/ 8 | 9 | CC = ../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../include/*))) 16 | INCLUDE_DIR = ../../include 17 | HEADERS2 = $(sort $(dir $(wildcard ../include/*))) 18 | INCLUDE2_DIR = ../include 19 | 20 | CFLAGS := -fPIC -I$(INCLUDE_DIR) -I$(INCLUDE2_DIR) 21 | 22 | build: $(OBJECT_NAME) 23 | 24 | $(OBJECT_NAME): $(OBJ) 25 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 26 | %.o: %.c $(HEADERS) $(HEADERS2) 27 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 28 | 29 | %.o: %.cpp $(HEADERS) $(HEADERS2) 30 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 31 | 32 | clean: 33 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 34 | -------------------------------------------------------------------------------- /libc/libgcc/allocator.cpp: -------------------------------------------------------------------------------- 1 | extern "C" void *malloc(unsigned long s); 2 | extern "C" void free(void *p); 3 | extern "C" void *memset(void *dest, int data, unsigned long nbytes); 4 | 5 | void *operator new(unsigned long Size) 6 | { 7 | if (Size == 0) 8 | Size = 1; 9 | if (void *Pointer = malloc(Size)) 10 | { 11 | memset(Pointer, 0, Size); 12 | return Pointer; 13 | } 14 | // warn("new( %llx ) failed!", Size); 15 | throw; 16 | } 17 | 18 | void *operator new[](unsigned long Size) 19 | { 20 | if (Size == 0) 21 | Size = 1; 22 | if (void *Pointer = malloc(Size)) 23 | { 24 | memset(Pointer, 0, Size); 25 | return Pointer; 26 | } 27 | // warn("new[]( %llx ) failed!", Size); 28 | throw; 29 | } 30 | 31 | void operator delete(void *Pointer) 32 | { 33 | free(Pointer); 34 | } 35 | 36 | void operator delete[](void *Pointer) 37 | { 38 | free(Pointer); 39 | } 40 | 41 | void operator delete(void *Pointer, long unsigned int n) 42 | { 43 | free(Pointer); 44 | } 45 | 46 | void operator delete[](void *Pointer, long unsigned int n) 47 | { 48 | free(Pointer); 49 | } 50 | -------------------------------------------------------------------------------- /libc/src/FennixStandardLibrary/alloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // stub 4 | -------------------------------------------------------------------------------- /libc/src/FennixStandardLibrary/file.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | FILE *FileOpen(const char *Filename, const char *Mode) 9 | { 10 | void *ret = (void *)syscall_FileOpen((char *)Filename /*, Mode*/); 11 | if (ret == NULL) 12 | return NULL; 13 | FILE *file = (FILE *)malloc(sizeof(FILE)); 14 | file->Khnd = ret; 15 | return file; 16 | } 17 | 18 | size_t FileRead(uint8_t *Buffer, size_t Size, size_t Count, FILE *Stream) 19 | { 20 | return syscall_FileRead(Stream->Khnd, 0 /*offset*/, Buffer, Size); 21 | } 22 | 23 | size_t FileWrite(const uint8_t *Buffer, size_t Size, size_t Count, FILE *Stream) 24 | { 25 | return syscall_FileWrite(Stream->Khnd, 0 /*offset*/, (void *)Buffer, Size); 26 | } 27 | 28 | int FileSeek(FILE *Stream, long int Offset, enum Seek Whence) 29 | { 30 | WriteSysDebugger("FileSeek( %p %ld %d ) stub\n", Stream, Offset, Whence); 31 | return 0; 32 | } 33 | 34 | long int FileTell(FILE *Stream) 35 | { 36 | WriteSysDebugger("FileTell( %p ) stub\n", Stream); 37 | return 0; 38 | } 39 | 40 | int MakeDirectory(const char *Path, int Mode) 41 | { 42 | WriteSysDebugger("MakeDirectory( %s %d ) stub\n", Path, Mode); 43 | return 0; 44 | } 45 | 46 | int RenameFile(const char *OldFileName, const char *NewFileName) 47 | { 48 | WriteSysDebugger("RenameFile( %s %s ) stub\n", OldFileName, NewFileName); 49 | return 0; 50 | } 51 | 52 | int RemoveFile(const char *FileName) 53 | { 54 | WriteSysDebugger("RemoveFile( %s ) stub\n", FileName); 55 | return 0; 56 | } 57 | 58 | int FileClose(FILE *Stream) 59 | { 60 | syscall_FileClose(Stream->Khnd); 61 | free(Stream); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /libc/src/FennixStandardLibrary/system.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include "../printf.h" 5 | 6 | char syswritedbgbuf[2048]; 7 | 8 | static inline void append_syswritedbg(char s[], char n) 9 | { 10 | long unsigned i = 0; 11 | while (s[i] != '\0') 12 | ++i; 13 | 14 | int len = i; 15 | s[len] = n; 16 | s[len + 1] = '\0'; 17 | } 18 | 19 | static inline void syswritedbgprint_wrapper(char c, void *unused) 20 | { 21 | append_syswritedbg(syswritedbgbuf, c); 22 | (void)unused; 23 | } 24 | 25 | void WriteSysDebugger(const char *Format, ...) 26 | { 27 | // mono 1 - multi 2 28 | if (syscall_getScheduleMode() == 2) 29 | { 30 | // write info about the current thread 31 | } 32 | syswritedbgbuf[0] = '\0'; 33 | va_list args; 34 | va_start(args, Format); 35 | vfctprintf(syswritedbgprint_wrapper, NULL, Format, args); 36 | va_end(args); 37 | syscall_dbg(0x3F8, (char *)syswritedbgbuf); 38 | } 39 | 40 | void usleep(unsigned long Microseconds) 41 | { 42 | syscall_usleep(Microseconds); 43 | } 44 | 45 | int system(const char *Command) 46 | { 47 | // mono 1 - multi 2 48 | if (syscall_getScheduleMode() == 2) 49 | return syscall_createProcess((char *)Command, 0, 0); 50 | else if (syscall_getScheduleMode() == 1) 51 | return -1; 52 | } 53 | 54 | void Exit(int Status) 55 | { 56 | syscall_exit(Status); 57 | while (1) 58 | ; 59 | } 60 | -------------------------------------------------------------------------------- /libc/src/Makefile: -------------------------------------------------------------------------------- 1 | include ../../Makefile.conf 2 | 3 | NAME=c 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../resources/initrd/system/lib/ 8 | 9 | CC = ../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../include/*))) 16 | INCLUDE_DIR = ../../include 17 | HEADERS2 = $(sort $(dir $(wildcard ../include/*))) 18 | INCLUDE2_DIR = ../include 19 | 20 | LDFLAGS := 21 | CFLAGS := -fPIC -I$(INCLUDE_DIR) -I$(INCLUDE2_DIR) 22 | 23 | build: $(OBJECT_NAME) 24 | 25 | $(OBJECT_NAME): $(OBJ) 26 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 27 | 28 | %.o: %.c $(HEADERS) $(HEADERS2) 29 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 30 | 31 | %.o: %.cpp $(HEADERS) $(HEADERS2) 32 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 33 | 34 | clean: 35 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 36 | -------------------------------------------------------------------------------- /libc/src/alloc/liballoc_1_1.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBALLOC_H 2 | #define _LIBALLOC_H 3 | 4 | // #define libPREFIX(func) u##func 5 | #define libPREFIX(func) func 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | extern void *libPREFIX(malloc)(size_t); ///< The standard function. 16 | extern void *libPREFIX(realloc)(void *, size_t); ///< The standard function. 17 | extern void *libPREFIX(calloc)(size_t, size_t); ///< The standard function. 18 | extern void libPREFIX(free)(void *); ///< The standard function. 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /libc/src/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/libc/src/main.c -------------------------------------------------------------------------------- /libc/src/string/mem.c: -------------------------------------------------------------------------------- 1 | void *memcpy(void *__restrict__ dest, const void *__restrict__ src, unsigned long n) 2 | { 3 | unsigned char *d = (unsigned char *)dest; 4 | const unsigned char *c = (const unsigned char *)src; 5 | for (unsigned long i = 0; i < n; i++) 6 | d[i] = c[i]; 7 | return dest; 8 | } 9 | 10 | void *memset(void *dest, int data, unsigned long nbytes) 11 | { 12 | unsigned char *buf = (unsigned char *)dest; 13 | for (unsigned long i = 0; i < nbytes; i++) 14 | buf[i] = (unsigned char)data; 15 | return dest; 16 | } 17 | 18 | void *memmove(void *dest, const void *src, unsigned long n) 19 | { 20 | unsigned char *dst = (unsigned char *)dest; 21 | const unsigned char *srcc = (const unsigned char *)src; 22 | if (dst < srcc) 23 | { 24 | for (unsigned long i = 0; i < n; i++) 25 | dst[i] = srcc[i]; 26 | } 27 | else 28 | { 29 | for (unsigned long i = n; i != 0; i--) 30 | dst[i - 1] = srcc[i - 1]; 31 | } 32 | return dest; 33 | } 34 | 35 | int memcmp(const void *vl, const void *vr, unsigned long n) 36 | { 37 | const unsigned char *l = vl, *r = vr; 38 | for (; n && *l == *r; n--, l++, r++) 39 | ; 40 | return n ? *l - *r : 0; 41 | } 42 | -------------------------------------------------------------------------------- /limine.cfg: -------------------------------------------------------------------------------- 1 | TIMEOUT=0 2 | INTERFACE_BRANDING=Fennix 3 | 4 | :Fennix (Limine) 5 | # DO NOT EDIT! 6 | COMMENT=Boot Fennix using Limine protocol 7 | RESOLUTION=1280x720 8 | PROTOCOL=limine 9 | KERNEL_CMDLINE=debug 10 | KERNEL_PATH=boot:///kernel.fsys 11 | MODULE_PATH=boot:///initrd.tar.gz 12 | -------------------------------------------------------------------------------- /lynx.cfg: -------------------------------------------------------------------------------- 1 | CMDLINE=debug 2 | INITRD=initrd.tar.gz 3 | -------------------------------------------------------------------------------- /resources/initrd/ascii: -------------------------------------------------------------------------------- 1 | . 2 | .xKNNNNNNNNX0d' 3 | 'XNNNNNNNNNNNNNNO. 4 | .XNNKdcccooolcoXNNX. 5 | ONN0.;kOOKXNXO;cNNNK 6 | ,NNNX;..',;;;,''ONNNNc 7 | 0NNNNNNX00OOO0XNNNNNNX 8 | ,NNNNNNNNNNNNNNNNNNNNNN; 9 | ONNNNNNNNNNNNNNNNNNNNNNx 10 | .NNNNNNNNNNNNNNNNNNNNNNNK 11 | xNNNNNNNNNNNNNNNNNNNNNNNN 12 | .NNNNNNNNNNNNNNNNNNNNNNNNN. 13 | oNNNNNNNNNNNNNNNNNNNNNNNNN. 14 | XNNNNNNNNNNNNNNNNNNNNNNNNN' 15 | ,NNNNNNO. lXNNNNNNNNN; 16 | kNNNNNX ;NNNNNNNNN; 17 | .. .NNNNNNX .NNNNNNNNN, 18 | cKNNNNKKNNNNNNK 'NNNNNNNNN. 19 | .kKNNNNNNNNN0o .,ONNNNNNNNN 20 | lXNNNNNNNNNNNNk 21 | :KNNNNNNNNKx. 22 | -------------------------------------------------------------------------------- /resources/initrd/ascii_link: -------------------------------------------------------------------------------- 1 | ascii -------------------------------------------------------------------------------- /resources/initrd/home/default/.config/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/.config/.gitkeep -------------------------------------------------------------------------------- /resources/initrd/home/default/Apps/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitkeep 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /resources/initrd/home/default/Apps/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/Apps/.gitkeep -------------------------------------------------------------------------------- /resources/initrd/home/default/Desktop/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/Desktop/.gitkeep -------------------------------------------------------------------------------- /resources/initrd/home/default/Documents/Sample File.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /resources/initrd/home/default/Downloads/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/Downloads/.gitkeep -------------------------------------------------------------------------------- /resources/initrd/home/default/Games/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitkeep 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /resources/initrd/home/default/Games/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/Games/.gitkeep -------------------------------------------------------------------------------- /resources/initrd/home/default/Music/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/Music/.gitkeep -------------------------------------------------------------------------------- /resources/initrd/home/default/Pictures/Fennix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/Pictures/Fennix.png -------------------------------------------------------------------------------- /resources/initrd/home/default/Videos/Fennix.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/home/default/Videos/Fennix.mp4 -------------------------------------------------------------------------------- /resources/initrd/system/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitkeep 3 | !.gitignore 4 | !config/kernel.cfg 5 | !config/nic.json 6 | !drivers/driver.cfg 7 | !fonts/* 8 | !lib/.gitkeep 9 | !wallpapers/* 10 | !*/ 11 | -------------------------------------------------------------------------------- /resources/initrd/system/config/kernel.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/config/kernel.cfg -------------------------------------------------------------------------------- /resources/initrd/system/drivers/driver.cfg: -------------------------------------------------------------------------------- 1 | # blacklisted drivers 2 | blacklist="" -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/LICENSE: -------------------------------------------------------------------------------- 1 | Tamsyn font is free. You are hereby granted permission to use, copy, modify, 2 | and distribute it as you see fit. 3 | 4 | Tamsyn font is provided "as is" without any express or implied warranty. 5 | 6 | The author makes no representations about the suitability of this font for 7 | a particular purpose. 8 | 9 | In no event will the author be held liable for damages arising from the use 10 | of this font. 11 | -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn10x20b.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn10x20b.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn10x20r.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn10x20r.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn5x9b.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn5x9b.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn5x9r.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn5x9r.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn6x12b.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn6x12b.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn6x12r.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn6x12r.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x13b.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x13b.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x13r.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x13r.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x14b.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x14b.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x14r.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn7x14r.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x15b.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x15b.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x15r.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x15r.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x16b.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x16b.psf -------------------------------------------------------------------------------- /resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x16r.psf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/fonts/tamsyn-font-1.11/Tamsyn8x16r.psf -------------------------------------------------------------------------------- /resources/initrd/system/lib/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/lib/.gitkeep -------------------------------------------------------------------------------- /resources/initrd/system/wallpapers/IMG_0199.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/wallpapers/IMG_0199.JPG -------------------------------------------------------------------------------- /resources/initrd/system/wallpapers/IMG_0199_1000x1000.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/wallpapers/IMG_0199_1000x1000.JPG -------------------------------------------------------------------------------- /resources/initrd/system/wallpapers/IMG_0199_1000x1000.TGA: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/wallpapers/IMG_0199_1000x1000.TGA -------------------------------------------------------------------------------- /resources/initrd/system/wallpapers/fennec.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/system/wallpapers/fennec.tga -------------------------------------------------------------------------------- /resources/initrd/test.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /resources/initrd/test_dir/.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | -------------------------------------------------------------------------------- /resources/initrd/test_dir/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in {1..2048} 4 | do 5 | touch $i.txt 6 | echo "This file name is $i.txt!" > $i.txt 7 | done 8 | -------------------------------------------------------------------------------- /resources/initrd/tmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/initrd/tmp/.gitkeep -------------------------------------------------------------------------------- /resources/modules/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/resources/modules/.gitkeep -------------------------------------------------------------------------------- /startup.nsh: -------------------------------------------------------------------------------- 1 | @echo -off 2 | mode 80 25 3 | 4 | cls 5 | if exist .\EFI\BOOT\BOOTX64.EFI then 6 | .\EFI\BOOT\BOOTX64.EFI 7 | goto END 8 | endif 9 | 10 | if exist fs0:\EFI\BOOT\BOOTX64.EFI then 11 | fs0: 12 | echo Fennix Bootloader found in fs0: 13 | .\EFI\BOOT\BOOTX64.EFI 14 | goto END 15 | endif 16 | 17 | if exist fs1:\EFI\BOOT\BOOTX64.EFI then 18 | fs1: 19 | echo Fennix Bootloader found in fs1: 20 | .\EFI\BOOT\BOOTX64.EFI 21 | goto END 22 | endif 23 | 24 | if exist fs2:\EFI\BOOT\BOOTX64.EFI then 25 | fs2: 26 | echo Fennix Bootloader found in fs2: 27 | .\EFI\BOOT\BOOTX64.EFI 28 | goto END 29 | endif 30 | 31 | if exist fs3:\EFI\BOOT\BOOTX64.EFI then 32 | fs3: 33 | echo Fennix Bootloader found in fs3: 34 | .\EFI\BOOT\BOOTX64.EFI 35 | goto END 36 | endif 37 | 38 | if exist fs4:\EFI\BOOT\BOOTX64.EFI then 39 | fs4: 40 | echo Fennix Bootloader found in fs4: 41 | .\EFI\BOOT\BOOTX64.EFI 42 | goto END 43 | endif 44 | 45 | if exist fs5:\EFI\BOOT\BOOTX64.EFI then 46 | fs5: 47 | echo Fennix Bootloader found in fs5: 48 | .\EFI\BOOT\BOOTX64.EFI 49 | goto END 50 | endif 51 | 52 | if exist fs6:\EFI\BOOT\BOOTX64.EFI then 53 | fs6: 54 | echo Fennix Bootloader found in fs6: 55 | .\EFI\BOOT\BOOTX64.EFI 56 | goto END 57 | endif 58 | 59 | if exist fs7:\EFI\BOOT\BOOTX64.EFI then 60 | fs7: 61 | echo Fennix Bootloader found in fs7: 62 | .\EFI\BOOT\BOOTX64.EFI 63 | goto END 64 | endif 65 | 66 | echo "Unable to find the bootloader". 67 | 68 | :END 69 | -------------------------------------------------------------------------------- /tools/website/assets/Background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/tools/website/assets/Background.png -------------------------------------------------------------------------------- /tools/website/js/script.js: -------------------------------------------------------------------------------- 1 | if (document.addEventListener) { 2 | document.addEventListener('contextmenu', function (e) { 3 | e.preventDefault(); 4 | }, false); 5 | } else { 6 | document.attachEvent('oncontextmenu', function () { 7 | window.event.returnValue = false; 8 | }); 9 | } 10 | -------------------------------------------------------------------------------- /userspace/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | make -C libs build 3 | make -C apps build 4 | make -C drivers build 5 | 6 | clean: 7 | make -C libs clean 8 | make -C apps clean 9 | make -C drivers clean 10 | -------------------------------------------------------------------------------- /userspace/apps/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | make -C games build 3 | make -C system build 4 | make -C user build 5 | 6 | clean: 7 | make -C games clean 8 | make -C system clean 9 | make -C user clean -------------------------------------------------------------------------------- /userspace/apps/games/.gitignore: -------------------------------------------------------------------------------- 1 | doomgeneric 2 | -------------------------------------------------------------------------------- /userspace/apps/games/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | make -C tictactoe build 3 | ifneq (,$(wildcard doomgeneric)) 4 | make -j$(shell nproc) -C doomgeneric build 5 | else 6 | git clone https://github.com/EnderIce2/doomgeneric.git 7 | make -j$(shell nproc) -C doomgeneric build 8 | endif 9 | 10 | clean: 11 | make -C tictactoe clean 12 | ifneq (,$(wildcard doomgeneric)) 13 | make -j$(shell nproc) -C doomgeneric clean 14 | else 15 | git clone https://github.com/EnderIce2/doomgeneric.git 16 | make -j$(shell nproc) -C doomgeneric clean 17 | endif 18 | -------------------------------------------------------------------------------- /userspace/apps/games/tictactoe/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=ttt 4 | OUTPUT_DIR=../../../../resources/initrd/home/default/Games/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | LD = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ld 8 | 9 | C_SOURCES = $(shell find ./ -type f -name '*.c') 10 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 11 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 12 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 13 | INCLUDE_DIR = ../../../../libc/include 14 | 15 | LDFLAGS := --sysroot=../../../../resources/initrd/system/ 16 | CFLAGS := -fPIC -I$(INCLUDE_DIR) 17 | 18 | build: $(NAME) 19 | 20 | $(NAME): $(OBJ) 21 | $(CC) $(LDFLAGS) $(OBJ) -o $(OUTPUT_DIR)$@ -lmonoton -lscparse -lcwalk 22 | 23 | %.o: %.c $(HEADERS) 24 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 25 | 26 | %.o: %.cpp $(HEADERS) 27 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 28 | 29 | clean: 30 | rm -f $(OUTPUT_DIR)$(NAME) $(OBJ) 31 | -------------------------------------------------------------------------------- /userspace/apps/games/tictactoe/tictactoe.cpp: -------------------------------------------------------------------------------- 1 | // TODO: Implement the game logic 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | return -1; 6 | } 7 | -------------------------------------------------------------------------------- /userspace/apps/system/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | make -C init build 3 | make -C drvmgr build 4 | make -C usermodecrash_handler build 5 | make -C monoton build 6 | make -C uiserver build 7 | make -C wm build 8 | make -C fesktop build 9 | make -C shutdown build 10 | make -C reboot build 11 | 12 | clean: 13 | make -C init clean 14 | make -C drvmgr clean 15 | make -C usermodecrash_handler clean 16 | make -C monoton clean 17 | make -C uiserver clean 18 | make -C wm clean 19 | make -C fesktop clean 20 | make -C shutdown clean 21 | make -C reboot clean -------------------------------------------------------------------------------- /userspace/apps/system/drvmgr/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=drvmgr 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/system/drvmgr/drvmgr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | syscall_dbg(0x3F8, (char *)"[DriverManager] Initialized\n"); 7 | while (1) 8 | ; 9 | return 1; 10 | } 11 | -------------------------------------------------------------------------------- /userspace/apps/system/fesktop/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=fesktop 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/system/fesktop/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void drawrectangle(uint64_t X, uint64_t Y, uint64_t W, uint64_t H, uint32_t C) 4 | { 5 | uint64_t address = syscall_displayAddress(); 6 | uint64_t width = syscall_displayWidth(); 7 | uint64_t height = syscall_displayHeight(); 8 | uint64_t ppsl = syscall_displayPixelsPerScanLine(); 9 | for (int y = Y; y < Y + H; y++) 10 | for (int x = X; x < X + W; x++) 11 | { 12 | if (x >= width || y >= height) 13 | continue; 14 | ((uint32_t *)address)[x + (y * ppsl)] = C; 15 | } 16 | } 17 | 18 | void Desktop() 19 | { 20 | uint64_t width = syscall_displayWidth(); 21 | uint64_t height = syscall_displayHeight(); 22 | drawrectangle(0, 0, width, height - 20, 0x008080); 23 | 24 | while (1) 25 | ; 26 | } 27 | 28 | void Dock() 29 | { 30 | uint64_t width = syscall_displayWidth(); 31 | uint64_t height = syscall_displayHeight(); 32 | 33 | drawrectangle(0, height - 20, width, 20, 0xacacac); 34 | 35 | // drawrectangle(2, height - 18, 50, 16, 0x5c5c5c); 36 | // drawrectangle(3, height - 17, 49, 15, 0x8c8c8c); 37 | 38 | int color1 = 0x5c5c5c; 39 | int color2 = 0x8c8c8c; 40 | 41 | while (1) 42 | { 43 | if (color1 > 0xFFFFFF) 44 | color1 = 0x5c5c5c; 45 | if (color2 > 0xFFFFFF) 46 | color2 = 0x8c8c8c; 47 | 48 | drawrectangle(2, height - 18, 50, 16, color1); 49 | drawrectangle(3, height - 17, 49, 15, color2); 50 | 51 | color1 += 0x00000F; 52 | color2 += 0x00000F; 53 | } 54 | } 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | // syscall_createThread((long)Desktop, 0, 0); 59 | // syscall_createThread((long)Dock, 0, 0); 60 | while (1) 61 | ; 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /userspace/apps/system/init/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=init 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/system/init/init.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void monotasking_shell_exit() 5 | { 6 | syscall_dbg(0x3F8, (char *)"[INIT] The shell exited!\n"); 7 | // TODO: cleanup everything and shutdown beacuse this process should not be killed 8 | } 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | syscall_dbg(0x3F8, (char *)"[INIT] This is a test so we can know if the syscalls are working as expected.\n"); 13 | // mono 1 - multi 2 14 | if (syscall_getScheduleMode() == 1) 15 | { 16 | syscall_dbg(0x3F8, (char *)"[INIT] Kernel is running under monotasking mode.\n"); 17 | /* ... do stuff ... */ 18 | syscall_createProcess((char *)"/system/monoton", 0, 0); 19 | syscall_pushTask((uint64_t)monotasking_shell_exit); 20 | return 0; 21 | } 22 | else 23 | { 24 | syscall_dbg(0x3F8, (char *)"[INIT] Kernel is running under multitasking mode.\n"); 25 | /* ... do stuff ... */ 26 | syscall_createProcess((char *)"/system/uiserver", 0, 0); 27 | 28 | while (1) 29 | ; 30 | } 31 | return 1; 32 | } 33 | -------------------------------------------------------------------------------- /userspace/apps/system/monoton/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=monoton 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | LD = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ld 8 | 9 | C_SOURCES = $(shell find ./ -type f -name '*.c') 10 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 11 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 12 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 13 | INCLUDE_DIR = ../../../../libc/include 14 | 15 | LDFLAGS := --sysroot=../../../../resources/initrd/system/ 16 | CFLAGS := -fPIC -I$(INCLUDE_DIR) 17 | 18 | build: $(NAME) 19 | 20 | $(NAME): $(OBJ) 21 | $(CC) $(LDFLAGS) $(OBJ) -o $(OUTPUT_DIR)$@ -lmonoton -lscparse -lcwalk -fPIC 22 | 23 | %.o: %.c $(HEADERS) 24 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 25 | 26 | %.o: %.cpp $(HEADERS) 27 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 28 | 29 | clean: 30 | rm -f $(OUTPUT_DIR)$(NAME) $(OBJ) 31 | -------------------------------------------------------------------------------- /userspace/apps/system/monoton/cmds.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | void Cat(File *CurrentPath, const char *Arguments); 5 | -------------------------------------------------------------------------------- /userspace/apps/system/monoton/dumper.cpp: -------------------------------------------------------------------------------- 1 | #include "dumper.hpp" 2 | 3 | #include "../../../libs/monoton/monotonlib.h" 4 | 5 | extern MonotonLib::mtl *mono; 6 | 7 | #define DumperPrint(m, ...) mono->printf(m, ##__VA_ARGS__) 8 | 9 | void DumpData(const char *Description, void *Address, unsigned long Length) 10 | { 11 | mono->print("-------------------------------------------------------------------------\n"); 12 | unsigned char *AddressChar = (unsigned char *)Address; 13 | unsigned char Buffer[17]; 14 | unsigned long Iterate; 15 | 16 | if (Description != nullptr) 17 | DumperPrint("%s:\n", Description); 18 | 19 | for (Iterate = 0; Iterate < Length; Iterate++) 20 | { 21 | if ((Iterate % 16) == 0) 22 | { 23 | if (Iterate != 0) 24 | DumperPrint(" %s\n", Buffer); 25 | DumperPrint(" %04x ", Iterate); 26 | } 27 | 28 | DumperPrint(" %02x", AddressChar[Iterate]); 29 | 30 | if ((AddressChar[Iterate] < 0x20) || (AddressChar[Iterate] > 0x7e)) 31 | Buffer[Iterate % 16] = '.'; 32 | else 33 | Buffer[Iterate % 16] = AddressChar[Iterate]; 34 | 35 | Buffer[(Iterate % 16) + 1] = '\0'; 36 | } 37 | 38 | while ((Iterate % 16) != 0) 39 | { 40 | DumperPrint(" "); 41 | Iterate++; 42 | } 43 | 44 | DumperPrint(" %s\n", Buffer); 45 | mono->print("-------------------------------------------------------------------------\n"); 46 | } 47 | -------------------------------------------------------------------------------- /userspace/apps/system/monoton/dumper.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void DumpData(const char *Description, void *Address, unsigned long Length); 4 | -------------------------------------------------------------------------------- /userspace/apps/system/monoton/monoton.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../../libs/monoton/monotonlib.h" 3 | #include "../../../libs/scparse/scparse.h" 4 | #include 5 | #include 6 | 7 | static inline void backspace(char s[]) 8 | { 9 | int len = strlen(s); 10 | s[len - 1] = '\0'; 11 | } 12 | 13 | static inline void append(char s[], char n) 14 | { 15 | int len = strlen(s); 16 | s[len] = n; 17 | s[len + 1] = '\0'; 18 | } 19 | 20 | static inline int isempty_1(char *str) 21 | { 22 | long unsigned i = 0; 23 | while (str[i] != '\0') 24 | ++i; 25 | 26 | if (i == 0) 27 | return 1; 28 | 29 | while (*str != '\0') 30 | { 31 | if (!isspace(*str)) 32 | return 0; 33 | str++; 34 | } 35 | return 1; 36 | } 37 | 38 | extern MonotonLib::mtl *mono; 39 | 40 | char *usr(); 41 | char *pwd(); 42 | void InitLogin(); 43 | -------------------------------------------------------------------------------- /userspace/apps/system/reboot/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=reboot 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | LD = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ld 8 | 9 | C_SOURCES = $(shell find ./ -type f -name '*.c') 10 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 11 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 12 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 13 | INCLUDE_DIR = ../../../../libc/include 14 | 15 | LDFLAGS := --sysroot=../../../../resources/initrd/system/ 16 | CFLAGS := -fPIC -I$(INCLUDE_DIR) 17 | 18 | build: $(NAME) 19 | 20 | $(NAME): $(OBJ) 21 | $(CC) $(LDFLAGS) $(OBJ) -o $(OUTPUT_DIR)$@ 22 | 23 | %.o: %.c $(HEADERS) 24 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 25 | 26 | %.o: %.cpp $(HEADERS) 27 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 28 | 29 | clean: 30 | rm -f $(OUTPUT_DIR)$(NAME) $(OBJ) 31 | -------------------------------------------------------------------------------- /userspace/apps/system/reboot/reboot.cpp: -------------------------------------------------------------------------------- 1 | #include "reboot.hpp" 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | syscall_reboot(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /userspace/apps/system/reboot/reboot.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /userspace/apps/system/shutdown/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=shutdown 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | LD = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ld 8 | 9 | C_SOURCES = $(shell find ./ -type f -name '*.c') 10 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 11 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 12 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 13 | INCLUDE_DIR = ../../../../libc/include 14 | 15 | LDFLAGS := --sysroot=../../../../resources/initrd/system/ 16 | CFLAGS := -fPIC -I$(INCLUDE_DIR) 17 | 18 | build: $(NAME) 19 | 20 | $(NAME): $(OBJ) 21 | $(CC) $(LDFLAGS) $(OBJ) -o $(OUTPUT_DIR)$@ 22 | 23 | %.o: %.c $(HEADERS) 24 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 25 | 26 | %.o: %.cpp $(HEADERS) 27 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 28 | 29 | clean: 30 | rm -f $(OUTPUT_DIR)$(NAME) $(OBJ) 31 | -------------------------------------------------------------------------------- /userspace/apps/system/shutdown/shutdown.cpp: -------------------------------------------------------------------------------- 1 | #include "shutdown.hpp" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | WriteSysDebugger("Shutting down...\n"); 7 | syscall_shutdown(); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /userspace/apps/system/shutdown/shutdown.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /userspace/apps/system/uiserver/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=uiserver 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/system/uiserver/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum MouseButton 4 | { 5 | MouseNone, 6 | Right, 7 | Middle, 8 | Left 9 | }; 10 | 11 | struct MouseInfo 12 | { 13 | MouseButton Buttons; 14 | uint32_t X; 15 | uint32_t Y; 16 | }; 17 | 18 | MouseInfo ReadMouseBuffer() 19 | { 20 | File *mousefile = (File *)syscall_FileOpen((char *)"/system/dev/mouse"); 21 | MouseInfo info = {MouseNone, 0, 0}; 22 | if (mousefile->Status == FileStatus::OK) 23 | syscall_FileRead(mousefile, 0, (uint8_t *)&info, sizeof(MouseInfo)); 24 | syscall_FileClose(mousefile); 25 | return info; 26 | } 27 | 28 | void EventListener() 29 | { 30 | while (true) 31 | { 32 | } 33 | } 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | syscall_createThread((long)EventListener, 0, 0); 38 | syscall_createProcess((char *)"/system/wm", 0, 0); 39 | while (1) 40 | ; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /userspace/apps/system/usermodecrash_handler/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=umc 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/system/usermodecrash_handler/usermodecrash_handler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "usm.h" 5 | 6 | int main(uint64_t *arg1, uint64_t *arg2) 7 | { 8 | syscall_dbg(0x3F8, (char *)"[UMC] Crash\n"); 9 | TrapFrame *frame = (TrapFrame*)arg1; 10 | // mono 1 - multi 2 11 | if (syscall_getScheduleMode() == 1) 12 | { 13 | syscall_dbg(0x3F8, (char *)"[UMC] Kernel is running under monotasking mode.\n"); 14 | return 0; 15 | } 16 | else 17 | { 18 | syscall_dbg(0x3F8, (char *)"[UMC] Kernel is running under multitasking mode.\n"); 19 | /* Run as service */ 20 | while (1) 21 | ; 22 | } 23 | return 1; 24 | } 25 | -------------------------------------------------------------------------------- /userspace/apps/system/wm/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=wm 4 | OUTPUT_DIR=../../../../resources/initrd/system/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/user/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | make -C brainfuckcompiler build 3 | make -C texteditor build 4 | 5 | clean: 6 | make -C brainfuckcompiler clean 7 | make -C texteditor clean 8 | -------------------------------------------------------------------------------- /userspace/apps/user/brainfuckcompiler/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=bfc 4 | OUTPUT_DIR=../../../../resources/initrd/home/default/Apps/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | C_SOURCES = $(shell find ./ -type f -name '*.c') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(C_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c17 $(C_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/user/texteditor/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=te 4 | OUTPUT_DIR=../../../../resources/initrd/home/default/Apps/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 7 | 8 | C_SOURCES = $(shell find ./ -type f -name '*.c') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../libc/include/*))) 10 | INCLUDE_DIR = ../../../../libc/include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(C_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) --sysroot=../../../../resources/initrd/system -fPIC -std=c17 $(C_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/apps/user/texteditor/texteditor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | // TODO 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /userspace/drivers/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | make -C peripheral/keyboard build 3 | make -C peripheral/mouse build 4 | make -C audio/ac97 build 5 | make -C video/bochs build 6 | make -C network/rtl8139 build 7 | 8 | clean: 9 | make -C peripheral/keyboard clean 10 | make -C peripheral/mouse clean 11 | make -C audio/ac97 clean 12 | make -C video/bochs clean 13 | make -C network/rtl8139 clean 14 | -------------------------------------------------------------------------------- /userspace/drivers/audio/ac97/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=AC97.drv 4 | OUTPUT_DIR=../../../../resources/initrd/system/drivers/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../include/*))) 10 | INCLUDE_DIR = ../../../../include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) -Tlink.ld -nostdlib -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/drivers/audio/ac97/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .driverdata : 4 | { 5 | KEEP(*(.driverdata*)) 6 | } 7 | 8 | .text : 9 | { 10 | *(.text*) 11 | } 12 | 13 | .rodata : 14 | { 15 | *(.rodata*) 16 | } 17 | 18 | .data : 19 | { 20 | *(.data*) 21 | } 22 | 23 | .bss : 24 | { 25 | *(.bss*) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /userspace/drivers/audio/ac97/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | DRIVER_ENTRY 4 | { 5 | return 0; 6 | } 7 | 8 | DRIVER = { 9 | .Name = "AC97 Audio Driver", 10 | .Type = TYPE_AUDIO, 11 | .Bind = {BIND_NULL}}; 12 | -------------------------------------------------------------------------------- /userspace/drivers/network/rtl8139/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=Rtl8139.drv 4 | OUTPUT_DIR=../../../../resources/initrd/system/drivers/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../include/*))) 10 | INCLUDE_DIR = ../../../../include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) -Tlink.ld -nostdlib -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/drivers/network/rtl8139/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .driverdata : 4 | { 5 | KEEP(*(.driverdata*)) 6 | } 7 | 8 | .text : 9 | { 10 | *(.text*) 11 | } 12 | 13 | .rodata : 14 | { 15 | *(.rodata*) 16 | } 17 | 18 | .data : 19 | { 20 | *(.data*) 21 | } 22 | 23 | .bss : 24 | { 25 | *(.bss*) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /userspace/drivers/network/rtl8139/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | DRIVER_ENTRY 4 | { 5 | return 0; 6 | } 7 | 8 | DRIVER = { 9 | .Name = "Realtek-8139 Network Driver", 10 | .Type = TYPE_NETWORK, 11 | .Bind = {BIND_NULL}}; 12 | -------------------------------------------------------------------------------- /userspace/drivers/peripheral/keyboard/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=keyboard.drv 4 | OUTPUT_DIR=../../../../resources/initrd/system/drivers/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../include/*))) 10 | INCLUDE_DIR = ../../../../include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) -Tlink.ld -nostdlib -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/drivers/peripheral/keyboard/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .driverdata : 4 | { 5 | KEEP(*(.driverdata*)) 6 | } 7 | 8 | .text : 9 | { 10 | *(.text*) 11 | } 12 | 13 | .rodata : 14 | { 15 | *(.rodata*) 16 | } 17 | 18 | .data : 19 | { 20 | *(.data*) 21 | } 22 | 23 | .bss : 24 | { 25 | *(.bss*) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /userspace/drivers/peripheral/keyboard/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | DriverKernelMainData *Calls = nullptr; 5 | 6 | InterruptHandler(KeyboardInterrupt) 7 | { 8 | Calls->KFctCall(KCALL_END_OF_INTERRUPT, INT_NUM); 9 | } 10 | 11 | DRIVER_ENTRY 12 | { 13 | Calls = Data; 14 | Data->KFctCall(KCALL_HOOK_INTERRUPT, IRQ1, KeyboardInterrupt); 15 | return DRIVER_SUCCESS; 16 | } 17 | 18 | DRIVER = { 19 | .Name = "PS/2 Keyboard Driver", 20 | .Type = TYPE_KEYBOARD, 21 | .Bind = 22 | { 23 | .Bind = BIND_INTERRUPT, 24 | .Interrupt = 25 | { 26 | .Vector = IRQ1}}}; 27 | -------------------------------------------------------------------------------- /userspace/drivers/peripheral/mouse/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=mouse.drv 4 | OUTPUT_DIR=../../../../resources/initrd/system/drivers/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../include/*))) 10 | INCLUDE_DIR = ../../../../include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) -Tlink.ld -nostdlib -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/drivers/peripheral/mouse/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .driverdata : 4 | { 5 | KEEP(*(.driverdata*)) 6 | } 7 | 8 | .text : 9 | { 10 | *(.text*) 11 | } 12 | 13 | .rodata : 14 | { 15 | *(.rodata*) 16 | } 17 | 18 | .data : 19 | { 20 | *(.data*) 21 | } 22 | 23 | .bss : 24 | { 25 | *(.bss*) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /userspace/drivers/peripheral/mouse/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | DRIVER_ENTRY 4 | { 5 | return 0; 6 | } 7 | 8 | DRIVER = { 9 | .Name = "PS/2 Mouse Driver", 10 | .Type = TYPE_MOUSE, 11 | .Bind = 12 | { 13 | .Bind = BIND_INTERRUPT, 14 | .Interrupt = 15 | { 16 | .Vector = 0x2C}}}; 17 | -------------------------------------------------------------------------------- /userspace/drivers/video/bochs/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=bochs-display.drv 4 | OUTPUT_DIR=../../../../resources/initrd/system/drivers/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../include/*))) 10 | INCLUDE_DIR = ../../../../include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) -Tlink.ld -nostdlib -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/drivers/video/bochs/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .driverdata : 4 | { 5 | KEEP(*(.driverdata*)) 6 | } 7 | 8 | .text : 9 | { 10 | *(.text*) 11 | } 12 | 13 | .rodata : 14 | { 15 | *(.rodata*) 16 | } 17 | 18 | .data : 19 | { 20 | *(.data*) 21 | } 22 | 23 | .bss : 24 | { 25 | *(.bss*) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /userspace/drivers/video/bochs/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | DRIVER_ENTRY 4 | { 5 | return 0; 6 | } 7 | 8 | DRIVER = { 9 | .Name = "Bochs Video Driver", 10 | .Type = TYPE_VIDEO, 11 | .Bind = {BIND_NULL}}; 12 | -------------------------------------------------------------------------------- /userspace/drivers/video/virtio/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../Makefile.conf 2 | 3 | NAME=virtiogpu.drv 4 | OUTPUT_DIR=../../../../resources/initrd/system/drivers/ 5 | 6 | CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ 7 | 8 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 9 | HEADERS = $(sort $(dir $(wildcard ../../../../include/*))) 10 | INCLUDE_DIR = ../../../../include 11 | 12 | build: $(NAME) 13 | 14 | $(NAME): $(CPP_SOURCES) 15 | $(CC) -I$(INCLUDE_DIR) -Tlink.ld -nostdlib -fPIC -std=c++2a $(CPP_SOURCES) -o $(OUTPUT_DIR)$(NAME) 16 | 17 | clean: 18 | rm -f $(OUTPUT_DIR)$(NAME) 19 | -------------------------------------------------------------------------------- /userspace/drivers/video/virtio/link.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .driverdata : 4 | { 5 | KEEP(*(.driverdata*)) 6 | } 7 | 8 | .text : 9 | { 10 | *(.text*) 11 | } 12 | 13 | .rodata : 14 | { 15 | *(.rodata*) 16 | } 17 | 18 | .data : 19 | { 20 | *(.data*) 21 | } 22 | 23 | .bss : 24 | { 25 | *(.bss*) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /userspace/drivers/video/virtio/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | DRIVER_ENTRY 4 | { 5 | return 0; 6 | } 7 | 8 | DRIVER = { 9 | .Name = "VirtIO Video Driver", 10 | .Type = TYPE_VIDEO, 11 | .Bind = {BIND_NULL}}; 12 | -------------------------------------------------------------------------------- /userspace/libs/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | make -C monoton build 3 | make -C scparse build 4 | make -C algo build 5 | make -C cwalk build 6 | make -C cargs build 7 | 8 | clean: 9 | make -C monoton clean 10 | make -C scparse clean 11 | make -C algo clean 12 | make -C cwalk clean 13 | make -C cargs clean 14 | -------------------------------------------------------------------------------- /userspace/libs/algo/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../Makefile.conf 2 | 3 | NAME=algo 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../../resources/initrd/system/lib/ 8 | 9 | CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../../libc/include/*))) 16 | INCLUDE_DIR = ../../../libc/include 17 | 18 | LDFLAGS := 19 | CFLAGS := -I$(INCLUDE_DIR) -fPIC --sysroot=../../../resources/initrd/system/ 20 | 21 | build: $(OBJECT_NAME) 22 | 23 | $(OBJECT_NAME): $(OBJ) 24 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 25 | %.o: %.c $(HEADERS) 26 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 27 | 28 | %.o: %.cpp $(HEADERS) 29 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 30 | 31 | clean: 32 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 33 | -------------------------------------------------------------------------------- /userspace/libs/algo/algo.c: -------------------------------------------------------------------------------- 1 | unsigned int CyclicRedundancyCheck32(unsigned char *Data) 2 | { 3 | static unsigned int Table[256]; 4 | unsigned int Byte, CRC; 5 | 6 | if (Table[1] == 0) 7 | { 8 | unsigned int Mask; 9 | for (Byte = 0; Byte <= 255; Byte++) 10 | { 11 | CRC = Byte; 12 | for (int j = 7; j >= 0; j--) 13 | { 14 | Mask = -(CRC & 1); 15 | CRC = (CRC >> 1) ^ (0xEDB88320 & Mask); 16 | } 17 | Table[Byte] = CRC; 18 | } 19 | } 20 | 21 | int i = 0; 22 | CRC = 0xFFFFFFFF; 23 | while ((Byte = Data[i]) != 0) 24 | { 25 | CRC = (CRC >> 8) ^ Table[(CRC ^ Byte) & 0xFF]; 26 | i = i + 1; 27 | } 28 | return ~CRC; 29 | } 30 | -------------------------------------------------------------------------------- /userspace/libs/algo/algo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | unsigned int CyclicRedundancyCheck32(unsigned char *Data); 4 | -------------------------------------------------------------------------------- /userspace/libs/cargs/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Leonard Iklé 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 | -------------------------------------------------------------------------------- /userspace/libs/cargs/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../Makefile.conf 2 | 3 | NAME=cargs 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../../resources/initrd/system/lib/ 8 | 9 | CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../../libc/include/*))) 16 | INCLUDE_DIR = ../../../libc/include 17 | 18 | LDFLAGS := 19 | CFLAGS := -I$(INCLUDE_DIR) -fPIC --sysroot=../../../resources/initrd/system/ 20 | 21 | build: $(OBJECT_NAME) 22 | 23 | $(OBJECT_NAME): $(OBJ) 24 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 25 | %.o: %.c $(HEADERS) 26 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 27 | 28 | %.o: %.cpp $(HEADERS) 29 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 30 | 31 | clean: 32 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 33 | -------------------------------------------------------------------------------- /userspace/libs/cwalk/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Leonard Iklé 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. -------------------------------------------------------------------------------- /userspace/libs/cwalk/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../Makefile.conf 2 | 3 | NAME=cwalk 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../../resources/initrd/system/lib/ 8 | 9 | CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../../libc/include/*))) 16 | INCLUDE_DIR = ../../../libc/include 17 | 18 | LDFLAGS := 19 | CFLAGS := -I$(INCLUDE_DIR) -fPIC --sysroot=../../../resources/initrd/system/ 20 | 21 | build: $(OBJECT_NAME) 22 | 23 | $(OBJECT_NAME): $(OBJ) 24 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 25 | %.o: %.c $(HEADERS) 26 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 27 | 28 | %.o: %.cpp $(HEADERS) 29 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 30 | 31 | clean: 32 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 33 | -------------------------------------------------------------------------------- /userspace/libs/drawlib/main.cpp: -------------------------------------------------------------------------------- 1 | // void *imgg = (void *)syscall_FileOpen((char *)"/system/wallpapers/fennec.tga"); 2 | // if (imgg == nullptr) 3 | // { 4 | // syscall_dbg(0x3F8, (char *)"[LoadImage] Could not open file.\n"); 5 | // return; 6 | // } 7 | // syscall_dbg(0x3F8, (char *)"[LoadImage] Image opened.\n"); 8 | 9 | // uint64_t sizeeeee = syscall_FileSize(imgg); 10 | 11 | // void *imgdata = malloc(sizeeeee); 12 | // syscall_dbg(0x3F8, (char *)"[LoadImage] IMAGE GOT SIZE.\n"); 13 | // syscall_FileRead(imgg, 0, imgdata, sizeeeee); 14 | // syscall_dbg(0x3F8, (char *)"[LoadImage] Image Readed\n"); 15 | // // unsigned int *image = jpg_parse((uint8_t *)imgdata, sizeeeee); 16 | // unsigned int *image = tga_parse((uint8_t *)imgdata, sizeeeee); 17 | // syscall_dbg(0x3F8, (char *)"[LoadImage] Image Parsed\n"); 18 | // if (image == nullptr) 19 | // syscall_dbg(0x3F8, (char *)"failed to parse image file!\n"); 20 | 21 | // uint32_t x = Xi, y = 0; 22 | // for (size_t i = 0; i < image[0] * image[1]; i++) 23 | // { 24 | // if (x <= width || y <= height) 25 | // ((uint32_t *)address)[x + (y * ppsl)] = image[i]; 26 | // y++; 27 | // if (y == image[1]) 28 | // { 29 | // x++; 30 | // y = 0; 31 | // } 32 | // } 33 | // syscall_FileClose(imgg); 34 | // free(image); -------------------------------------------------------------------------------- /userspace/libs/fenlib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | C_SOURCES = $(shell find ./ -type f -name '*.c') 3 | S_SOURCES = $(shell find ./ -type f -name '*.s') 4 | ASM_SOURCES = $(shell find ./ -type f -name '*.asm') 5 | OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.s=.o} 6 | 7 | # https://wiki.osdev.org/ELF 8 | build: $(OBJ) 9 | 10 | %.o: %.c 11 | $(CC) -std=c17 -c $< -o $@ 12 | 13 | %.o: %.asm 14 | ${NASM} $< -f elf64 -o $@ 15 | 16 | %.bin: %.s 17 | ${NASM} $< -f elf64 -o $@ 18 | 19 | clean: 20 | 21 | -------------------------------------------------------------------------------- /userspace/libs/fenlib/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/userspace/libs/fenlib/main.cpp -------------------------------------------------------------------------------- /userspace/libs/monoton/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../Makefile.conf 2 | 3 | NAME=monoton 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../../resources/initrd/system/lib/ 8 | 9 | CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../../libc/include/*))) 16 | INCLUDE_DIR = ../../../libc/include 17 | 18 | LDFLAGS := 19 | CFLAGS := -I$(INCLUDE_DIR) -fPIC --sysroot=../../../resources/initrd/system/ 20 | 21 | build: $(OBJECT_NAME) 22 | 23 | $(OBJECT_NAME): $(OBJ) 24 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 25 | 26 | %.o: %.c $(HEADERS) 27 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 28 | 29 | %.o: %.cpp $(HEADERS) 30 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 31 | 32 | clean: 33 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 34 | -------------------------------------------------------------------------------- /userspace/libs/proclib/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EnderIce2/FennixProject/60cd8adbe8d565660b54574e516537360a7b3e4a/userspace/libs/proclib/main.cpp -------------------------------------------------------------------------------- /userspace/libs/scparse/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../Makefile.conf 2 | 3 | NAME=scparse 4 | 5 | OBJECT_NAME=lib$(NAME).a 6 | 7 | OUTPUT_DIR=../../../resources/initrd/system/lib/ 8 | 9 | CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc 10 | AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar 11 | 12 | C_SOURCES = $(shell find ./ -type f -name '*.c') 13 | CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') 14 | OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) 15 | HEADERS = $(sort $(dir $(wildcard ../../../libc/include/*))) 16 | INCLUDE_DIR = ../../../libc/include 17 | 18 | LDFLAGS := 19 | CFLAGS := -I$(INCLUDE_DIR) -fPIC --sysroot=../../../resources/initrd/system/ 20 | 21 | build: $(OBJECT_NAME) 22 | 23 | $(OBJECT_NAME): $(OBJ) 24 | $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) 25 | %.o: %.c $(HEADERS) 26 | $(CC) $(CFLAGS) -std=c17 -c $< -o $@ 27 | 28 | %.o: %.cpp $(HEADERS) 29 | $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ 30 | 31 | clean: 32 | rm -f $(OUTPUT_DIR)$(OBJECT_NAME) $(OBJ) 33 | -------------------------------------------------------------------------------- /userspace/libs/scparse/scparse.c: -------------------------------------------------------------------------------- 1 | #include "scparse.h" 2 | 3 | int scparse__shiftkey = 0; 4 | --------------------------------------------------------------------------------