├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json └── settings.json ├── LICENSE ├── README.md ├── apps ├── browser │ └── main.cpp ├── calc │ └── calc.cpp ├── clock │ └── clock.cpp ├── compositor │ ├── compositor.cpp │ ├── compositor.h │ ├── contextmanager.cpp │ ├── contextmanager.h │ ├── cursor.h │ ├── debugger.cpp │ ├── debugger.h │ ├── main.cpp │ └── scancodes.cpp ├── desktop │ ├── desktop.cpp │ └── item.h ├── init │ ├── init.cpp │ └── progress.h ├── linker.ld ├── makefile ├── mines │ └── mines.cpp ├── powermanager │ └── main.cpp ├── sysinfo │ └── sysinfo.cpp └── terminal │ ├── terminal.cpp │ ├── terminalcontrol.cpp │ └── terminalcontrol.h ├── docs ├── CactusOS Initrd Layout.xml ├── CactusOS Kernel Design.xml ├── MemoryLayout.odt ├── UHCI.drawio └── folderlayout.txt ├── grub.cfg ├── grubcore.cfg ├── images ├── Logo.png ├── Screenshot Bootscreen.png ├── Screenshot Debugging.png └── Screenshot Desktop.png ├── initrd └── PCI Class Codes.txt ├── isofiles ├── apps │ └── Readme.txt ├── boot.jpg ├── desktop │ ├── calculator.png │ ├── explorer.png │ ├── items.txt │ ├── mine.png │ ├── power.png │ └── terminal.png ├── fonts │ └── Ubuntu15.cff ├── initrd ├── setup │ ├── boot.img │ ├── core.img │ ├── warning.txt │ └── welcome.txt └── wallpap.jpg ├── kernel ├── include │ ├── common │ │ ├── convert.h │ │ ├── list.h │ │ ├── memoryoperations.h │ │ ├── print.h │ │ ├── random.h │ │ ├── string.h │ │ └── types.h │ ├── core │ │ ├── cpu.h │ │ ├── exceptions.h │ │ ├── fpu.h │ │ ├── gdt.h │ │ ├── idt.h │ │ ├── physicalmemory.h │ │ ├── port.h │ │ ├── power.h │ │ ├── registers.h │ │ ├── tss.h │ │ └── virtualmemory.h │ ├── installer │ │ ├── installer.h │ │ └── textgui.h │ ├── multiboot │ │ └── multiboot.h │ └── system │ │ ├── bootconsole.h │ │ ├── components │ │ ├── apm.h │ │ ├── bochsvbe.h │ │ ├── dma.h │ │ ├── edid.h │ │ ├── graphicsdevice.h │ │ ├── pci.h │ │ ├── pit.h │ │ ├── rtc.h │ │ ├── smbios.h │ │ ├── systemcomponent.h │ │ └── vesa.h │ │ ├── debugger.h │ │ ├── disks │ │ ├── disk.h │ │ ├── diskcontroller.h │ │ ├── diskmanager.h │ │ └── partitionmanager.h │ │ ├── drivers │ │ ├── disk │ │ │ ├── ahci │ │ │ │ ├── ahcicontroller.h │ │ │ │ ├── ahcidefs.h │ │ │ │ └── ahciport.h │ │ │ └── ide.h │ │ ├── driver.h │ │ ├── drivermanager.h │ │ ├── integrated │ │ │ ├── floppy.h │ │ │ ├── ps2-keyboard.h │ │ │ └── ps2-mouse.h │ │ ├── pcidrivers.h │ │ ├── usb │ │ │ ├── controllers │ │ │ │ ├── ehci.h │ │ │ │ ├── ohci.h │ │ │ │ ├── uhci.h │ │ │ │ └── xhci.h │ │ │ ├── mass_storage.h │ │ │ ├── usbcomborecv.h │ │ │ ├── usbdefs.h │ │ │ ├── usbdriver.h │ │ │ ├── usbkeyboard.h │ │ │ └── usbmouse.h │ │ └── video │ │ │ └── vmwaresvga.h │ │ ├── initrd.h │ │ ├── input │ │ ├── keyboard.h │ │ └── keyboardmanager.h │ │ ├── interruptmanager.h │ │ ├── listings │ │ ├── directorylisting.h │ │ ├── listingcontroller.h │ │ └── systeminfo.h │ │ ├── log.h │ │ ├── memory │ │ ├── deviceheap.h │ │ ├── fifostream.h │ │ ├── heap.h │ │ ├── new.h │ │ ├── sharedmem.h │ │ └── stream.h │ │ ├── serialport.h │ │ ├── syscalls │ │ ├── implementations │ │ │ ├── cactusos.h │ │ │ └── linux.h │ │ └── syscalls.h │ │ ├── system.h │ │ ├── tasking │ │ ├── elf.h │ │ ├── ipcmanager.h │ │ ├── lock.h │ │ ├── process.h │ │ ├── scheduler.h │ │ └── thread.h │ │ ├── usb │ │ ├── hidparser.h │ │ ├── usbcontroller.h │ │ ├── usbdevice.h │ │ ├── usbendpoint.h │ │ └── usbmanager.h │ │ ├── vfs │ │ ├── fat.h │ │ ├── iso9660.h │ │ ├── vfsmanager.h │ │ └── virtualfilesystem.h │ │ └── virtual8086 │ │ ├── VM86Args.h │ │ ├── VM86Manager.h │ │ └── VM86Monitor.h ├── linker.ld └── src │ ├── boot │ └── loader.s │ ├── common │ ├── convert.cpp │ ├── memoryoperations.cpp │ ├── print.cpp │ ├── random.cpp │ └── string.cpp │ ├── core │ ├── cpu.cpp │ ├── cpuhelper.asm │ ├── exceptions.cpp │ ├── fpu.cpp │ ├── gdt.cpp │ ├── gdthelper.asm │ ├── idt.cpp │ ├── idthelper.s │ ├── physicalmemory.cpp │ ├── power.cpp │ ├── tss.cpp │ ├── tsshelper.asm │ └── virtualmemory.cpp │ ├── gdb │ ├── gdbimpl.cpp │ └── i386-stub.c │ ├── installer │ ├── installer.cpp │ └── textgui.cpp │ ├── kernel.cpp │ └── system │ ├── bootconsole.cpp │ ├── components │ ├── apm.cpp │ ├── bochsvbe.cpp │ ├── dma.cpp │ ├── edid.cpp │ ├── graphicsdevice.cpp │ ├── pci.cpp │ ├── pit.cpp │ ├── rtc.cpp │ ├── smbios.cpp │ ├── systemcomponents.cpp │ └── vesa.cpp │ ├── debugger.cpp │ ├── disks │ ├── disk.cpp │ ├── diskcontroller.cpp │ ├── diskmanager.cpp │ └── partitionmanager.cpp │ ├── drivers │ ├── disk │ │ ├── ahci │ │ │ ├── ahcicontroller.cpp │ │ │ └── ahciport.cpp │ │ └── ide.cpp │ ├── driver.cpp │ ├── drivermanager.cpp │ ├── integrated │ │ ├── floppy.cpp │ │ ├── ps2-keyboard.cpp │ │ └── ps2-mouse.cpp │ ├── pcidrivers.cpp │ ├── usb │ │ ├── controllers │ │ │ ├── ehci.cpp │ │ │ ├── ohci.cpp │ │ │ ├── uhci.cpp │ │ │ └── xhci.cpp │ │ ├── mass_storage.cpp │ │ ├── usbcomborecv.cpp │ │ ├── usbdriver.cpp │ │ ├── usbkeyboard.cpp │ │ └── usbmouse.cpp │ └── video │ │ └── vmwaresvga.cpp │ ├── initrd.cpp │ ├── input │ ├── keyboard.cpp │ └── keyboardmanager.cpp │ ├── interruptmanager.cpp │ ├── listings │ ├── directorylisting.cpp │ ├── listingcontroller.cpp │ └── systeminfo.cpp │ ├── log.cpp │ ├── memory │ ├── deviceheap.cpp │ ├── fifostream.cpp │ ├── heap.cpp │ ├── sharedmem.cpp │ └── stream.cpp │ ├── serialport.cpp │ ├── syscalls │ ├── implementations │ │ ├── cactusos.cpp │ │ └── linux.cpp │ └── syscalls.cpp │ ├── system.cpp │ ├── tasking │ ├── atomic.s │ ├── ipcmanager.cpp │ ├── lock.cpp │ ├── process.cpp │ ├── scheduler.cpp │ ├── thread.cpp │ └── userspace.asm │ ├── usb │ ├── hidparser.cpp │ ├── usbcontroller.cpp │ ├── usbdevice.cpp │ ├── usbendpoint.cpp │ └── usbmanager.cpp │ ├── vfs │ ├── fat.cpp │ ├── iso9660.cpp │ ├── vfsmanager.cpp │ └── virtualfilesystem.cpp │ └── virtual8086 │ ├── VM8086Code.asm │ ├── VM8086Helper.asm │ ├── VM8086Manager.cpp │ └── VM8086Monitor.cpp ├── lib ├── include │ ├── api.h │ ├── bitreader.h │ ├── convert.h │ ├── datetime.h │ ├── gui │ │ ├── canvas.h │ │ ├── colors.h │ │ ├── context.h │ │ ├── contextheap.h │ │ ├── contextinfo.h │ │ ├── directgui.h │ │ ├── events.h │ │ ├── fonts │ │ │ ├── font.h │ │ │ └── fontparser.h │ │ ├── gui.h │ │ ├── property.h │ │ ├── rect.h │ │ └── widgets │ │ │ ├── button.h │ │ │ ├── control.h │ │ │ ├── label.h │ │ │ ├── listview.h │ │ │ ├── scrollbar.h │ │ │ ├── scrollbox.h │ │ │ ├── slider.h │ │ │ └── window.h │ ├── heap.h │ ├── imaging │ │ ├── bmpformat.h │ │ ├── image.h │ │ ├── jpeg_decoder.h │ │ └── pngformat.h │ ├── ipc.h │ ├── list.h │ ├── listing.h │ ├── log.h │ ├── math.h │ ├── new.h │ ├── proc.h │ ├── random.h │ ├── shared.h │ ├── string.h │ ├── syscall.h │ ├── systeminfo.h │ ├── time.h │ ├── types.h │ ├── vector.h │ └── vfs.h ├── makefile └── src │ ├── api.cpp │ ├── convert.cpp │ ├── crt │ └── crt0.asm │ ├── datetime.cpp │ ├── gui │ ├── canvas.cpp │ ├── colors.cpp │ ├── context.cpp │ ├── contextheap.cpp │ ├── directgui.cpp │ ├── fonts │ │ ├── font.cpp │ │ └── fontparser.cpp │ ├── gui.cpp │ ├── property.cpp │ ├── rect.cpp │ └── widgets │ │ ├── button.cpp │ │ ├── control.cpp │ │ ├── label.cpp │ │ ├── scrollbar.cpp │ │ ├── slider.cpp │ │ └── window.cpp │ ├── heap.cpp │ ├── imaging │ ├── bmpformat.cpp │ ├── image.cpp │ └── pngformat.cpp │ ├── ipc.cpp │ ├── log.cpp │ ├── main.cpp │ ├── math.cpp │ ├── proc.cpp │ ├── random.cpp │ ├── string.cpp │ ├── syscall.cpp │ ├── systeminfo.cpp │ ├── time.cpp │ └── vfs.cpp ├── makefile ├── makefile.config ├── qemu-usb-config.cfg ├── rungdb └── tools ├── advancedDebugger ├── main.py ├── mainGUI.ui └── mainWindow.py ├── fontGenerator └── fontgen.py ├── initrdGenerator └── main.cpp └── serialDebugger └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Custom 35 | *.pcap 36 | *.bin 37 | *.iso 38 | *.ipch 39 | *.log 40 | 41 | virtualbox_log.txt 42 | tools/fontGenerator/font.ttf 43 | *.img 44 | *.sym 45 | *.pyc -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "${workspaceFolder}/kernel/include", 8 | "${workspaceFolder}/lib/include" 9 | ], 10 | "defines": [ 11 | "CACTUSOSKERNEL" 12 | ], 13 | "compilerPath": "/usr/bin/gcc", 14 | "compilerArgs": [ 15 | "-m32", 16 | "-Wall", 17 | "-Werror", 18 | "-Wextra" 19 | ], 20 | "intelliSenseMode": "${default}" 21 | } 22 | ], 23 | "version": 4 24 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "array": "cpp", 4 | "initializer_list": "cpp", 5 | "string_view": "cpp", 6 | "utility": "cpp", 7 | "thread": "cpp", 8 | "chrono": "cpp", 9 | "typeinfo": "cpp", 10 | "ratio": "cpp", 11 | "type_traits": "cpp", 12 | "*.tcc": "cpp", 13 | "cctype": "cpp", 14 | "clocale": "cpp", 15 | "cmath": "cpp", 16 | "cstdarg": "cpp", 17 | "cstddef": "cpp", 18 | "cstdint": "cpp", 19 | "cstdio": "cpp", 20 | "cstdlib": "cpp", 21 | "cwchar": "cpp", 22 | "cwctype": "cpp", 23 | "unordered_map": "cpp", 24 | "vector": "cpp", 25 | "exception": "cpp", 26 | "fstream": "cpp", 27 | "functional": "cpp", 28 | "iosfwd": "cpp", 29 | "iostream": "cpp", 30 | "istream": "cpp", 31 | "limits": "cpp", 32 | "new": "cpp", 33 | "optional": "cpp", 34 | "ostream": "cpp", 35 | "sstream": "cpp", 36 | "stdexcept": "cpp", 37 | "streambuf": "cpp", 38 | "system_error": "cpp", 39 | "tuple": "cpp", 40 | "cstring": "cpp", 41 | "random": "cpp", 42 | "atomic": "cpp", 43 | "deque": "cpp", 44 | "string": "cpp", 45 | "algorithm": "cpp", 46 | "memory": "cpp", 47 | "memory_resource": "cpp", 48 | "hash_map": "cpp", 49 | "list": "cpp", 50 | "iterator": "cpp", 51 | "bit": "cpp", 52 | "ctime": "cpp", 53 | "numeric": "cpp", 54 | "cinttypes": "cpp" 55 | }, 56 | "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: WebKit, PointerAlignment: Left}", 57 | "python.pythonPath": "/usr/bin/python3", 58 | "cSpell.words": [ 59 | "LIBCACTUSOS" 60 | ] 61 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Remco123 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 | -------------------------------------------------------------------------------- /apps/browser/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace LIBCactusOS; 14 | 15 | Window* mainWindow = 0; 16 | 17 | void ValueChanged(void* s, int v) 18 | { 19 | mainWindow->backColor = v * 1000; 20 | } 21 | 22 | int main(int argc, char** argv) 23 | { 24 | GUI::SetDefaultFont(); 25 | 26 | mainWindow = new Window(600, 600, 300, 300); 27 | mainWindow->titleString = "CactusOS File Browser"; 28 | 29 | ScrollBar* scroll = new ScrollBar(Vertical); 30 | scroll->x = 100; 31 | scroll->y = 200; 32 | scroll->value.onChanged += ValueChanged; 33 | mainWindow->AddChild(scroll); 34 | 35 | while (GUI::HasItems()) { 36 | GUI::DrawGUI(); 37 | GUI::ProcessEvents(); 38 | //scroll->value += 1; 39 | if(scroll->value >= scroll->maxValue) { 40 | scroll->value = 0; 41 | scroll->maxValue += 20; 42 | } 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /apps/compositor/contextmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "contextmanager.h" 2 | 3 | using namespace LIBCactusOS; 4 | 5 | ContextManager::ContextManager() 6 | : contextList() 7 | { } 8 | 9 | ContextManager::~ContextManager() 10 | { } 11 | 12 | ContextInfo* ContextManager::FindTargetContext(int x, int y) 13 | { 14 | // Loop through all known contexts starting at the one on the front 15 | for(ContextInfo* c : contextList) 16 | { 17 | if(x >= c->x && x <= c->x + (int)c->width) // Check if the coordinate x,y fits in the border 18 | if(y >= c->y && y <= c->y + (int)c->height) // of the context. If so return as result. 19 | return c; 20 | } 21 | 22 | return 0; 23 | } 24 | List ContextManager::FindTargetContexts(Rectangle area) 25 | { 26 | List result; 27 | for(ContextInfo* c : contextList) 28 | { 29 | Rectangle item = Rectangle(c->width, c->height, c->x, c->y); 30 | if(area.Intersect(item, 0)) 31 | result.push_back(c); 32 | } 33 | return result; 34 | } 35 | 36 | void ContextManager::MoveToFront(ContextInfo* info) 37 | { 38 | contextList.Remove(info); 39 | contextList.push_front(info); 40 | } -------------------------------------------------------------------------------- /apps/compositor/contextmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONTEXTMANAGER_H 2 | #define __CONTEXTMANAGER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | // Class that manages a list of contexts 9 | class ContextManager 10 | { 11 | private: 12 | 13 | public: 14 | // List of al contexts present on the desktop 15 | // Organized from top to bottom, so top context is at position 0 16 | List contextList; 17 | 18 | // Initialize a new instance of the ContextManager 19 | ContextManager(); 20 | 21 | // Destructor 22 | ~ContextManager(); 23 | 24 | 25 | // Find the corresponding context at the position given by x and y 26 | // The order is from top to bottom! 27 | ContextInfo* FindTargetContext(int x, int y); 28 | 29 | // Find all contexts that exist in the given area 30 | List FindTargetContexts(Rectangle area); 31 | 32 | // Move a context to the front of the desktop 33 | void MoveToFront(ContextInfo* info); 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /apps/compositor/cursor.h: -------------------------------------------------------------------------------- 1 | #ifndef _CURSOR_H 2 | #define _CURSOR_H 3 | 4 | #include 5 | 6 | #define ALPHA 0 7 | #define BLACK 1 8 | #define WHITE 2 9 | 10 | #define CURSOR_W 12 11 | #define CURSOR_H 19 12 | 13 | LIBCactusOS::uint8_t cursorBitmap[CURSOR_W * CURSOR_H] = 14 | { 15 | BLACK,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA, 16 | BLACK,BLACK,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA, 17 | BLACK,WHITE,BLACK,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA, 18 | BLACK,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA, 19 | BLACK,WHITE,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA, 20 | BLACK,WHITE,WHITE,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA, 21 | BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA, 22 | BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA,ALPHA, 23 | BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA, 24 | BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK,ALPHA,ALPHA, 25 | BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK,ALPHA, 26 | BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK, 27 | BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,BLACK,BLACK,BLACK,BLACK,BLACK, 28 | BLACK,WHITE,WHITE,WHITE,BLACK,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA,ALPHA, 29 | BLACK,WHITE,WHITE,BLACK,ALPHA,BLACK,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA, 30 | BLACK,WHITE,BLACK,ALPHA,ALPHA,BLACK,WHITE,WHITE,BLACK,ALPHA,ALPHA,ALPHA, 31 | BLACK,BLACK,ALPHA,ALPHA,ALPHA,ALPHA,BLACK,WHITE,WHITE,BLACK,ALPHA,ALPHA, 32 | ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,BLACK,WHITE,WHITE,BLACK,ALPHA,ALPHA, 33 | ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,ALPHA,BLACK,BLACK,ALPHA,ALPHA,ALPHA 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /apps/compositor/debugger.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEBUGGER_H 2 | #define __DEBUGGER_H 3 | 4 | #include "compositor.h" 5 | 6 | class Compositor; 7 | 8 | // Class used to display usefull debugging information when testing the compositor 9 | class CompositorDebugger 10 | { 11 | private: 12 | // To which compositor is this debugger atached? 13 | Compositor* target = 0; 14 | public: 15 | // Is the debugger enabled? 16 | bool enabled = false; 17 | 18 | // Create a new instance of a CompositorDebugger 19 | CompositorDebugger(Compositor* target); 20 | 21 | 22 | // Handle the debugging of one specific context 23 | // Called for every context every frame 24 | void ProcessContext(ContextInfo* ctx); 25 | 26 | // Handles any additional debugging for each frame 27 | void ProcessGeneral(); 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /apps/compositor/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "compositor.h" 8 | 9 | using namespace LIBCactusOS; 10 | 11 | int main(int argc, char** argv) 12 | { 13 | Compositor* mainCompositor = new Compositor(); 14 | while(1) 15 | { 16 | // Update cursor position with the value stored in SysInfo 17 | mainCompositor->curMouseX = Process::systemInfo->MouseX; 18 | mainCompositor->curMouseY = Process::systemInfo->MouseY; 19 | mainCompositor->curMouseZ = Process::systemInfo->MouseZ; 20 | 21 | /////////////////////////// 22 | // Process GUI Events 23 | /////////////////////////// 24 | mainCompositor->ProcessEvents(); 25 | 26 | /////////////////////////// 27 | // Process GUI Requests from clients 28 | /////////////////////////// 29 | mainCompositor->ProcessRequests(); 30 | 31 | /////////////////////////// 32 | // Draw a new version of the desktop 33 | /////////////////////////// 34 | mainCompositor->DrawFrame(); 35 | 36 | // Update cursor variables for next run 37 | mainCompositor->prevMouseX = mainCompositor->curMouseX; 38 | mainCompositor->prevMouseY = mainCompositor->curMouseY; 39 | mainCompositor->prevMouseZ = mainCompositor->curMouseZ; 40 | 41 | // Switch processes after drawing desktop 42 | // It is useless to draw it like 30 times in a couple milliseconds. 43 | Process::Yield(); 44 | } 45 | 46 | delete mainCompositor; 47 | return 0; 48 | } -------------------------------------------------------------------------------- /apps/desktop/item.h: -------------------------------------------------------------------------------- 1 | #ifndef ITEM_H 2 | #define ITEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace LIBCactusOS; 10 | using namespace LIBCactusOS::Imaging; 11 | 12 | class DesktopItem : Rectangle 13 | { 14 | public: 15 | Context* context; 16 | char* label; 17 | bool drawLabel; 18 | char* filename; 19 | uint8_t* iconBuffer; 20 | DesktopItem(int x, int y, int width, int height); 21 | 22 | void DrawToContext(); 23 | }; 24 | 25 | DesktopItem::DesktopItem(int x, int y, int width, int height) 26 | : Rectangle(width, height, x, y) { 27 | this->context = GUI::RequestContext(width, height, x, y); 28 | this->context->canvas->Clear(); 29 | this->context->sharedContextInfo->background = true; 30 | this->context->sharedContextInfo->supportsTransparency = true; 31 | this->context->sharedContextInfo->supportsDirtyRects = true; 32 | } 33 | 34 | void DesktopItem::DrawToContext() 35 | { 36 | if(this->iconBuffer) 37 | { 38 | Image* img = PNGDecoder::ConvertRAW(this->iconBuffer); 39 | if(img) { 40 | uint32_t* src = img->GetBufferPtr(); 41 | for(int x = 0; x < img->GetWidth(); x++) 42 | for(int y = 0; y < img->GetHeight(); y++) { 43 | uint32_t argb = src[y * img->GetWidth() + x]; 44 | this->context->canvas->SetPixel(x, y, argb); 45 | } 46 | } 47 | else 48 | this->context->canvas->Clear(Colors::Black); 49 | } 50 | if(this->drawLabel) { 51 | this->context->canvas->DrawRect(0xFF000000, 0, height-20, width-1, 20-1); 52 | this->context->canvas->DrawString(GUI::defaultFont, this->label, 5, height-17, 0xFFFFFFFF); 53 | } 54 | this->context->sharedContextInfo->AddDirtyArea(0, 0, width, height); 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /apps/init/init.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "progress.h" 16 | 17 | using namespace LIBCactusOS; 18 | using namespace LIBCactusOS::Imaging; 19 | 20 | char* path = "B:\\boot.jpg"; 21 | 22 | int main(int argc, char** argv) 23 | { 24 | Log(Info, "Init process started!"); 25 | 26 | if (DirectGUI::RequestFramebuffer() != SYSCALL_RET_SUCCES) 27 | return -1; 28 | 29 | DirectGUI::Clear(0xFFFFFFFF); 30 | 31 | int x_p = GUI::Width/2 - 100; 32 | int y_p = GUI::Width/2 - 200; 33 | 34 | ProgressBar* bar = new ProgressBar(x_p, y_p + 250, 200, 10); 35 | bar->SetValue(0); 36 | 37 | Log(Info, "Loading Boot Logo"); 38 | Image* logo = Image::CreateFromFile(path); 39 | if(logo) 40 | logo->DrawTo(DirectGUI::GetCanvas(), GUI::Width / 2 - logo->GetWidth()/2, GUI::Height / 2 - logo->GetHeight()/2); 41 | 42 | bar->SetValue(70); 43 | 44 | Print("Launched Compositor pid: %d\n", Process::Run("B:\\apps\\compositor.bin")); 45 | 46 | // Prevent that one of the other launch processes gets the PID of 3 47 | // There can be (a very small) chance that the desktop will get launched before the compositor if there is a weird task switch 48 | while (Process::Active(GUI::compositorPID) == false) 49 | Time::Sleep(100); 50 | 51 | Print("Launched Desktop pid: %d\n", Process::Run("B:\\apps\\desktop.bin")); 52 | Print("Launched Clock pid: %d\n", Process::Run("B:\\apps\\clock.bin")); 53 | //Print("Launched Sysinfo pid: %d\n", Process::Run("B:\\apps\\powermanager.bin")); 54 | 55 | bar->SetValue(100); 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /apps/init/progress.h: -------------------------------------------------------------------------------- 1 | #ifndef PROGRESS_H 2 | #define PROGRESS_H 3 | 4 | #include 5 | #include 6 | 7 | using namespace LIBCactusOS; 8 | 9 | class ProgressBar 10 | { 11 | private: 12 | int x = 0; 13 | int y = 0; 14 | int w = 0; 15 | int h = 0; 16 | 17 | uint32_t background = 0xFFFFFFFF; 18 | uint32_t foreground = 0xFF00FF00; 19 | uint32_t borderColor = 0xFF000000; 20 | public: 21 | ProgressBar(int x_p, int y_p, int width, int height); 22 | 23 | void SetValue(int v); 24 | }; 25 | 26 | ProgressBar::ProgressBar(int x_p, int y_p, int width, int height) 27 | { 28 | this->x = x_p; 29 | this->y = y_p; 30 | this->w = width; 31 | this->h = height; 32 | } 33 | 34 | void ProgressBar::SetValue(int v) 35 | { 36 | DirectGUI::DrawFillRect(background, x, y, w + 1, h); 37 | DirectGUI::DrawRect(borderColor, x, y, w, h); 38 | if(v == 0) 39 | return; 40 | 41 | double fraction = (v/100.0); 42 | DirectGUI::DrawFillRect(foreground, x + 1, y + 1, (fraction * (double)w), h - 1); 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /apps/linker.ld: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | SECTIONS 3 | { 4 | . = 8M; 5 | .text BLOCK(4K) : ALIGN(4K) 6 | { 7 | *(.text) 8 | } 9 | .rodata BLOCK(4K) : ALIGN(4K) 10 | { 11 | start_ctors = .; 12 | *(SORT(.ctors*)) /* Note the "SORT" */ 13 | end_ctors = .; 14 | 15 | start_dtors = .; 16 | *(SORT(.dtors*)) 17 | end_dtors = .; 18 | 19 | *(.rodata) 20 | } 21 | .data BLOCK(4K) : ALIGN(4K) 22 | { 23 | *(.data) 24 | } 25 | .bss BLOCK(4K) : ALIGN(4K) 26 | { 27 | *(COMMON) 28 | *(.bss) 29 | *(.bootstrap_stack) 30 | } 31 | } -------------------------------------------------------------------------------- /apps/makefile: -------------------------------------------------------------------------------- 1 | CONFIG = ../makefile.config 2 | include ${CONFIG} 3 | 4 | LIBINCLUDE := ../lib/include 5 | LIBDIR := ../lib 6 | LIBFILE := ../lib/libcactusos.a 7 | DEBUG := -g 8 | 9 | G++PARAMS := -m32 $(DEBUG) -I $(LIBINCLUDE) $(OPTIMIZE_FLAGS) -Wall -fno-omit-frame-pointer -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-exceptions -fno-rtti -fno-leading-underscore -Wno-write-strings -fpermissive -Wno-unknown-pragmas 10 | GCCPARAMS := -m32 $(DEBUG) -I $(LIBINCLUDE) $(OPTIMIZE_FLAGS) -Wall -fno-omit-frame-pointer -nostdlib -fno-builtin -fleading-underscore -Wno-unknown-pragmas 11 | LDPARAMS := -m elf_i386 12 | 13 | APPS := $(shell find * -type d) 14 | APPOUT := ../isofiles/apps 15 | 16 | SRCFILES := $(shell find $(APPS) -type f \( -name \*.cpp -o -name \*.s -o -name \*.asm -o -name \*.c \)) #Find all the files that end with .cpp/.s/.asm/.c 17 | OBJFILES := $(patsubst %.cpp,%.o,$(patsubst %.s,%.o,$(patsubst %.asm,%.o,$(patsubst %.c,%.o,$(SRCFILES))))) #Replace the .cpp/.s/.asm/.c extension with .o 18 | 19 | .PHONY: all clean 20 | 21 | all: linker.ld $(LIBFILE) $(OBJFILES) 22 | for app in $(APPS) ; do \ 23 | echo building $$app.bin to $(APPOUT)/$$app.bin; \ 24 | i686-elf-ld $(LDPARAMS) -T $< -o $(APPOUT)/$$app.bin $$app/*.o -L$(LIBDIR) --library=cactusos; \ 25 | nm -a $(APPOUT)/$$app.bin | sort -d > $(APPOUT)/$$app.sym; \ 26 | done 27 | 28 | clean: 29 | rm -rf $(OBJFILES) $(LIBFILE) 30 | 31 | # Build libcactusos.a with makefile in the LIBDIR 32 | $(LIBFILE): 33 | cd $(LIBDIR) && $(MAKE) 34 | 35 | %.o: %.cpp 36 | mkdir -p $(@D) 37 | i686-elf-g++ $(G++PARAMS) -c -o $@ $< 38 | 39 | %.o: %.c 40 | mkdir -p $(@D) 41 | i686-elf-gcc $(GCCPARAMS) -c -o $@ $< 42 | 43 | %.o: %.asm 44 | mkdir -p $(@D) 45 | nasm -f elf32 -O0 $< -o $@ 46 | 47 | %.o: %.s 48 | mkdir -p $(@D) 49 | i686-elf-as --32 -o $@ $< -------------------------------------------------------------------------------- /apps/terminal/terminalcontrol.h: -------------------------------------------------------------------------------- 1 | #ifndef TERMINAL_CONTROL_H 2 | #define TERMINAL_CONTROL_H 3 | 4 | #include 5 | 6 | #define TERM_WIDTH 74 7 | #define TERM_HEIGH 26 8 | 9 | class TerminalControl : public Control 10 | { 11 | private: 12 | char* textBuffer = 0; 13 | List inputKeys; 14 | 15 | int x,y; 16 | bool cursor = false; 17 | public: 18 | uint32_t textColor = 0xFF000000; 19 | 20 | TerminalControl(int w, int h); 21 | ~TerminalControl(); 22 | 23 | // Read a new command from this command prompt. 24 | char* ReadCommand(char* prompt = 0); 25 | void Write(char c); 26 | void Write(char* str); 27 | void ScrollLine(); 28 | void Clear(); 29 | void ToggleCursor(); 30 | 31 | void DrawTo(Canvas* context, int x_abs, int y_abs) override; 32 | 33 | /*///////// 34 | // Events called by parent or context 35 | *////////// 36 | friend class Window; 37 | friend class Context; 38 | protected: 39 | // Called on keypress 40 | void OnKeyDown(uint8_t key, KEYPACKET_FLAGS modifiers) override; 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /docs/CactusOS Initrd Layout.xml: -------------------------------------------------------------------------------- 1 | 7ZpRb6M4EIB/TR6vwgYS8ljIZntSV7t3WekeKxcMWAXMgbNJ++tvbEwIMbTZvSaptm2jCo9tbM839sw4ndhBvv1ckTL9wiOaTbAVbSf2YoKxN5vDXyl4bASupwVJxaJGhDrBij1RLbS0dM0iWvcaCs4zwcq+MORFQUPRk5Gq4pt+s5hn/VFLklBDsApJZkr/YZFI9bLwrJPfUJakol2e3VTkpG2rF1KnJOKbPZH9aWIHFeeiecq3Ac2k6lq1NP2WI7W7eVW0EMd0WFHP/vz9693N8mlR3y2s9K9r9Id+yw+SrfV6lwxWjq0bSiJa6ZmLx1Yb9YblGSmg5Me8ECtdY0E5TFkW3ZJHvpbTqQUJH9qSn/KKPUF7kkEVAgFUV0LDxlP5NpZlAc94pcaxqSV/ez1X8o16rIrW0Pdbu3Z0IPpCtr2Gt6QW7Sx5lpGyZvdq3rJjTqqEFT4Xgue6UbvKZX9SsfqBepKxpABZCGOBkrQumtUgB8paq7QSdDuKC+2MAPYO5TkV1SM00R0cbTZ62yBblzedEaKplqV7BogsRxu/Nvxk9+rOOOBB28dP2Ao2bCVMCZiIVZCcTlwfZuguDIsBDQgFvOIPtFVmwRsT2tOvFtUlCVmR3NJYrsfpJH/rJUoRB83GmdpMKYsiWkjSXBBB7nfmWHJWCKUC14cPaCqwrlw1wwDKqCvDRzavRMALmCZhChAFm9lQaTc9uvhYuuPbzUSuGcNGOApx2+7VCdtjhEt5mIHSrA/E/w+xiy+M2DEQr0EZNr4TkqnUwAfdX6Y78y5M1zXofk9pe0Jji8cyelKSWLn5QEVEcofTLclLqftrKGQ84VdlkYzZQiryzpEfZxaty8yUXfhS9wyCrGstzsEK5CD+JmWCrsBi5IgbiCiVZayLiEbaLl7Bt+6Cy9a5unMDHPaGwFknAjcdARevVd+GVnMMj0GDcSGm2vDqAZ7eHUHPNQja86HwyD0RwZlBUJ04etNFcLTJBUI8KlcI48cycpRzG4yzf1NMGCFzo6FzbjTPwPRnwUQVyVOvyVbgBYXM32jO9XgjCdAenOdyn6NzlV5O1M99dAszGUIm8VfAdpB74KHNNXg8OqfCNjewvZyg9jbPgWp/PQLwnjf4gSwNn1VTyIzwlPfXPmL671peOPi+vHfA1q30E/d52VWc4CjapcmnPozGTWcU2MEBNZRlWwP83JPhM0M45fUP8PWc/QfLQZY7cJeDaYZ1KsVSMD08d1zbe+eMZhdnZBmM9BXoQsVsb8u/IOfyDsa8M259sYXfmr7w9PL6MjODIYcsjQ5fCdj7v+/xjZ4POw/OhiFTP+/RYCYLI774Xnng5QdD43xHF4dopg6dD546M3v+3hF5F0eEx1wwPocbfiEXxn11DSXDZ/Yo2AxZAhIKXn9dqdsLfZ+hbyDe4tXS/nfHqH9Bj72T3GEMOBPHHaA2/XloUOy+xVd1e/8JYX/6Dw== -------------------------------------------------------------------------------- /docs/MemoryLayout.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/docs/MemoryLayout.odt -------------------------------------------------------------------------------- /docs/folderlayout.txt: -------------------------------------------------------------------------------- 1 | root dir: 2 | - .vscode -> project files for the Visual Studio Code IDE 3 | - isofiles -> files that will be included to the CactusOS.iso file, this will eventually contain files required for the setup (if we decide to go that way) 4 | - kernel -> the source code for the kernel 5 | - include -> kernel header files 6 | - src -> kernel source files 7 | - linker.ld -> the linker script used to compile the kernel 8 | - tools -> usefull tools for developing the os, so far only a serial debug application is added 9 | - .gitignore -> used by git to ignore files, in our case we ignore the compiled object files 10 | - grub.cfg -> the grub bootloader config file, this is also added to the iso 11 | - makefile -> this projects makefile 12 | - README.md -> contains a small summary of this repository for github -------------------------------------------------------------------------------- /grub.cfg: -------------------------------------------------------------------------------- 1 | set timeout=10 2 | set default=1 3 | 4 | menuentry "CactusOS" { 5 | multiboot /boot/CactusOS.bin 6 | 7 | echo "Loading initrd" 8 | module /initrd 9 | } 10 | 11 | menuentry "CactusOS with serial logging (COM1)" { 12 | multiboot /boot/CactusOS.bin serial 13 | 14 | echo "Loading initrd" 15 | module /initrd 16 | } 17 | 18 | menuentry "CactusOS with gdb stub (COM1)" { 19 | multiboot /boot/CactusOS.bin gdb 20 | 21 | echo "Loading initrd" 22 | module /initrd 23 | } -------------------------------------------------------------------------------- /grubcore.cfg: -------------------------------------------------------------------------------- 1 | set root='hd0,msdos1' 2 | configfile /boot/grub/grub.cfg -------------------------------------------------------------------------------- /images/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/images/Logo.png -------------------------------------------------------------------------------- /images/Screenshot Bootscreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/images/Screenshot Bootscreen.png -------------------------------------------------------------------------------- /images/Screenshot Debugging.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/images/Screenshot Debugging.png -------------------------------------------------------------------------------- /images/Screenshot Desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/images/Screenshot Desktop.png -------------------------------------------------------------------------------- /isofiles/apps/Readme.txt: -------------------------------------------------------------------------------- 1 | This will contain the apps that can be run with CactusOS, the apps will only be present here when compiled. -------------------------------------------------------------------------------- /isofiles/boot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/boot.jpg -------------------------------------------------------------------------------- /isofiles/desktop/calculator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/desktop/calculator.png -------------------------------------------------------------------------------- /isofiles/desktop/explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/desktop/explorer.png -------------------------------------------------------------------------------- /isofiles/desktop/items.txt: -------------------------------------------------------------------------------- 1 | ////////////////// 2 | This file contains the items that are present on the desktop 3 | This file is parsed by the desktop application on startup 4 | ////////////////// 5 | 6 | "Calculator" file="B:\apps\calc.bin" icon="B:\desktop\calculator.png" 7 | "Terminal" file="B:\apps\terminal.bin" icon="B:\desktop\terminal.png" 8 | "Power Manager" file="B:\apps\powermanager.bin" icon="B:\desktop\power.png" 9 | "Mines" file="B:\apps\mines.bin" icon="B:\desktop\mine.png" 10 | "Browser" file="B:\apps\browser.bin" icon="B:\desktop\explorer.png" 11 | -------------------------------------------------------------------------------- /isofiles/desktop/mine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/desktop/mine.png -------------------------------------------------------------------------------- /isofiles/desktop/power.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/desktop/power.png -------------------------------------------------------------------------------- /isofiles/desktop/terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/desktop/terminal.png -------------------------------------------------------------------------------- /isofiles/fonts/Ubuntu15.cff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/fonts/Ubuntu15.cff -------------------------------------------------------------------------------- /isofiles/initrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/initrd -------------------------------------------------------------------------------- /isofiles/setup/boot.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/setup/boot.img -------------------------------------------------------------------------------- /isofiles/setup/core.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/setup/core.img -------------------------------------------------------------------------------- /isofiles/setup/warning.txt: -------------------------------------------------------------------------------- 1 | WARNING!!!!!! 2 | 3 | This setup could set your pc into a unusable state, 4 | use this setup at your own risk! 5 | In order to prevent damaging your pc, read the instructions carefully. 6 | I am not responsible for any damage. 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Press Enter to continue 24 | -------------------------------------------------------------------------------- /isofiles/setup/welcome.txt: -------------------------------------------------------------------------------- 1 | Welcome to the setup program of CactusOS. 2 | With this setup you can install the OS on your hard-drive. 3 | 4 | CactusOS is a open-source operating system meant for private use. 5 | It does not have many features yet but it is still in active development. 6 | The current features include: 7 | - Higher Half Kernel 8 | - Virtual 8086 Mode 9 | - VESA VBE + EDID Parser via bios instructions 10 | - Support for IDE Drives (ATA/ATAPI) 11 | - Very Basic USB support 12 | - Only USB Storage Devices at the moment 13 | - Support for ISO9660 and FAT Filesystems 14 | 15 | There are also some basic applications installed by default which include 16 | - File Manager 17 | - Terminal 18 | - Mines Game 19 | - Clock Widget 20 | - Power manager (For shutting down and restarting) 21 | 22 | For more info visit: https://github.com/Remco123/CactusOS 23 | Press Enter to continue 24 | 25 | -------------------------------------------------------------------------------- /isofiles/wallpap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Remco123/CactusOS/95825bbbd54ca71ea40dcdda23f0ba6604d5c4a8/isofiles/wallpap.jpg -------------------------------------------------------------------------------- /kernel/include/common/convert.h: -------------------------------------------------------------------------------- 1 | #ifndef CACTUSOS__COMMON__CONVERT_H 2 | #define CACTUSOS__COMMON__CONVERT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace common 10 | { 11 | class Convert 12 | { 13 | public: 14 | static char* IntToString(int i); 15 | static char* IntToString32(uint32_t i); 16 | 17 | static char* IntToHexString(common::uint8_t w); 18 | static char* IntToHexString(common::uint16_t w); 19 | static char* IntToHexString(common::uint32_t w); 20 | 21 | static int StringToInt(char* string); 22 | static uint32_t HexToInt(char* string); 23 | }; 24 | } 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /kernel/include/common/memoryoperations.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__COMMON__MEMORYOPERATIONS_H 2 | #define __CACTUSOS__COMMON__MEMORYOPERATIONS_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace common 9 | { 10 | #define phys2virt(x) ((x) + 3_GB) 11 | #define virt2phys(x) ((x) - 3_GB) 12 | 13 | class MemoryOperations 14 | { 15 | public: 16 | static void* memmove(void* dstptr, const void* srcptr, uint32_t size); 17 | static int memcmp(const void* aptr, const void* bptr, uint32_t size); 18 | static void* memset(void* bufptr, char value, uint32_t size); 19 | static void* memcpy(void* dstptr, const void* srcptr, uint32_t size); 20 | }; 21 | } 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /kernel/include/common/print.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__COMMON__PRINTF_H 2 | #define __CACTUSOS__COMMON__PRINTF_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace common 11 | { 12 | class Print 13 | { 14 | public: 15 | static void printfHex(uint8_t key); 16 | static void printfHex16(uint16_t key); 17 | static void printfHex32(uint32_t key); 18 | static void printbits(uint8_t key); 19 | static void printbits(uint16_t key); 20 | static void printbits(uint32_t key); 21 | static void printbits(uint64_t key); 22 | }; 23 | } 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /kernel/include/common/random.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__COMMON__RANDOM_H 2 | #define __CACTUSOS__COMMON__RANDOM_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace common 9 | { 10 | class Random 11 | { 12 | private: 13 | static uint32_t next; 14 | public: 15 | static int Next(uint32_t max = 32767); 16 | static int Next(uint32_t min, uint32_t max); 17 | static void SetSeed(uint32_t seed); 18 | }; 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /kernel/include/common/string.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__COMMON__STRING_H 2 | #define __CACTUSOS__COMMON__STRING_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace common 11 | { 12 | #define isalpha(c) (((unsigned)c|32)-'a' < 26) 13 | 14 | class String 15 | { 16 | public: 17 | static int strlen(const char* str); 18 | static bool strcmp(const char* strA, const char* strB); 19 | static bool strncmp(const char* s1, const char* s2, int n); 20 | static int IndexOf(const char* str, char c, common::uint32_t skip = 0); 21 | static bool Contains(const char* str, char c); 22 | static List Split(const char* str, char d); 23 | static char* Uppercase(char* str); 24 | static char* Lowercase(char* str); 25 | static char Uppercase(char c); 26 | static char Lowercase(char c); 27 | static char* strcpy(char *s1, const char *s2); 28 | static char* strncpy(char *s1, const char *s2, unsigned int n); 29 | }; 30 | } 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /kernel/include/common/types.h: -------------------------------------------------------------------------------- 1 | #ifndef CACTUSOS__COMMON__TYPES_H 2 | #define CACTUSOS__COMMON__TYPES_H 3 | 4 | namespace CactusOS 5 | { 6 | namespace common 7 | { 8 | typedef char int8_t; 9 | typedef unsigned char uint8_t; 10 | typedef short int16_t; 11 | typedef unsigned short uint16_t; 12 | typedef int int32_t; 13 | typedef unsigned int uint32_t; 14 | typedef long long int int64_t; 15 | typedef unsigned long long int uint64_t; 16 | typedef unsigned long long uintptr_t; 17 | 18 | constexpr uint64_t divide64(uint64_t n, uint32_t base, uint32_t* r = 0) 19 | { 20 | uint64_t rem = n; 21 | uint64_t b = base; 22 | uint64_t res = 0, d = 1; 23 | uint32_t high = rem >> 32; 24 | 25 | /* Reduce the thing a bit first */ 26 | if (high >= base) { 27 | high /= base; 28 | res = (uint64_t) high << 32; 29 | rem -= (uint64_t) (high*base) << 32; 30 | } 31 | 32 | while ((int64_t)b > 0 && b < rem) { 33 | b = b+b; 34 | d = d+d; 35 | } 36 | 37 | do { 38 | if (rem >= b) { 39 | rem -= b; 40 | res += d; 41 | } 42 | b >>= 1; 43 | d >>= 1; 44 | } while (d); 45 | 46 | if(r) 47 | *r = rem; 48 | 49 | return res; 50 | } 51 | } 52 | constexpr common::uint32_t operator"" _KB(unsigned long long no) 53 | { 54 | return no * 1024; 55 | } 56 | constexpr common::uint32_t operator"" _MB(unsigned long long no) 57 | { 58 | return no * (1024_KB); 59 | } 60 | constexpr common::uint32_t operator"" _GB(unsigned long long no) 61 | { 62 | return no * (1024_MB); 63 | } 64 | } 65 | 66 | #endif -------------------------------------------------------------------------------- /kernel/include/core/cpu.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__CORE__CPU_H 2 | #define __CACTUSOS__CORE__CPU_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace core 9 | { 10 | #define EDX_SSE2 (1 << 26) // Streaming SIMD Extensions 2 11 | #define EDX_FXSR (1 << 24) // Can we use the fxsave/fxrstor instructions? 12 | 13 | class CPU 14 | { 15 | public: 16 | static void PrintVendor(); 17 | static void EnableFeatures(); 18 | }; 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /kernel/include/core/exceptions.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__CORE__EXCEPTIONS_H 2 | #define __CACTUSOS__CORE__EXCEPTIONS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace CactusOS 10 | { 11 | namespace core 12 | { 13 | struct SelectorErrorCode 14 | { 15 | common::uint8_t External : 1; 16 | common::uint8_t Table : 2; 17 | common::uint16_t TableIndex : 13; 18 | } __attribute__((packed)); 19 | 20 | 21 | class Exceptions 22 | { 23 | private: 24 | static common::uint32_t DivideByZero(common::uint32_t esp); 25 | static common::uint32_t GeneralProtectionFault(common::uint32_t esp); 26 | static common::uint32_t PageFault(common::uint32_t esp); 27 | static common::uint32_t TrapException(common::uint32_t esp); 28 | static common::uint32_t FloatingPointException(common::uint32_t esp); 29 | static common::uint32_t StackSegmentFault(common::uint32_t esp); 30 | static void ShowStacktrace(common::uint32_t esp); 31 | public: 32 | static common::uint32_t HandleException(common::uint32_t number, common::uint32_t esp); 33 | 34 | /* 35 | * Enables the automatic pagefault fix procedure 36 | * Warning: Only use when trying to access physical memory with no way to map it. 37 | */ 38 | static void EnablePagefaultAutoFix(); 39 | /* 40 | * Disables the automatic pagefault fix procedure 41 | */ 42 | static void DisablePagefaultAutoFix(); 43 | }; 44 | } 45 | } 46 | 47 | #endif -------------------------------------------------------------------------------- /kernel/include/core/fpu.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__CORE__FPU_H 2 | #define __CACTUSOS__CORE__FPU_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace core 9 | { 10 | struct FPUControlWord 11 | { 12 | common::uint8_t InvalidOperand : 1; 13 | common::uint8_t DenormalOperand : 1; 14 | common::uint8_t ZeroDevide : 1; 15 | common::uint8_t Overflow : 1; 16 | common::uint8_t Underflow : 1; 17 | common::uint8_t Precision : 1; 18 | common::uint8_t reserved1 : 1; 19 | common::uint8_t reserved2 : 1; 20 | common::uint8_t PrecisionControl : 2; 21 | common::uint8_t RoundingControl : 2; 22 | common::uint8_t InfinityControl : 1; 23 | common::uint8_t reserved3 : 3; 24 | } __attribute__((packed)); 25 | 26 | class FPU 27 | { 28 | public: 29 | static void Enable(); 30 | }; 31 | } 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /kernel/include/core/gdt.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__CORE__GDT_H 2 | #define __CACTUSOS__CORE__GDT_H 3 | 4 | #include 5 | 6 | using namespace CactusOS::common; 7 | 8 | namespace CactusOS 9 | { 10 | namespace core 11 | { 12 | struct GDTEntry 13 | { 14 | common::uint16_t limit_low; // The lower 16 bits of the limit. 15 | common::uint16_t base_low; // The lower 16 bits of the base. 16 | common::uint8_t base_middle; // The next 8 bits of the base. 17 | common::uint8_t access; // Access flags, determine what ring this segment can be used in. 18 | common::uint8_t granularity; 19 | common::uint8_t base_high; // The last 8 bits of the base. 20 | } __attribute__((packed)); 21 | 22 | struct GDTPointer 23 | { 24 | common::uint16_t limit; // The upper 16 bits of all selector limits. 25 | common::uint32_t base; // The address of the first gdt_entry_t struct. 26 | } __attribute__((packed)); 27 | 28 | class GlobalDescriptorTable 29 | { 30 | public: 31 | static void SetDescriptor(int number, common::uint32_t base, common::uint32_t limit, common::uint8_t access, common::uint8_t gran); 32 | static GDTEntry* GetDescriptor(int number); 33 | static void Init(); 34 | }; 35 | } 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /kernel/include/core/power.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__CORE__POWER_H 2 | #define __CACTUSOS__CORE__POWER_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace core 9 | { 10 | class Power 11 | { 12 | public: 13 | static void Initialize(); 14 | static void Reboot(); 15 | static void Poweroff(); 16 | }; 17 | } 18 | } 19 | 20 | #endif -------------------------------------------------------------------------------- /kernel/include/core/tss.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__CORE__TSS_H 2 | #define __CACTUSOS__CORE__TSS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace core 11 | { 12 | struct TSSEntry { 13 | common::uint32_t prevTss; 14 | common::uint32_t esp0; 15 | common::uint32_t ss0; 16 | common::uint32_t esp1; 17 | common::uint32_t ss1; 18 | common::uint32_t esp2; 19 | common::uint32_t ss2; 20 | common::uint32_t cr3; 21 | common::uint32_t eip; 22 | common::uint32_t eflags; 23 | common::uint32_t eax; 24 | common::uint32_t ecx; 25 | common::uint32_t edx; 26 | common::uint32_t ebx; 27 | common::uint32_t esp; 28 | common::uint32_t ebp; 29 | common::uint32_t esi; 30 | common::uint32_t edi; 31 | common::uint32_t es; 32 | common::uint32_t cs; 33 | common::uint32_t ss; 34 | common::uint32_t ds; 35 | common::uint32_t fs; 36 | common::uint32_t gs; 37 | common::uint32_t ldt; 38 | common::uint16_t trap; 39 | common::uint16_t iomap; 40 | }; 41 | 42 | class TSS 43 | { 44 | public: 45 | static void Install(common::uint32_t idx, common::uint32_t kernelSS, common::uint32_t kernelESP); 46 | static void SetStack(common::uint32_t kernelSS, common::uint32_t kernelESP); 47 | static TSSEntry* GetCurrent(); 48 | }; 49 | } 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /kernel/include/installer/installer.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__INSTALLER__INSTALLER_H 2 | #define __CACTUSOS__INSTALLER__INSTALLER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | // Class responsible for installing CactusOS on a hard drive 10 | class Installer 11 | { 12 | public: 13 | static void SetupError(); 14 | static void Run(); 15 | static char GetKey(); 16 | 17 | // Installer Steps 18 | static void ShowWelcomeMessage(); 19 | static void ShowWarningMessage(); 20 | static void ShowDiskSelection(); 21 | static void ShowDiskEraseMenu(); 22 | static void ShowInstallScreen(); 23 | static void ShowSystemCopyScreen(system::FAT* fatFS); 24 | static void CreateFatPartition(system::PartitionTableEntry* pEntry); 25 | }; 26 | 27 | #define KEY_ENTER 0x1C 28 | #define KEY_ARROW_UP 0x48 29 | #define KEY_ARROW_DOWN 0x50 30 | #define KEY_LEFT_ARROW 0x33 31 | #define KEY_RIGHT_ARROW 0x34 32 | #define KEY_MINUS 0x0C 33 | #define KEY_PLUS 0x0D 34 | #define KEY_A 0x1E 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /kernel/include/installer/textgui.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__INSTALLER__TEXTGUI_H 2 | #define __CACTUSOS__INSTALLER__TEXTGUI_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | #define TEXT_COLOR system::VGA_COLOR_WHITE 9 | 10 | //Draw a simple gui using the VGA text mode 11 | class TextGUI 12 | { 13 | public: 14 | static void DisableCursor(); 15 | static void SetPixel(int x, int y, char color, common::uint16_t character = ' ', char background = system::VGA_COLOR_BLUE); 16 | static void ClearScreen(char color = system::VGA_COLOR_BLACK); 17 | static void StatusBar(char* text, int percentage = 0); 18 | static void DrawString(char* text, int x, int y, char color = TEXT_COLOR, char background = system::VGA_COLOR_BLUE); 19 | }; 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /kernel/include/system/bootconsole.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__BOOTCONSOLE_H 2 | #define __CACTUSOS__SYSTEM__BOOTCONSOLE_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace CactusOS 10 | { 11 | namespace system 12 | { 13 | #define VGA_WIDTH 80 14 | #define VGA_HEIGHT 25 15 | 16 | enum vga_color { 17 | VGA_COLOR_BLACK = 0, 18 | VGA_COLOR_BLUE = 1, 19 | VGA_COLOR_GREEN = 2, 20 | VGA_COLOR_CYAN = 3, 21 | VGA_COLOR_RED = 4, 22 | VGA_COLOR_MAGENTA = 5, 23 | VGA_COLOR_BROWN = 6, 24 | VGA_COLOR_LIGHT_GREY = 7, 25 | VGA_COLOR_DARK_GREY = 8, 26 | VGA_COLOR_LIGHT_BLUE = 9, 27 | VGA_COLOR_LIGHT_GREEN = 10, 28 | VGA_COLOR_LIGHT_CYAN = 11, 29 | VGA_COLOR_LIGHT_RED = 12, 30 | VGA_COLOR_LIGHT_MAGENTA = 13, 31 | VGA_COLOR_LIGHT_BROWN = 14, 32 | VGA_COLOR_WHITE = 15 33 | }; 34 | 35 | class BootConsole 36 | { 37 | private: 38 | static int XOffset; 39 | static int YOffset; 40 | static bool writeToSerial; 41 | 42 | static void Scroll(); 43 | public: 44 | static common::uint8_t ForegroundColor; 45 | static common::uint8_t BackgroundColor; 46 | 47 | static void Init(bool enableSerial = false); 48 | 49 | static void Write(char c); 50 | static void Write(char* str); 51 | static void WriteLine(char* str); 52 | static void WriteLine(); 53 | 54 | static void Clear(); 55 | static void SetX(int x); 56 | static void SetY(int y); 57 | 58 | static common::uint16_t* GetBuffer(); 59 | }; 60 | } 61 | } 62 | 63 | #endif -------------------------------------------------------------------------------- /kernel/include/system/components/bochsvbe.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__COMPONENTS__BOCHSVBE_H 2 | #define __CACTUSOS__SYSTEM__COMPONENTS__BOCHSVBE_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | #define VBE_DISPI_BANK_ADDRESS 0xA0000 11 | #define VBE_DISPI_BANK_SIZE_KB 64 12 | 13 | #define VBE_DISPI_MAX_XRES 1024 14 | #define VBE_DISPI_MAX_YRES 768 15 | 16 | #define VBE_DISPI_IOPORT_INDEX 0x01CE 17 | #define VBE_DISPI_IOPORT_DATA 0x01CF 18 | 19 | #define VBE_DISPI_INDEX_ID 0x0 20 | #define VBE_DISPI_INDEX_XRES 0x1 21 | #define VBE_DISPI_INDEX_YRES 0x2 22 | #define VBE_DISPI_INDEX_BPP 0x3 23 | #define VBE_DISPI_INDEX_ENABLE 0x4 24 | #define VBE_DISPI_INDEX_BANK 0x5 25 | #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6 26 | #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7 27 | #define VBE_DISPI_INDEX_X_OFFSET 0x8 28 | #define VBE_DISPI_INDEX_Y_OFFSET 0x9 29 | 30 | #define VBE_DISPI_ID0 0xB0C0 31 | #define VBE_DISPI_ID1 0xB0C1 32 | #define VBE_DISPI_ID2 0xB0C2 33 | #define VBE_DISPI_ID3 0xB0C3 34 | #define VBE_DISPI_ID4 0xB0C4 35 | #define VBE_DISPI_ID5 0xB0C5 36 | 37 | #define VBE_DISPI_DISABLED 0x00 38 | #define VBE_DISPI_ENABLED 0x01 39 | #define VBE_DISPI_VBE_ENABLED 0x40 40 | #define VBE_DISPI_LFB_ENABLED 0x40 41 | #define VBE_DISPI_NOCLEARMEM 0x80 42 | 43 | #define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000 44 | 45 | class BochsVBE : public GraphicsDevice, public SystemComponent 46 | { 47 | public: 48 | BochsVBE(); 49 | 50 | static bool IsAvailable(); 51 | bool SelectBestVideoMode(); 52 | }; 53 | } 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /kernel/include/system/components/graphicsdevice.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__COMPONENTS__GRAPHICSDEVICE_H 2 | #define __CACTUSOS__SYSTEM__COMPONENTS__GRAPHICSDEVICE_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class GraphicsDevice 11 | { 12 | public: 13 | common::uint32_t width; 14 | common::uint32_t height; 15 | common::uint8_t bpp; 16 | common::uint32_t framebufferPhys; 17 | char* identifier = 0; 18 | 19 | GraphicsDevice(char* name); 20 | virtual ~GraphicsDevice(); 21 | virtual bool SelectBestVideoMode(); 22 | 23 | common::uint32_t GetBufferSize(); 24 | 25 | static GraphicsDevice* GetBestDevice(); 26 | }; 27 | } 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /kernel/include/system/components/pit.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__CORE__PIT_H 2 | #define __CACTUSOS__CORE__PIT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | #define PIT_FREQUENCY 1000 13 | 14 | class PIT : public SystemComponent, public InterruptHandler 15 | { 16 | private: 17 | volatile common::uint64_t timer_ticks; 18 | public: 19 | PIT(); 20 | 21 | common::uint32_t HandleInterrupt(common::uint32_t esp); 22 | void Sleep(common::uint32_t ms); 23 | 24 | //PCSpeaker 25 | void PlaySound(common::uint32_t nFrequence); 26 | void NoSound(); 27 | void Beep(); 28 | void Beep(common::uint32_t freq); 29 | void Beep(common::uint32_t freq, common::uint32_t duration); 30 | 31 | common::uint64_t Ticks(); 32 | }; 33 | } 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /kernel/include/system/components/rtc.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__COMPONENTS__RTC_H 2 | #define __CACTUSOS__SYSTEM__COMPONENTS__RTC_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | #define CURRENT_YEAR 2020 12 | 13 | class RTC : public SystemComponent 14 | { 15 | private: 16 | bool UpdateInProgress(); 17 | common::uint8_t ReadRegister(int reg); 18 | public: 19 | RTC(); 20 | 21 | common::uint32_t GetSecond(); 22 | common::uint32_t GetMinute(); 23 | common::uint32_t GetHour(); 24 | common::uint32_t GetDay(); 25 | common::uint32_t GetMonth(); 26 | common::uint32_t GetYear(); 27 | }; 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /kernel/include/system/components/systemcomponent.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__COMPONENTS_H 2 | #define __CACTUSOS__SYSTEM__COMPONENTS_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class SystemComponent 11 | { 12 | private: 13 | char* Name; 14 | char* Description; 15 | public: 16 | SystemComponent(char* name = 0, char* description = 0); 17 | 18 | char* GetComponentName(); 19 | char* GetComponentDescription(); 20 | }; 21 | } 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /kernel/include/system/disks/disk.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DISKS__DISK_H 2 | #define __CACTUSOS__SYSTEM__DISKS__DISK_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | class DiskController; 13 | 14 | enum DiskType 15 | { 16 | HardDisk, 17 | USBDisk, 18 | Floppy, 19 | CDROM 20 | }; 21 | 22 | class Disk 23 | { 24 | public: 25 | DiskController* controller; // Which controller is controling this disk device 26 | common::uint32_t controllerIndex; // The real number for the disk on the controller 27 | char* identifier = 0; // Disk Identifier 28 | DiskType type; // Type of disk 29 | common::uint64_t size; // Size of disk in bytes 30 | common::uint32_t numBlocks; // Number of data blocks 31 | common::uint32_t blockSize; // Size of one block of data 32 | 33 | Disk(common::uint32_t controllerIndex, DiskController* controller, DiskType type, common::uint64_t size, common::uint32_t blocks, common::uint32_t blocksize); 34 | 35 | virtual char ReadSector(common::uint32_t lba, common::uint8_t* buf); 36 | virtual char WriteSector(common::uint32_t lba, common::uint8_t* buf); 37 | }; 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /kernel/include/system/disks/diskcontroller.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DISKS__DISKCONTROLLER_H 2 | #define __CACTUSOS__SYSTEM__DISKS__DISKCONTROLLER_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace CactusOS 13 | { 14 | namespace system 15 | { 16 | class DiskController 17 | { 18 | public: 19 | DiskController(); 20 | 21 | virtual char ReadSector(common::uint16_t drive, common::uint32_t lba, common::uint8_t* buf); 22 | virtual char WriteSector(common::uint16_t drive, common::uint32_t lba, common::uint8_t* buf); 23 | virtual bool EjectDrive(common::uint8_t drive); 24 | }; 25 | } 26 | } 27 | 28 | 29 | #endif -------------------------------------------------------------------------------- /kernel/include/system/disks/diskmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DISKS__DISKMANAGER_H 2 | #define __CACTUSOS__SYSTEM__DISKS__DISKMANAGER_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace CactusOS 15 | { 16 | namespace system 17 | { 18 | struct BiosDriveParameters 19 | { 20 | common::uint16_t bufLen; 21 | common::uint16_t infoFlags; 22 | common::uint32_t cilinders; 23 | common::uint32_t heads; 24 | common::uint32_t sectorsPerTrack; 25 | common::uint64_t totalSectors; 26 | common::uint16_t bytesPerSector; 27 | 28 | common::uint32_t eddParameters; 29 | 30 | common::uint16_t signature; 31 | common::uint8_t devPathLen; 32 | common::uint8_t reserved1[3]; 33 | char hostBusName[4]; 34 | char interfaceName[8]; 35 | common::uint8_t interfacePath[8]; 36 | common::uint8_t devicePath[8]; 37 | common::uint8_t reserved2; 38 | common::uint8_t checksum; 39 | } __attribute__((packed)); 40 | 41 | class Disk; 42 | class DiskManager 43 | { 44 | public: 45 | List allDisks; 46 | 47 | DiskManager(); 48 | 49 | //Add disk to system and check for filesystems 50 | void AddDisk(Disk* disk); 51 | //Remove disk from system and unmount filesystems 52 | void RemoveDisk(Disk* disk); 53 | 54 | char ReadSector(common::uint16_t drive, common::uint32_t lba, common::uint8_t* buf); 55 | char WriteSector(common::uint16_t drive, common::uint32_t lba, common::uint8_t* buf); 56 | 57 | BiosDriveParameters* GetDriveInfoBios(common::uint8_t drive); 58 | }; 59 | } 60 | } 61 | 62 | 63 | #endif -------------------------------------------------------------------------------- /kernel/include/system/disks/partitionmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DISKS__PARTITIONMANAGER_H 2 | #define __CACTUSOS__SYSTEM__DISKS__PARTITIONMANAGER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | struct PartitionTableEntry 12 | { 13 | common::uint8_t bootable; 14 | 15 | common::uint8_t start_head; 16 | common::uint8_t start_sector : 6; 17 | common::uint16_t start_cylinder : 10; 18 | 19 | common::uint8_t partition_id; 20 | 21 | common::uint8_t end_head; 22 | common::uint8_t end_sector : 6; 23 | common::uint16_t end_cylinder : 10; 24 | 25 | common::uint32_t start_lba; 26 | common::uint32_t length; 27 | } __attribute__((packed)); 28 | 29 | 30 | struct MasterBootRecord 31 | { 32 | common::uint8_t bootloader[440]; 33 | common::uint32_t signature; 34 | common::uint16_t unused; 35 | 36 | PartitionTableEntry primaryPartitions[4]; 37 | 38 | common::uint16_t magicnumber; 39 | } __attribute__((packed)); 40 | 41 | class PartitionManager 42 | { 43 | private: 44 | //Check partition type and assign filesystem driver if available 45 | static void AssignVFS(PartitionTableEntry partition, Disk* disk); 46 | public: 47 | //Read partition descriptor of disk and assign fileysysem if possible 48 | static void DetectAndLoadFilesystem(Disk* disk); 49 | }; 50 | } 51 | } 52 | 53 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/disk/ahci/ahcicontroller.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__DISK_CONTROLLERS__AHCI_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__DISK_CONTROLLERS__AHCI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace CactusOS 12 | { 13 | namespace system 14 | { 15 | namespace drivers 16 | { 17 | class AHCIController : public Driver, public InterruptHandler, public DiskController 18 | { 19 | private: 20 | // Array of ports that are present on this controller 21 | AHCIPort* ports[32]; 22 | 23 | PCIDevice* pciDevice = 0; 24 | 25 | uint32_t regBase = 0; 26 | int32_t portCount = 0; 27 | 28 | // Read AHCI Register from memory location 29 | inline uint32_t readRegister(uint32_t offset); 30 | 31 | // Write a value to an AHCI Register 32 | inline void writeRegister(uint32_t offset, uint32_t value); 33 | 34 | // Wait for a specific bit to be clear in a register 35 | inline bool waitForClear(uint32_t reg, uint32_t bits, uint32_t timeout); 36 | 37 | // Wait for a specific bit to be set in a register 38 | inline bool waitForSet(uint32_t reg, uint32_t bits, uint32_t timeout); 39 | public: 40 | AHCIController(PCIDevice* device); 41 | 42 | bool Initialize() override; 43 | bool Reset(); 44 | 45 | common::uint32_t HandleInterrupt(common::uint32_t esp) override; 46 | 47 | // DiskController Functions 48 | char ReadSector(common::uint16_t drive, common::uint32_t lba, common::uint8_t* buf) override; 49 | char WriteSector(common::uint16_t drive, common::uint32_t lba, common::uint8_t* buf) override; 50 | bool EjectDrive(common::uint8_t drive) override; 51 | }; 52 | } 53 | } 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/driver.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVER_H 2 | #define __CACTUSOS__SYSTEM__DRIVER_H 3 | 4 | namespace CactusOS 5 | { 6 | namespace system 7 | { 8 | namespace drivers 9 | { 10 | class Driver 11 | { 12 | private: 13 | char* Name; 14 | char* Description; 15 | public: 16 | Driver(char* name = 0, char* description = 0); 17 | 18 | char* GetDriverName(); 19 | char* GetDriverDescription(); 20 | 21 | virtual bool Initialize(); 22 | }; 23 | } 24 | } 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/drivermanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERMANAGER__DRIVER_H 2 | #define __CACTUSOS__SYSTEM__DRIVERMANAGER__DRIVER_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace CactusOS 11 | { 12 | namespace system 13 | { 14 | namespace drivers 15 | { 16 | class DriverManager 17 | { 18 | private: 19 | List driverList; 20 | public: 21 | DriverManager(); 22 | 23 | void AddDriver(Driver* drv); 24 | 25 | void ActivateAll(); 26 | }; 27 | } 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/integrated/ps2-keyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__PS2KEYBOARD_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__PS2KEYBOARD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace CactusOS 10 | { 11 | namespace system 12 | { 13 | namespace drivers 14 | { 15 | #define PS2_DATA 0x60 16 | #define PS2_STATUS 0x64 17 | #define PS2_COMMAND 0x64 18 | 19 | class PS2KeyboardDriver : public InterruptHandler, public Keyboard, public Driver, public FIFOStream 20 | { 21 | public: 22 | PS2KeyboardDriver(); 23 | 24 | bool Initialize(); 25 | common::uint32_t HandleInterrupt(common::uint32_t esp); 26 | 27 | // Update LED's on a keyboard device 28 | void UpdateLEDS() override; 29 | }; 30 | } 31 | } 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/integrated/ps2-mouse.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__PS2MOUSE_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__PS2MOUSE_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | namespace drivers 12 | { 13 | struct MousePacket 14 | { 15 | unsigned char LeftBTN : 1; 16 | unsigned char RightBTN : 1; 17 | unsigned char MiddleBTN : 1; 18 | unsigned char Always1 : 1; 19 | unsigned char Xsign : 1; 20 | unsigned char Ysign : 1; 21 | unsigned char Xoverflow : 1; 22 | unsigned char Yoverflow : 1; 23 | 24 | signed char XMovement; 25 | signed char YMovement; 26 | signed char ZMovement; //if MouseID == 3 27 | }; 28 | 29 | 30 | class PS2MouseDriver : public InterruptHandler, public Driver 31 | { 32 | private: 33 | #define MOUSE_DATA 0x60 34 | #define MOUSE_COMMAND 0x64 35 | #define MOUSE_ACK 0xFA 36 | 37 | common::uint8_t MouseID = 0; 38 | common::uint8_t MouseCycle = 0; 39 | signed char* packetBuffer; 40 | 41 | bool ready = false; 42 | public: 43 | PS2MouseDriver(); 44 | 45 | bool Initialize(); 46 | common::uint32_t HandleInterrupt(common::uint32_t esp); 47 | 48 | /** 49 | * Enable the scrollwheel for this mouse, returns true when succeeded 50 | */ 51 | bool EnableScrollWheel(); 52 | /** 53 | * Valid values: 10,20,40,60,80,100,200 54 | */ 55 | bool SetSampleRate(common::uint8_t value); 56 | /** 57 | * Handle a packet send by the mouse 58 | */ 59 | void ProcessPacket(); 60 | }; 61 | } 62 | } 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/pcidrivers.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__PCIDRIVERS_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__PCIDRIVERS_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | namespace drivers 12 | { 13 | struct PCIAttachedDriverEntry 14 | { 15 | common::uint16_t vendorID; 16 | common::uint16_t deviceID; 17 | char* driverString; 18 | } __attribute__((packed)); 19 | 20 | class PCIDrivers 21 | { 22 | public: 23 | static void AssignDriversFromPCI(PCIController* pci, DriverManager* driverManager); 24 | }; 25 | } 26 | } 27 | } 28 | 29 | 30 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/usb/usbcomborecv.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__USB__COMBORECEIVER_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__USB__COMBORECEIVER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | namespace drivers 13 | { 14 | // Class describing a device used for both keyboard and mouse input 15 | class USBComboReceiver: public USBDriver, public Keyboard 16 | { 17 | private: 18 | uint8_t prevPacket[8]; 19 | 20 | int keyboardIntEndpoint = -1; 21 | int mouseIntEndpoint = -1; 22 | 23 | int keyboardInterface = -1; 24 | int mouseInterface = -1; 25 | public: 26 | // Instance initializer 27 | USBComboReceiver(USBDevice* dev); 28 | 29 | // Called when device is plugged into system 30 | bool Initialize() override; 31 | 32 | // Called when device is unplugged from system 33 | void DeInitialize() override; 34 | 35 | // Called by USB driver when we receive a interrupt packet 36 | bool HandleInterruptPacket(InterruptTransfer_t* transfer) override; 37 | }; 38 | } 39 | } 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/usb/usbdriver.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__USB__USBDRIVER_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__USB__USBDRIVER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | typedef struct InterruptTransfer InterruptTransfer_t; 12 | 13 | class USBDriver : public drivers::Driver 14 | { 15 | public: 16 | // Which device is this driver for 17 | USBDevice* device; 18 | public: 19 | USBDriver(USBDevice* dev, char* driverName); 20 | virtual ~USBDriver(); 21 | 22 | // De-Active this driver from the system 23 | // Called when device is unplugged 24 | virtual void DeInitialize(); 25 | 26 | // Called from USB Controller when a interrupt packet is received 27 | virtual bool HandleInterruptPacket(InterruptTransfer_t* transfer); 28 | }; 29 | } 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/usb/usbkeyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__USB__KEYBOARD_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__USB__KEYBOARD_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | namespace drivers 13 | { 14 | class USBKeyboard : public USBDriver, public Keyboard 15 | { 16 | private: 17 | int InInterruptEndpoint = -1; 18 | 19 | uint8_t prevPacket[8]; 20 | public: 21 | // Instance initializer 22 | USBKeyboard(USBDevice* dev); 23 | 24 | // Called when mass storage device is plugged into system 25 | bool Initialize() override; 26 | 27 | // Called when mass storage device is unplugged from system 28 | void DeInitialize() override; 29 | 30 | // Called by USB driver when we receive a interrupt packet 31 | bool HandleInterruptPacket(InterruptTransfer_t* transfer) override; 32 | 33 | // Update LED's on a keyboard device 34 | void UpdateLEDS() override; 35 | }; 36 | } 37 | } 38 | } 39 | 40 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/usb/usbmouse.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__USB__MOUSE_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__USB__MOUSE_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | namespace drivers 12 | { 13 | class USBMouse : public USBDriver 14 | { 15 | private: 16 | HIDParser hidParser; 17 | bool GetHIDProperty(struct HID_DATA* target, uint8_t* buffer, int bufLen, HID_USAGE item); 18 | 19 | bool useCustomReport = false; 20 | struct HID_DATA hidX; 21 | struct HID_DATA hidY; 22 | struct HID_DATA hidZ; 23 | 24 | int InInterruptEndpoint = -1; 25 | public: 26 | // Instance initializer 27 | USBMouse(USBDevice* dev); 28 | 29 | // Called when device is plugged into system 30 | bool Initialize() override; 31 | 32 | // Called when device is unplugged from system 33 | void DeInitialize() override; 34 | 35 | // Called by USB driver when we receive a interrupt packet 36 | bool HandleInterruptPacket(InterruptTransfer_t* transfer) override; 37 | }; 38 | } 39 | } 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /kernel/include/system/drivers/video/vmwaresvga.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DRIVERS__VMWARESVGA_H 2 | #define __CACTUSOS__SYSTEM__DRIVERS__VMWARESVGA_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace CactusOS 10 | { 11 | namespace system 12 | { 13 | namespace drivers 14 | { 15 | #define VMWARESVGAII_VENDORID 0x15AD 16 | #define VMWARESVGAII_DEVICEID 0x0405 17 | 18 | #define SVGA_INDEX_PORT 0x0 19 | #define SVGA_VALUE_PORT 0x1 20 | #define SVGA_BIOS_PORT 0x2 21 | #define SVGA_IRQSTATUS_PORT 0x8 22 | 23 | #define SVGA_MAGIC 0x900000UL 24 | #define SVGA_MAKE_ID(ver) (SVGA_MAGIC << 8 | (ver)) 25 | 26 | /* Version 2 let the address of the frame buffer be unsigned on Win32 */ 27 | #define SVGA_VERSION_2 2 28 | #define SVGA_ID_2 SVGA_MAKE_ID(SVGA_VERSION_2) 29 | 30 | #define SVGA_REG_ID 0 31 | #define SVGA_REG_FB_START 13 32 | #define SVGA_REG_FB_Enable 1 33 | #define SVGA_REG_FB_Width 2 34 | #define SVGA_REG_FB_Height 3 35 | #define SVGA_REG_FB_BitsPerPixel 7 36 | 37 | class VMWARESVGAII : public Driver, public GraphicsDevice 38 | { 39 | private: 40 | PCIDevice* pciDevice; 41 | 42 | void WriteRegister(common::uint32_t reg, common::uint32_t value); 43 | common::uint32_t ReadRegister(common::uint32_t reg); 44 | public: 45 | VMWARESVGAII(PCIDevice* pciDev); 46 | 47 | bool Initialize(); 48 | bool SelectBestVideoMode(); 49 | }; 50 | } 51 | } 52 | } 53 | 54 | #endif -------------------------------------------------------------------------------- /kernel/include/system/initrd.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__INITRD_H 2 | #define __CACTUSOS__SYSTEM__INITRD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace CactusOS 10 | { 11 | namespace system 12 | { 13 | struct InitrdFileHeader 14 | { 15 | char name[30]; 16 | char path[100]; 17 | common::uint32_t size; 18 | } __attribute__((packed)); 19 | 20 | class InitialRamDisk 21 | { 22 | public: 23 | static void Initialize(multiboot_info_t* mbi); 24 | 25 | static void* ReadFile(const char* path, common::uint32_t* fileSizeReturn = 0); 26 | }; 27 | } 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /kernel/include/system/input/keyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__INPUT__KEYBOARD_H 2 | #define __CACTUSOS__SYSTEM__INPUT__KEYBOARD_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | // Structure for modifier keys that are keyboard specific 11 | struct InternalKeyboardStatus 12 | { 13 | bool LeftShift; 14 | bool RightShift; 15 | 16 | bool Alt; 17 | bool AltGr; 18 | 19 | bool LeftControl; 20 | bool RightControl; 21 | }; 22 | 23 | // Structure for shared modifier keys between keyboards 24 | struct KeyboardStatus 25 | { 26 | bool CapsLock; 27 | bool NumLock; 28 | }; 29 | 30 | // Types of keyboards currently supported 31 | enum KeyboardType 32 | { 33 | PS2, 34 | USB 35 | }; 36 | 37 | // Interface for providing a common access for all keyboard devices 38 | class Keyboard 39 | { 40 | public: 41 | KeyboardType type; 42 | InternalKeyboardStatus status; 43 | public: 44 | Keyboard(KeyboardType type); 45 | 46 | // Update LED's on a keyboard device 47 | virtual void UpdateLEDS(); 48 | 49 | // Checks if the buffer contains the given key, also returns position of key 50 | bool ContainsKey(common::uint8_t key, common::uint8_t* packet, int* pos); 51 | }; 52 | } 53 | } 54 | 55 | #endif -------------------------------------------------------------------------------- /kernel/include/system/input/keyboardmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__INPUT__KEYBOARDMANAGER_H 2 | #define __CACTUSOS__SYSTEM__INPUT__KEYBOARDMANAGER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | // Class responsable for managing all keyboard devices present on the system 13 | // Also provides a stream interface to read keystrokes 14 | class KeyboardManager : public FIFOStream 15 | { 16 | public: 17 | // List of all keyboards present on system 18 | List keyboards; 19 | 20 | // Status of all keyboards 21 | KeyboardStatus sharedStatus; 22 | private: 23 | uint8_t ConvertToPS2(uint32_t key); 24 | public: 25 | KeyboardManager(); 26 | 27 | // Handle a keypress or a change in modifier keys 28 | void HandleKeyChange(Keyboard* src, uint32_t key, bool pressed); 29 | }; 30 | } 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /kernel/include/system/interruptmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__INTERRUPTMANAGER_H 2 | #define __CACTUSOS__SYSTEM__INTERRUPTMANAGER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | class InterruptHandler 12 | { 13 | public: 14 | InterruptHandler(common::uint8_t intNumber); 15 | virtual common::uint32_t HandleInterrupt(common::uint32_t esp); 16 | }; 17 | 18 | 19 | class InterruptManager 20 | { 21 | private: 22 | static List* interruptCallbacks[256]; 23 | public: 24 | static void Initialize(); 25 | static common::uint32_t HandleInterrupt(common::uint8_t interrupt, common::uint32_t esp); 26 | 27 | static void AddHandler(InterruptHandler* handler, common::uint8_t interrupt); 28 | static void RemoveHandler(InterruptHandler* handler, common::uint8_t interrupt); 29 | }; 30 | } 31 | } 32 | 33 | 34 | #endif -------------------------------------------------------------------------------- /kernel/include/system/listings/directorylisting.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__LISTINGS__DIRECTORYLISTING_H 2 | #define __CACTUSOS__SYSTEM__LISTINGS__DIRECTORYLISTING_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | // A class that is responsable for processes which request a directory list 11 | class DirectoryListing : public ListingController 12 | { 13 | public: 14 | /** 15 | Create new instance of DirectoryListing 16 | */ 17 | DirectoryListing(); 18 | 19 | /** 20 | Begin processing a new directorylist request 21 | Returns amount of items in directory 22 | */ 23 | int BeginListing(Thread* thread, uint32_t pathPtr) override; 24 | /** 25 | Get an item from the current request. 26 | Returns characters in file/dirname 27 | */ 28 | int GetEntry(Thread* thread, int entry, uint32_t bufPtr) override; 29 | /** 30 | End the current listing 31 | */ 32 | void EndListing(Thread* thread) override; 33 | }; 34 | } 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /kernel/include/system/listings/listingcontroller.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__VFS__LISTINGCONTROLLER_H 2 | #define __CACTUSOS__SYSTEM__VFS__LISTINGCONTROLLER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | // A class that creates an easy interface for threads to request a list from the kernel. 12 | // This can for example be a list of files or processes. 13 | class ListingController 14 | { 15 | protected: 16 | // Threads that have also requested a listing before an other one was finished. 17 | List waitingQueue; 18 | 19 | // Current thread which has requested a list 20 | Thread* currentReqThread; 21 | 22 | // Are we currently handling a request? 23 | bool requestBusy = false; 24 | public: 25 | ListingController(); 26 | 27 | virtual int BeginListing(Thread* thread, uint32_t arg1 = 0); 28 | virtual int GetEntry(Thread* thread, int entry, uint32_t bufPtr); 29 | virtual void EndListing(Thread* thread); 30 | }; 31 | } 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /kernel/include/system/listings/systeminfo.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__LISTINGS__SYSTEMINFO_H 2 | #define __CACTUSOS__SYSTEM__LISTINGS__SYSTEMINFO_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | struct SIBIOS 11 | { 12 | char* vendor = "N/A"; 13 | char* version = "N/A"; 14 | char* releaseDate = "N/A"; 15 | }; 16 | 17 | struct SISYSTEM 18 | { 19 | char* manufacturer = "N/A"; 20 | char* product = "N/A"; 21 | char* version = "N/A"; 22 | char* serial = "N/A"; 23 | char* sku = "N/A"; 24 | char* family = "N/A"; 25 | }; 26 | 27 | struct SIENCLOSURE 28 | { 29 | char* manufacturer = "N/A"; 30 | char* version = "N/A"; 31 | char* serial = "N/A"; 32 | char* sku = "N/A"; 33 | }; 34 | 35 | struct SIPROCESSOR 36 | { 37 | char* socket = "N/A"; 38 | char* manufacturer = "N/A"; 39 | char* version = "N/A"; 40 | }; 41 | 42 | class SystemInfoManager 43 | { 44 | public: 45 | static SIBIOS bios; 46 | static SISYSTEM system; 47 | static SIENCLOSURE enclosure; 48 | static SIPROCESSOR processor; 49 | public: 50 | // Handle a request from a syscall to get information about the system 51 | static bool HandleSysinfoRequest(void* arrayPointer, int count, common::uint32_t retAddr, bool getSize); 52 | }; 53 | } 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /kernel/include/system/log.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__LOG_H 2 | #define __CACTUSOS__SYSTEM__LOG_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | #define LOG_SHOW_MS 1 11 | 12 | enum LogLevel 13 | { 14 | Info, 15 | Warning, 16 | Error 17 | }; 18 | 19 | void Log(LogLevel level, const char* __restrict__ format, ...); 20 | void Print(const char* data, common::uint32_t length); 21 | } 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /kernel/include/system/memory/deviceheap.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__DEVICEHEAP_H 2 | #define __CACTUSOS__SYSTEM__DEVICEHEAP_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | // Memory reserved for devices, 100MB Should be more than enough 12 | #define DEVICE_HEAP_SIZE 100_MB 13 | 14 | #define DEVICE_HEAP_START (KERNEL_HEAP_START + KERNEL_HEAP_SIZE + 4_MB) 15 | #define DEVICE_HEAP_END (DEVICE_HEAP_START + DEVICE_HEAP_SIZE) 16 | 17 | // Class that can allocate memory for memory mapped devices 18 | class DeviceHeap 19 | { 20 | private: 21 | // Current address of last memory allocation 22 | // Will increase on every allocation 23 | static common::uint32_t currentAddress; 24 | public: 25 | // Allocate a chunck of memory in the virtual address space 26 | // Must be a page aligned size 27 | // Note: Memory needs to be mapped to right address afterwards, function does not include this 28 | static common::uint32_t AllocateChunk(common::uint32_t size); 29 | }; 30 | } 31 | } 32 | 33 | 34 | #endif -------------------------------------------------------------------------------- /kernel/include/system/memory/fifostream.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__MEMORY__FIFOSTREAM_H 2 | #define __CACTUSOS__SYSTEM__MEMORY__FIFOSTREAM_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | class FIFOStream : public Stream 13 | { 14 | private: 15 | // Internal buffer 16 | char* buffer; 17 | // End of the internal buffer 18 | char* buffer_end; 19 | // Number of items in the buffer 20 | int count; 21 | // Maximum allowed items 22 | int capacity; 23 | // Pointer to head 24 | char* head; 25 | // Pointer to tail 26 | char* tail; 27 | public: 28 | /** 29 | * Create a new fifo stream 30 | */ 31 | FIFOStream(int capacity = 100); 32 | ~FIFOStream(); 33 | 34 | /** 35 | * Read a byte from this stream 36 | */ 37 | char Read(); 38 | /** 39 | * Write a byte to this stream buffer 40 | */ 41 | void Write(char byte); 42 | /** 43 | * How many bytes can currently be read? 44 | */ 45 | int Available(); 46 | }; 47 | } 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /kernel/include/system/memory/heap.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__HEAP_H 2 | #define __CACTUSOS__SYSTEM__HEAP_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | #define KERNEL_HEAP_START (KERNEL_VIRT_ADDR + 4_MB) 12 | #define KERNEL_HEAP_SIZE 16_MB 13 | 14 | // Only split a memory block when we can use it to store this amount of data in it 15 | #define MINIMAL_SPLIT_SIZE 4 16 | 17 | // Magic number used for memory headers 18 | #define MEMORY_HEADER_MAGIC 1234567890 19 | 20 | #ifndef align_up 21 | #define align_up(num, align) \ 22 | (((num) + ((align) - 1)) & ~((align) - 1)) 23 | #endif 24 | 25 | struct MemoryHeader 26 | { 27 | common::uint32_t magic; 28 | 29 | MemoryHeader* next; 30 | MemoryHeader* prev; 31 | common::uint32_t allocated; 32 | common::uint32_t size; 33 | } __attribute__((packed)); 34 | 35 | class KernelHeap 36 | { 37 | private: 38 | static common::uint32_t startAddress; 39 | static common::uint32_t endAddress; 40 | 41 | static MemoryHeader* firstHeader; 42 | 43 | static void* InternalAllocate(common::uint32_t size); 44 | static MemoryHeader* FirstFree(common::uint32_t size); 45 | 46 | static MutexLock heapMutex; 47 | public: 48 | static void Initialize(common::uint32_t start, common::uint32_t end); 49 | 50 | static void* malloc(common::uint32_t size, common::uint32_t* physReturn = 0); 51 | static void free(void* ptr); 52 | 53 | static void* alignedMalloc(common::uint32_t size, common::uint32_t align, common::uint32_t* physReturn = 0); 54 | static void allignedFree(void* ptr); 55 | 56 | static bool CheckForErrors(); 57 | static common::uint32_t UsedMemory(); 58 | }; 59 | } 60 | } 61 | 62 | 63 | #endif -------------------------------------------------------------------------------- /kernel/include/system/memory/new.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__NEW_H 2 | #define __CACTUSOS__SYSTEM__NEW_H 3 | 4 | #include 5 | #include 6 | 7 | using namespace CactusOS::system; 8 | 9 | void *operator new(size_t size) 10 | { 11 | return KernelHeap::malloc(size); 12 | } 13 | 14 | void *operator new[](size_t size) 15 | { 16 | return KernelHeap::malloc(size); 17 | } 18 | 19 | void* operator new(size_t size, void* ptr) 20 | { 21 | return ptr; 22 | } 23 | 24 | void* operator new[](size_t size, void* ptr) 25 | { 26 | return ptr; 27 | } 28 | 29 | void operator delete(void *p) 30 | { 31 | KernelHeap::free(p); 32 | } 33 | 34 | void operator delete[](void *p) 35 | { 36 | KernelHeap::free(p); 37 | } 38 | 39 | void operator delete(void* ptr, size_t size) 40 | { 41 | KernelHeap::free(ptr); 42 | } 43 | void operator delete[](void* ptr, size_t size) 44 | { 45 | KernelHeap::free(ptr); 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /kernel/include/system/memory/sharedmem.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__MEMORY__SHAREDMEM_H 2 | #define __CACTUSOS__SYSTEM__MEMORY__SHAREDMEM_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class SharedMemory 11 | { 12 | public: 13 | /** 14 | * Create a shared area of memory between processes 15 | * Proc1: Procces 1 where the memory needs to be present 16 | * Proc2: Process 2 where the memory needs to be present 17 | * virtStart: The virtual start of the memory region 18 | * len: The length of the memory region 19 | */ 20 | static bool CreateSharedRegion(Process* proc1, Process* proc2, common::uint32_t virtStart, common::uint32_t len); 21 | /** 22 | * Create a shared area of memory between processes 23 | * Proc1: Procces 1 where the memory needs to be present 24 | * Proc2: Process 2 where the memory needs to be present 25 | * virtStart1: The virtual start of the memory region for process 1 26 | * virtStart2: The virtual start of the memory region for process 2 27 | * len: The length of the memory region 28 | */ 29 | static bool CreateSharedRegion(Process* proc1, Process* proc2, common::uint32_t virtStart1, common::uint32_t virtStart2, common::uint32_t len); 30 | /** 31 | * Remove shared memory between 2 processes 32 | */ 33 | static bool RemoveSharedRegion(Process* proc1, Process* proc2, common::uint32_t virtStart, common::uint32_t len); 34 | /** 35 | * Remove shared memory between 2 processes 36 | */ 37 | static bool RemoveSharedRegion(Process* proc1, Process* proc2, common::uint32_t virtStart1, common::uint32_t virtStart2, common::uint32_t len); 38 | }; 39 | } 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /kernel/include/system/memory/stream.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__MEMORY__STREAM_H 2 | #define __CACTUSOS__SYSTEM__MEMORY__STREAM_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class Stream 11 | { 12 | public: 13 | /** 14 | * Create a new instance of the stream class 15 | */ 16 | Stream(); 17 | /** 18 | * Delete the stream and free all the memory it has used 19 | */ 20 | virtual ~Stream(); 21 | 22 | /** 23 | * Read a byte from this stream 24 | */ 25 | virtual char Read(); 26 | /** 27 | * Write a byte to this stream buffer 28 | */ 29 | virtual void Write(char byte); 30 | /** 31 | * How many bytes can currently be read? 32 | */ 33 | virtual int Available(); 34 | }; 35 | } 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /kernel/include/system/serialport.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__SERIALPORT_H 2 | #define __CACTUSOS__SYSTEM__SERIALPORT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | enum COMPort 13 | { 14 | COM1 = 0x3F8, 15 | COM2 = 0x2F8, 16 | COM3 = 0x3E8, 17 | COM4 = 0x2E8 18 | }; 19 | 20 | class Serialport 21 | { 22 | private: 23 | static COMPort PortAddress; 24 | public: 25 | static int SerialReceiveReady(); 26 | static int SerialSendReady(); 27 | 28 | static bool Initialized; 29 | static void Init(COMPort port); 30 | 31 | static char Read(); 32 | static void Write(char a); 33 | static void WriteStr(char* str); 34 | }; 35 | } 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /kernel/include/system/syscalls/implementations/cactusos.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__SYSCALLS__IMPLEMENTATIONS_CACTUSOS_H 2 | #define __CACTUSOS__SYSTEM__SYSCALLS__IMPLEMENTATIONS_CACTUSOS_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class CactusOSSyscalls 11 | { 12 | public: 13 | static core::CPUState* HandleSyscall(core::CPUState* state); 14 | }; 15 | } 16 | } 17 | 18 | #endif -------------------------------------------------------------------------------- /kernel/include/system/syscalls/implementations/linux.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__SYSCALLS__IMPLEMENTATIONS_LINUX_H 2 | #define __CACTUSOS__SYSTEM__SYSCALLS__IMPLEMENTATIONS_LINUX_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class LinuxSyscalls 11 | { 12 | public: 13 | static core::CPUState* HandleSyscall(core::CPUState* state); 14 | }; 15 | } 16 | } 17 | 18 | #endif -------------------------------------------------------------------------------- /kernel/include/system/syscalls/syscalls.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__SYSCALLS__SYSCALLS_H 2 | #define __CACTUSOS__SYSTEM__SYSCALLS__SYSCALLS_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class SystemCallHandler : public InterruptHandler 11 | { 12 | public: 13 | SystemCallHandler(); 14 | 15 | common::uint32_t HandleInterrupt(common::uint32_t esp); 16 | }; 17 | } 18 | } 19 | 20 | #endif -------------------------------------------------------------------------------- /kernel/include/system/tasking/elf.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__ELFLOADER_H 2 | #define __CACTUSOS__SYSTEM__ELFLOADER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | #define ELFMAG0 0x7f 12 | #define ELFMAG1 'E' 13 | #define ELFMAG2 'L' 14 | #define ELFMAG3 'F' 15 | 16 | struct ElfHeader { 17 | unsigned char e_ident[16]; 18 | common::uint16_t e_type; 19 | common::uint16_t e_machine; 20 | common::uint32_t e_version; 21 | common::uint32_t e_entry; 22 | common::uint32_t e_phoff; 23 | common::uint32_t e_shoff; 24 | common::uint32_t e_flags; 25 | common::uint16_t e_ehsize; 26 | common::uint16_t e_phentsize; 27 | common::uint16_t e_phnum; 28 | common::uint16_t e_shentsize; 29 | common::uint16_t e_shnum; 30 | common::uint16_t e_shstrndx; 31 | } __attribute__((packed)); 32 | 33 | struct ElfSectionHeader { 34 | common::uint32_t sh_name; 35 | common::uint32_t sh_type; 36 | common::uint32_t sh_flags; 37 | common::uint32_t sh_addr; 38 | common::uint32_t sh_offset; 39 | common::uint32_t sh_size; 40 | common::uint32_t sh_link; 41 | common::uint32_t sh_info; 42 | common::uint32_t sh_addralign; 43 | common::uint32_t sh_entsize; 44 | } __attribute__((packed)); 45 | 46 | struct ElfProgramHeader { 47 | common::uint32_t p_type; 48 | common::uint32_t p_offset; 49 | common::uint32_t p_vaddr; 50 | common::uint32_t p_paddr; 51 | common::uint32_t p_filesz; 52 | common::uint32_t p_memsz; 53 | common::uint32_t p_flags; 54 | common::uint32_t p_align; 55 | } __attribute__((packed)); 56 | } 57 | } 58 | 59 | #endif -------------------------------------------------------------------------------- /kernel/include/system/tasking/ipcmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__TASKING__IPCMANAGER_H 2 | #define __CACTUSOS__SYSTEM__TASKING__IPCMANAGER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | struct IPCReceiveDescriptor 12 | { 13 | // Which process is waiting for a message? 14 | Process* receivingProcess; 15 | // Which thread called receive and is currently blocked. 16 | Thread* receivingThread; 17 | // Do we need to receive the message from a specific process? 18 | int receiveFromPID; 19 | // Do we need to receive a specific type of message? 20 | int receiveType; 21 | }; 22 | 23 | class IPCManager 24 | { 25 | public: 26 | static void Initialize(); 27 | static void HandleSend(core::CPUState* state, Process* proc); 28 | static void HandleReceive(core::CPUState* state, Process* proc); 29 | }; 30 | } 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /kernel/include/system/tasking/lock.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__TASKING__LOCK_H 2 | #define __CACTUSOS__SYSTEM__TASKING__LOCK_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class MutexLock 11 | { 12 | private: 13 | int value = 0; 14 | public: 15 | MutexLock(); 16 | 17 | void Lock(); 18 | void Unlock(); 19 | }; 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /kernel/include/system/tasking/process.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTOSOS__SYSTEM__TASKING__PROCESS_H 2 | #define __CACTOSOS__SYSTEM__TASKING__PROCESS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include <../../lib/include/ipc.h> 8 | #include 9 | 10 | namespace CactusOS 11 | { 12 | namespace system 13 | { 14 | class SymbolDebugger; 15 | 16 | enum ProcessState 17 | { 18 | Active 19 | }; 20 | 21 | #define PROC_USER_HEAP_SIZE 1_MB //1 MB heap space for processes, and of course more if needed. 22 | 23 | struct Thread; 24 | 25 | struct Process 26 | { 27 | int id; 28 | int syscallID; 29 | bool isUserspace; 30 | char* args; 31 | ProcessState state; 32 | List Threads; 33 | common::uint32_t pageDirPhys; 34 | struct Excecutable 35 | { 36 | common::uint32_t memBase; 37 | common::uint32_t memSize; 38 | } excecutable; 39 | 40 | struct Heap 41 | { 42 | common::uint32_t heapStart; 43 | common::uint32_t heapEnd; 44 | } heap; 45 | List ipcMessages; 46 | 47 | Stream* stdInput; 48 | Stream* stdOutput; 49 | 50 | // For Debuging 51 | char fileName[32]; 52 | 53 | // Debugger assigned to this process 54 | SymbolDebugger* symDebugger = 0; 55 | }; 56 | 57 | class ProcessHelper 58 | { 59 | private: 60 | ProcessHelper(); 61 | public: 62 | static List Processes; 63 | 64 | static Process* Create(char* fileName, char* arguments = 0, bool isKernel = false); 65 | static Process* CreateKernelProcess(); 66 | static void RemoveProcess(Process* proc); 67 | static void UpdateHeap(Process* proc, common::uint32_t newEndAddr); 68 | static Process* ProcessById(int id); 69 | }; 70 | } 71 | } 72 | 73 | #endif -------------------------------------------------------------------------------- /kernel/include/system/tasking/scheduler.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__TASKING__SCHEDULER_H 2 | #define __CACTUSOS__SYSTEM__TASKING__SCHEDULER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CactusOS 9 | { 10 | namespace system 11 | { 12 | #define SCHEDULER_FREQUENCY 30 13 | 14 | class Scheduler : public InterruptHandler 15 | { 16 | private: 17 | common::uint32_t frequency = 0; 18 | common::uint32_t tickCount = 0; 19 | 20 | List threadsList; 21 | Thread* currentThread = 0; 22 | 23 | Thread* GetNextReadyThread(); 24 | void ProcessSleepingThreads(); 25 | 26 | bool switchForced = false; //Is the current switch forced by a forceSwitch() call? 27 | public: 28 | bool Enabled = true; 29 | Scheduler(); 30 | 31 | common::uint32_t HandleInterrupt(common::uint32_t esp); 32 | 33 | void AddThread(Thread* thread, bool forceSwitch = false); 34 | void ForceSwitch(); 35 | 36 | Thread* CurrentThread(); 37 | Process* CurrentProcess(); 38 | 39 | void InitialThreadUserJump(Thread* thread); 40 | 41 | //Blocking and unblocking 42 | void Block(Thread* thread, BlockedState reason = BlockedState::Unkown); 43 | void Unblock(Thread* thread, bool forceSwitch = false); 44 | }; 45 | } 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /kernel/include/system/tasking/thread.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTOSOS__SYSTEM__TASKING__THREAD_H 2 | #define __CACTOSOS__SYSTEM__TASKING__THREAD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace CactusOS 10 | { 11 | namespace system 12 | { 13 | #define THREAD_STACK_SIZE 4_KB 14 | 15 | #define SEG_USER_DATA 0x23 16 | #define SEG_USER_CODE 0x1B 17 | #define SEG_KERNEL_DATA 0x10 18 | #define SEG_KERNEL_CODE 8 19 | 20 | enum ThreadState 21 | { 22 | Blocked, 23 | Ready, 24 | Stopped, 25 | Started 26 | }; 27 | 28 | enum BlockedState 29 | { 30 | Unkown, 31 | SleepMS, 32 | ReceiveIPC 33 | }; 34 | 35 | struct Process; 36 | 37 | struct Thread 38 | { 39 | Process* parent; 40 | common::uint8_t* stack; 41 | common::uint8_t* userStack; 42 | common::uint32_t userStackSize; 43 | ThreadState state; 44 | BlockedState blockedState; 45 | core::CPUState* regsPtr; 46 | 47 | common::uint32_t timeDelta; 48 | common::uint8_t* FPUBuffer; 49 | }; 50 | 51 | class ThreadHelper 52 | { 53 | private: 54 | ThreadHelper(); 55 | public: 56 | static Thread* CreateFromFunction(void (*entryPoint)(), bool isKernel = false, common::uint32_t flags = 0x202, Process* parent = 0); 57 | static void RemoveThread(Thread* thread); 58 | }; 59 | } 60 | } 61 | 62 | #endif -------------------------------------------------------------------------------- /kernel/include/system/usb/usbendpoint.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__USB__USBENDPOINT_H 2 | #define __CACTUSOS__SYSTEM__USB__USBENDPOINT_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | enum EndpointDirection : int 11 | { 12 | Out, 13 | In 14 | }; 15 | 16 | enum EndpointType : int 17 | { 18 | Control, 19 | Isochronous, 20 | Bulk, 21 | Interrupt 22 | }; 23 | 24 | // An easy interface for managing endpoints 25 | class USBEndpoint 26 | { 27 | private: 28 | bool toggleState = false; 29 | public: 30 | common::uint8_t endpointNumber = 0; // Index of endpoint in device 31 | EndpointDirection dir = EndpointDirection::Out; // Direction of transfer for this endpoint 32 | EndpointType type = EndpointType::Control; // Type of endpoint 33 | common::uint16_t maxPacketSize = 0; // Max size a packet can be for this endpoint 34 | common::uint8_t interval = 0; // Interval for interrupt packets 35 | public: 36 | // Create new USB Endpoint from ENDPOINT_DESC gathered from configuration descriptor 37 | USBEndpoint(struct ENDPOINT_DESC* src); 38 | 39 | // Get toggle bit and toggle it for next packet 40 | bool Toggle(); 41 | 42 | // Set Toggle bit 43 | void SetToggle(bool v); 44 | }; 45 | } 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /kernel/include/system/usb/usbmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__USB__USBMANAGER_H 2 | #define __CACTUSOS__SYSTEM__USB__USBMANAGER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace CactusOS 8 | { 9 | namespace system 10 | { 11 | class USBManager 12 | { 13 | public: 14 | // The list of all usb controllers present on this pc. (the ones detected by pci) 15 | List controllerList; 16 | // List of all known USBDevices 17 | List deviceList; 18 | // Holds if usb devices present on boot are all initialized 19 | bool initDone = false; 20 | public: 21 | //Create new instance of USBManager 22 | USBManager(); 23 | 24 | //Add controller to list, called by HC drivers. 25 | void AddController(USBController* c); 26 | //Remove controller from list 27 | void RemoveController(USBController* c); 28 | //Add device to list, called by HC drivers. 29 | void AddDevice(USBDevice* c); 30 | //Remove device, called after device unplug 31 | void RemoveDevice(USBController* controller, uint8_t port); 32 | //Send the setup command to all the controllers 33 | void SetupAll(); 34 | //Make all usb devices detect their properties and automaticly select a driver 35 | void AssignAllDrivers(); 36 | //Check for changes in usb status 37 | void USBPoll(); 38 | }; 39 | } 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /kernel/include/system/vfs/vfsmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__VFS__VFSMANAGER_H 2 | #define __CACTUSOS__SYSTEM__VFS__VFSMANAGER_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | class VFSManager 11 | { 12 | public: 13 | List* Filesystems; 14 | public: 15 | int bootPartitionID = -1; 16 | 17 | VFSManager(); 18 | void Mount(VirtualFileSystem* vfs); 19 | void Unmount(VirtualFileSystem* vfs); 20 | void UnmountByDisk(Disk* disk); 21 | 22 | int ExtractDiskNumber(const char* path, common::uint8_t* idSizeReturn); 23 | bool SearchBootPartition(); 24 | 25 | ///////////// 26 | // Filesystem functions 27 | ///////////// 28 | 29 | // Read file contents into buffer 30 | int ReadFile(const char* filename, uint8_t* buffer, uint32_t offset = 0, uint32_t len = -1); 31 | // Write buffer to file, file will be created when create equals true 32 | int WriteFile(const char* filename, uint8_t* buffer, uint32_t len, bool create = true); 33 | 34 | // Check if file exist 35 | bool FileExists(const char* filename); 36 | // Check if directory exist 37 | bool DirectoryExists(const char* filename); 38 | 39 | // Create a file at the filepath 40 | int CreateFile(const char* path); 41 | // Create a new directory 42 | int CreateDirectory(const char* path); 43 | 44 | // Get size of specified file in bytes 45 | uint32_t GetFileSize(const char* filename); 46 | // Returns list of context inside a directory 47 | List* DirectoryList(const char* path); 48 | 49 | /////////////////// 50 | // Higher Level Functions 51 | /////////////////// 52 | 53 | // Eject the drive given by a path 54 | bool EjectDrive(const char* path); 55 | }; 56 | } 57 | } 58 | 59 | #endif -------------------------------------------------------------------------------- /kernel/include/system/virtual8086/VM86Args.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__VIRTUAL_8086__VM86ARGS_H 2 | #define __CACTUSOS__SYSTEM__VIRTUAL_8086__VM86ARGS_H 3 | 4 | #include 5 | 6 | namespace CactusOS 7 | { 8 | namespace system 9 | { 10 | struct VM86Arguments 11 | { 12 | common::uint16_t AX; 13 | common::uint16_t BX; 14 | common::uint16_t CX; 15 | common::uint16_t DX; 16 | 17 | common::uint16_t DI; 18 | } __attribute__((packed)); 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /kernel/include/system/virtual8086/VM86Manager.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__VIRTUAL_8086__VM86MANAGER_H 2 | #define __CACTUSOS__SYSTEM__VIRTUAL_8086__VM86MANAGER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace CactusOS 11 | { 12 | namespace system 13 | { 14 | class Virtual8086Manager : public InterruptHandler 15 | { 16 | private: 17 | void vm86Enter(common::uint16_t ss, common::uint16_t sp, common::uint16_t cs, common::uint16_t ip, common::uint32_t arg); 18 | public: 19 | Virtual8086Manager(); 20 | common::uint32_t HandleInterrupt(common::uint32_t esp); 21 | 22 | // Call a bios interrupt while passing multiple arguments via the regs variable 23 | void CallInterrupt(common::uint8_t intNumber, VM86Arguments* regs); 24 | 25 | // Execute a specific function defined in VM8086Code.asm 26 | // Sometimes things can't be done using the CallInterrupt function 27 | void ExecuteCode(common::uint32_t instructionStart, common::uint32_t args); 28 | }; 29 | } 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /kernel/include/system/virtual8086/VM86Monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOS__SYSTEM__VIRTUAL_8086__VM86MONITOR_H 2 | #define __CACTUSOS__SYSTEM__VIRTUAL_8086__VM86MONITOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace CactusOS 10 | { 11 | namespace system 12 | { 13 | class Virtual8086Monitor : public InterruptHandler 14 | { 15 | public: 16 | Virtual8086Monitor(); 17 | 18 | common::uint32_t HandleInterrupt(common::uint32_t esp); 19 | }; 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /kernel/linker.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT(elf32-i386) 2 | OUTPUT_ARCH(i386:i386) 3 | 4 | ENTRY(_entrypoint) 5 | 6 | SECTIONS 7 | { 8 | . = 0xC0100000; 9 | 10 | _kernel_base = .; 11 | 12 | .text ALIGN(4K) : AT(ADDR(.text)-0xC0000000) 13 | { 14 | *(.multiboot) 15 | *(.text*) 16 | } 17 | 18 | .rodata ALIGN (4K) : AT(ADDR(.rodata)-0xC0000000) 19 | { 20 | *(.rodata) 21 | } 22 | 23 | .bss ALIGN(4K) : AT(ADDR(.bss)-0xC0000000) 24 | { 25 | *(.COMMON) 26 | *(.bss) 27 | *(.bootstrap_stack) 28 | } 29 | 30 | .data ALIGN(4K) : AT(ADDR(.data)-0xC0000000) 31 | { 32 | start_ctors = .; 33 | KEEP(*( .init_array )); 34 | KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* ))); 35 | end_ctors = .; 36 | 37 | *(.data*) 38 | } 39 | 40 | /DISCARD/ : { *(.fini_array*) *(.comment) } 41 | 42 | _kernel_end = .; 43 | } -------------------------------------------------------------------------------- /kernel/src/boot/loader.s: -------------------------------------------------------------------------------- 1 | .set ALIGN, 1<<0 # align loaded modules on page boundaries 2 | .set MEMINFO, 1<<1 # provide memory map 3 | .set FLAGS, ALIGN | MEMINFO # this is the Multiboot 'flag' field 4 | .set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header 5 | .set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot 6 | 7 | .section .multiboot 8 | .align 4 9 | .long MAGIC 10 | .long FLAGS 11 | .long CHECKSUM 12 | 13 | .set KERNEL_VIRTUAL_BASE, 0xC0000000 14 | .set KERNEL_PAGE_NUMBER, (KERNEL_VIRTUAL_BASE >> 22) 15 | 16 | .section .bootstrap_stack, "aw", @nobits 17 | stack_bottom: 18 | .skip 16384 # 16 KiB 19 | .global stack_top 20 | stack_top: 21 | 22 | .section .data 23 | .align 0x1000 24 | .global BootPageDirectory 25 | BootPageDirectory: 26 | # identity map the first 4 MB 27 | .long 0x00000083 28 | 29 | # pages before kernel 30 | .rept (KERNEL_PAGE_NUMBER - 1) 31 | .long 0 32 | .endr 33 | 34 | # this page contains the kernel 35 | .long 0x00000083 36 | 37 | # pages after kernel 38 | .rept (1024 - KERNEL_PAGE_NUMBER - 1) 39 | .long 0 40 | .endr 41 | 42 | .global _kernel_virtual_base 43 | _kernel_virtual_base: 44 | .long KERNEL_VIRTUAL_BASE 45 | 46 | .section .text 47 | .align 4 48 | .global _entrypoint 49 | .type _entrypoint, @function 50 | 51 | _entrypoint: 52 | mov $(BootPageDirectory - KERNEL_VIRTUAL_BASE), %ecx 53 | mov %ecx, %cr3 54 | 55 | # enable 4 mb pages 56 | mov %cr4, %ecx 57 | or $0x00000010, %ecx 58 | mov %ecx, %cr4 59 | 60 | # enable paging 61 | mov %cr0, %ecx 62 | or $0x80000001, %ecx 63 | mov %ecx, %cr0 64 | 65 | # jump to higher half code 66 | lea 4f, %ecx 67 | jmp *%ecx 68 | 69 | 4: 70 | # Unmap the identity-mapped pages 71 | movl $0, BootPageDirectory 72 | invlpg 0 73 | 74 | movl $stack_top, %esp 75 | # Mark end of call stack for unwinding 76 | movl $0, %ebp 77 | 78 | add $KERNEL_VIRTUAL_BASE, %ebx 79 | 80 | call callConstructors 81 | 82 | push $_kernel_base 83 | push $_kernel_end 84 | push %eax 85 | push %ebx 86 | call kernelMain 87 | 88 | _stop: 89 | cli 90 | hlt 91 | jmp _stop 92 | -------------------------------------------------------------------------------- /kernel/src/common/memoryoperations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS::common; 4 | 5 | void* MemoryOperations::memmove(void* dstptr, const void* srcptr, uint32_t size) 6 | { 7 | unsigned char* dst = (unsigned char*) dstptr; 8 | const unsigned char* src = (const unsigned char*) srcptr; 9 | if (dst < src) { 10 | for (uint32_t i = 0; i < size; i++) 11 | dst[i] = src[i]; 12 | } else { 13 | for (uint32_t i = size; i != 0; i--) 14 | dst[i-1] = src[i-1]; 15 | } 16 | return dstptr; 17 | } 18 | int MemoryOperations::memcmp(const void* aptr, const void* bptr, uint32_t size) 19 | { 20 | const unsigned char* a = (const unsigned char*) aptr; 21 | const unsigned char* b = (const unsigned char*) bptr; 22 | for (uint32_t i = 0; i < size; i++) { 23 | if (a[i] < b[i]) 24 | return -1; 25 | else if (b[i] < a[i]) 26 | return 1; 27 | } 28 | return 0; 29 | } 30 | void* MemoryOperations::memset(void* bufptr, char value, uint32_t size) 31 | { 32 | unsigned char* buf = (unsigned char*) bufptr; 33 | for (uint32_t i = 0; i < size; i++) 34 | buf[i] = (unsigned char) value; 35 | return bufptr; 36 | } 37 | void* MemoryOperations::memcpy(void* dstptr, const void* srcptr, uint32_t size) 38 | { 39 | unsigned char* dst = (unsigned char*) dstptr; 40 | const unsigned char* src = (const unsigned char*) srcptr; 41 | for (uint32_t i = 0; i < size; i++) 42 | dst[i] = src[i]; 43 | return dstptr; 44 | } -------------------------------------------------------------------------------- /kernel/src/common/print.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS; 4 | using namespace CactusOS::system; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::core; 7 | 8 | void Print::printfHex(uint8_t key) 9 | { 10 | char *foo = "00"; 11 | char *hex = "0123456789ABCDEF"; 12 | foo[0] = hex[(key >> 4) & 0xF]; 13 | foo[1] = hex[key & 0xF]; 14 | system::BootConsole::Write(foo); 15 | } 16 | void Print::printfHex16(uint16_t key) 17 | { 18 | printfHex((key >> 8) & 0xFF); 19 | printfHex(key & 0xFF); 20 | } 21 | void Print::printfHex32(uint32_t key) 22 | { 23 | printfHex((key >> 24) & 0xFF); 24 | printfHex((key >> 16) & 0xFF); 25 | printfHex((key >> 8) & 0xFF); 26 | printfHex(key & 0xFF); 27 | } 28 | void Print::printbits(uint8_t key) 29 | { 30 | for (unsigned int bit = 0; bit < (sizeof(key)*8); bit++) 31 | { 32 | BootConsole::Write(Convert::IntToString(key & 0x01)); 33 | key = key >> 1; 34 | } 35 | } 36 | void Print::printbits(uint16_t key) 37 | { 38 | for (unsigned int bit = 0; bit < (sizeof(key)*8); bit++) 39 | { 40 | BootConsole::Write(Convert::IntToString(key & 0x01)); 41 | key = key >> 1; 42 | } 43 | } 44 | void Print::printbits(uint32_t key) 45 | { 46 | for (unsigned int bit = 0; bit < (sizeof(key)*8); bit++) 47 | { 48 | BootConsole::Write(Convert::IntToString(key & 0x01)); 49 | key = key >> 1; 50 | } 51 | } 52 | void Print::printbits(uint64_t key) 53 | { 54 | for (unsigned int bit = 0; bit < (sizeof(key)*8); bit++) 55 | { 56 | BootConsole::Write(Convert::IntToString(key & 0x01)); 57 | key = key >> 1; 58 | } 59 | } -------------------------------------------------------------------------------- /kernel/src/common/random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS::common; 4 | 5 | uint32_t Random::next; 6 | 7 | int Random::Next(uint32_t max) 8 | { 9 | next = next * 1103515245 + 12345; 10 | return (unsigned int)(next / 65536) % (max+1); 11 | } 12 | 13 | int Random::Next(uint32_t min, uint32_t max) 14 | { 15 | return Next(max-min) + min; 16 | } 17 | 18 | void Random::SetSeed(uint32_t seed) 19 | { 20 | next = seed; 21 | } -------------------------------------------------------------------------------- /kernel/src/core/cpu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::core; 6 | using namespace CactusOS::common; 7 | using namespace CactusOS::system; 8 | 9 | extern "C" void EnableSSE(); 10 | 11 | static inline void cpuid(uint32_t reg, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) 12 | { 13 | asm volatile("cpuid" 14 | : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) 15 | : "0" (reg)); 16 | } 17 | 18 | void CPU::PrintVendor() 19 | { 20 | uint32_t largestStandardFunc; 21 | char vendor[13]; 22 | cpuid(0, &largestStandardFunc, (uint32_t*)(vendor + 0), (uint32_t *)(vendor + 8), (uint32_t *)(vendor + 4)); 23 | vendor[12] = '\0'; 24 | 25 | BootConsole::Write("CPU Vendor: "); BootConsole::WriteLine(vendor); 26 | } 27 | 28 | void CPU::EnableFeatures() 29 | { 30 | uint32_t eax, ebx, ecx, edx; 31 | 32 | cpuid(0x01, &eax, &ebx, &ecx, &edx); 33 | 34 | if (edx & EDX_SSE2) { 35 | BootConsole::WriteLine("CPU Has SSE2"); 36 | 37 | EnableSSE(); 38 | } 39 | else 40 | { 41 | BootConsole::WriteLine("Error: CPU has no SSE2. This is needed"); 42 | 43 | while(1); 44 | } 45 | 46 | if(edx & EDX_FXSR) { 47 | BootConsole::WriteLine("CPU Has FXSR"); 48 | } 49 | else 50 | { 51 | BootConsole::WriteLine("Error: CPU has no FXSR. This is needed"); 52 | 53 | while(1); 54 | } 55 | } -------------------------------------------------------------------------------- /kernel/src/core/cpuhelper.asm: -------------------------------------------------------------------------------- 1 | GLOBAL EnableSSE 2 | EnableSSE: 3 | mov eax, cr0 4 | and ax, 0xFFFB ;clear coprocessor emulation CR0.EM 5 | or ax, 0x2 ;set coprocessor monitoring CR0.MP 6 | mov cr0, eax 7 | mov eax, cr4 8 | or ax, 3 << 9 ;set CR4.OSFXSR and CR4.OSXMMEXCPT at the same time 9 | mov cr4, eax 10 | ret -------------------------------------------------------------------------------- /kernel/src/core/fpu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::core; 7 | 8 | void FPU::Enable() 9 | { 10 | uint32_t cr4; 11 | asm volatile ("mov %%cr4, %0" : "=r"(cr4)); 12 | cr4 |= 0x200; 13 | asm volatile ("mov %0, %%cr4" :: "r"(cr4)); 14 | 15 | //////////// 16 | // Set Control Word 17 | //////////// 18 | FPUControlWord cw; 19 | MemoryOperations::memset(&cw, 0, sizeof(FPUControlWord)); 20 | 21 | cw.InvalidOperand = 1; 22 | cw.DenormalOperand = 1; 23 | cw.ZeroDevide = 1; 24 | cw.Overflow = 1; 25 | cw.Underflow = 1; 26 | cw.Precision = 1; 27 | 28 | cw.PrecisionControl = 0b11; 29 | cw.RoundingControl = 0b00; 30 | cw.InfinityControl = 0; 31 | 32 | asm volatile("fldcw %0" :: "m"(cw)); 33 | } -------------------------------------------------------------------------------- /kernel/src/core/gdt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS::common; 4 | using namespace CactusOS::core; 5 | 6 | /*///////////////// 7 | // Variables 8 | /*///////////////// 9 | GDTEntry gdtEntries[6]; 10 | GDTPointer gdtPointer; 11 | 12 | extern "C" void gdt_flush(uint32_t); 13 | 14 | /*///////////////// 15 | // Public functions 16 | /*///////////////// 17 | void GlobalDescriptorTable::SetDescriptor(int number, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) 18 | { 19 | gdtEntries[number].base_low = (base & 0xFFFF); 20 | gdtEntries[number].base_middle = (base >> 16) & 0xFF; 21 | gdtEntries[number].base_high = (base >> 24) & 0xFF; 22 | 23 | gdtEntries[number].limit_low = (limit & 0xFFFF); 24 | gdtEntries[number].granularity = (limit >> 16) & 0x0F; 25 | 26 | gdtEntries[number].granularity |= gran & 0xF0; 27 | gdtEntries[number].access = access; 28 | } 29 | 30 | GDTEntry* GlobalDescriptorTable::GetDescriptor(int number) 31 | { 32 | return &gdtEntries[number]; 33 | } 34 | 35 | void GlobalDescriptorTable::Init() 36 | { 37 | gdtPointer.limit = (sizeof(GDTEntry) * 6) - 1; 38 | gdtPointer.base = (uint32_t)&gdtEntries; 39 | 40 | SetDescriptor(0, 0, 0, 0, 0); // Null segment 41 | SetDescriptor(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment 42 | SetDescriptor(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment 43 | SetDescriptor(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment 44 | SetDescriptor(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment 45 | // TSS descriptor will be loaded by the TSS class 46 | 47 | gdt_flush((uint32_t)&gdtPointer); 48 | } -------------------------------------------------------------------------------- /kernel/src/core/gdthelper.asm: -------------------------------------------------------------------------------- 1 | [GLOBAL gdt_flush] ; Allows the C code to call gdt_flush(). 2 | 3 | gdt_flush: 4 | mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter. 5 | lgdt [eax] ; Load the new GDT pointer 6 | 7 | mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment 8 | mov ds, ax ; Load all data segment selectors 9 | mov es, ax 10 | mov fs, ax 11 | mov gs, ax 12 | mov ss, ax 13 | jmp 0x08:.flush ; 0x08 is the offset to our code segment: Far jump! 14 | .flush: 15 | ret -------------------------------------------------------------------------------- /kernel/src/core/tss.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS; 4 | using namespace CactusOS::common; 5 | using namespace CactusOS::core; 6 | 7 | static TSSEntry tss; 8 | 9 | extern "C" void flush_tss(); 10 | 11 | void TSS::Install(uint32_t idx, uint32_t kernelSS, uint32_t kernelESP) 12 | { 13 | MemoryOperations::memset(&tss, 0, sizeof(TSSEntry)); 14 | 15 | //! install TSS descriptor 16 | uint32_t base = (uint32_t) &tss; 17 | 18 | //! install descriptor 19 | GlobalDescriptorTable::SetDescriptor (idx, base, base + sizeof (TSSEntry), 0xE9, 0); 20 | 21 | //! initialize TSS 22 | MemoryOperations::memset ((void*) &tss, 0, sizeof (TSSEntry)); 23 | 24 | //! set stack and segments 25 | tss.ss0 = kernelSS; 26 | tss.esp0 = kernelESP; 27 | tss.iomap = sizeof(TSSEntry); 28 | 29 | //! flush tss 30 | flush_tss(); 31 | } 32 | 33 | void TSS::SetStack(uint32_t kernelSS, uint32_t kernelESP) 34 | { 35 | tss.ss0 = kernelSS; 36 | tss.esp0 = kernelESP; 37 | } 38 | 39 | TSSEntry* TSS::GetCurrent() 40 | { 41 | return &tss; 42 | } -------------------------------------------------------------------------------- /kernel/src/core/tsshelper.asm: -------------------------------------------------------------------------------- 1 | global flush_tss 2 | flush_tss: 3 | mov ax, 0x28 4 | ltr ax 5 | ret -------------------------------------------------------------------------------- /kernel/src/installer/textgui.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace CactusOS; 6 | using namespace CactusOS::common; 7 | using namespace CactusOS::system; 8 | using namespace CactusOS::core; 9 | 10 | volatile uint16_t* videoMemory = (uint16_t*)0xC00B8000; 11 | 12 | void TextGUI::DisableCursor() 13 | { 14 | outportb(0x3D4, 0x0A); 15 | outportb(0x3D5, 0x20); 16 | } 17 | void TextGUI::SetPixel(int x, int y, char color, uint16_t character, char background) 18 | { 19 | uint16_t attrib = (background << 4) | (color & 0x0F); 20 | *(videoMemory + (y * VGA_WIDTH + x)) = character | (attrib << 8); 21 | } 22 | void TextGUI::ClearScreen(char color) 23 | { 24 | for(int y = 0; y < VGA_HEIGHT; y++) 25 | for(int x = 0; x < VGA_WIDTH; x++) 26 | SetPixel(x, y, color, ' '); 27 | } 28 | void TextGUI::StatusBar(char* text, int percentage) 29 | { 30 | for(int x = 0; x < VGA_WIDTH; x++) 31 | SetPixel(x, VGA_HEIGHT - 1, TEXT_COLOR, ' ', VGA_COLOR_LIGHT_GREY); 32 | 33 | DrawString(text, 0, VGA_HEIGHT - 1, TEXT_COLOR, VGA_COLOR_LIGHT_GREY); 34 | 35 | const int barWidth = 20; //Amount of characters for status bar 36 | const int startX = VGA_WIDTH - barWidth - 1; //Start of progress bar 37 | int width = ((double)percentage / 100.0) * (double)barWidth; 38 | 39 | SetPixel(startX, VGA_HEIGHT - 1, VGA_COLOR_BLACK, '[', VGA_COLOR_LIGHT_GREY); 40 | for(int i = 0; i < width; i++) 41 | SetPixel(startX + i + 1, VGA_HEIGHT - 1, VGA_COLOR_BLACK, '#', VGA_COLOR_LIGHT_GREY); 42 | 43 | SetPixel(startX + barWidth, VGA_HEIGHT - 1, VGA_COLOR_BLACK, ']', VGA_COLOR_LIGHT_GREY); 44 | } 45 | void TextGUI::DrawString(char* text, int x, int y, char color, char background) 46 | { 47 | int px = x; 48 | int py = y; 49 | for(int i = 0; text[i] != '\0'; ++i) { 50 | switch(text[i]) { 51 | case '\n': 52 | px = x; 53 | py += 1; 54 | break; 55 | default: 56 | SetPixel(px, py, color, text[i], background); 57 | px++; 58 | break; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /kernel/src/system/components/bochsvbe.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | https://wiki.osdev.org/Bochs_VBE_Extensions 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | using namespace CactusOS; 9 | using namespace CactusOS::common; 10 | using namespace CactusOS::system; 11 | using namespace CactusOS::core; 12 | 13 | BochsVBE::BochsVBE() 14 | : GraphicsDevice("Bochs VBE Adapter"), 15 | SystemComponent("BOCHS VBE", "Bochs VBE Extensions") 16 | { } 17 | 18 | void WriteRegister(uint16_t IndexValue, uint16_t DataValue) 19 | { 20 | outportw(VBE_DISPI_IOPORT_INDEX, IndexValue); 21 | outportw(VBE_DISPI_IOPORT_DATA, DataValue); 22 | } 23 | 24 | uint16_t ReadRegister(uint16_t IndexValue) 25 | { 26 | outportw(VBE_DISPI_IOPORT_INDEX, IndexValue); 27 | return inportw(VBE_DISPI_IOPORT_DATA); 28 | } 29 | 30 | bool BochsVBE::IsAvailable() 31 | { 32 | uint16_t id = ReadRegister(VBE_DISPI_INDEX_ID); 33 | return (id >= VBE_DISPI_ID0 && id <= VBE_DISPI_ID5); 34 | } 35 | 36 | void SetVideoMode(uint32_t Width, uint32_t Height, uint32_t BitDepth, int UseLinearFrameBuffer, int ClearVideoMemory) 37 | { 38 | WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED); 39 | WriteRegister(VBE_DISPI_INDEX_XRES, Width); 40 | WriteRegister(VBE_DISPI_INDEX_YRES, Height); 41 | WriteRegister(VBE_DISPI_INDEX_BPP, BitDepth); 42 | WriteRegister(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | 43 | (UseLinearFrameBuffer ? VBE_DISPI_LFB_ENABLED : 0) | 44 | (ClearVideoMemory ? 0 : VBE_DISPI_NOCLEARMEM)); 45 | } 46 | 47 | bool BochsVBE::SelectBestVideoMode() 48 | { 49 | if(!IsAvailable()) 50 | return false; 51 | 52 | SetVideoMode(VBE_DISPI_MAX_XRES, VBE_DISPI_MAX_YRES, 32, true, true); 53 | 54 | this->width = VBE_DISPI_MAX_XRES; 55 | this->height = VBE_DISPI_MAX_YRES; 56 | this->bpp = 32; 57 | this->framebufferPhys = VBE_DISPI_LFB_PHYSICAL_ADDRESS; 58 | 59 | return true; 60 | } -------------------------------------------------------------------------------- /kernel/src/system/components/graphicsdevice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace CactusOS; 7 | using namespace CactusOS::common; 8 | using namespace CactusOS::system; 9 | 10 | GraphicsDevice::GraphicsDevice(char* name) 11 | { 12 | this->width = 0; 13 | this->height = 0; 14 | this->bpp = 0; 15 | this->identifier = name; 16 | } 17 | 18 | GraphicsDevice::~GraphicsDevice() 19 | { 20 | 21 | } 22 | 23 | bool GraphicsDevice::SelectBestVideoMode() 24 | { 25 | return false; 26 | } 27 | 28 | uint32_t GraphicsDevice::GetBufferSize() 29 | { 30 | return this->width * this->height * (this->bpp/8); 31 | } 32 | 33 | //Select the best graphics device for the situation 34 | GraphicsDevice* GraphicsDevice::GetBestDevice() 35 | { 36 | #if BOCHS_GFX_HACK 37 | if(BochsVBE::IsAvailable() && System::isBochs) 38 | { 39 | //BootConsole::Write(" BochsVBE"); 40 | return new BochsVBE(); 41 | } 42 | #endif 43 | 44 | //BootConsole::Write(" VESA"); 45 | return new VESA(System::vm86Manager); 46 | } -------------------------------------------------------------------------------- /kernel/src/system/components/pit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::core; 7 | using namespace CactusOS::system; 8 | 9 | PIT::PIT() 10 | : SystemComponent("PIT", "Legacy Programmable Interval Timer"), 11 | InterruptHandler(IDT_INTERRUPT_OFFSET + 0) 12 | { 13 | timer_ticks = 0; 14 | 15 | uint64_t divisor = 1193180 / PIT_FREQUENCY; //Default is 1000 Hz 16 | 17 | outportb(0x43, 0x34); 18 | outportb(0x40, (uint8_t)divisor); 19 | outportb(0x40, (uint8_t)(divisor >> 8)); 20 | } 21 | 22 | uint32_t PIT::HandleInterrupt(uint32_t esp) 23 | { 24 | timer_ticks++; 25 | 26 | return esp; 27 | } 28 | void PIT::Sleep(uint32_t ms) 29 | { 30 | uint64_t targetTicks = timer_ticks + ms; 31 | while(timer_ticks < targetTicks) 32 | asm ("hlt"); // Wait for next interrupt 33 | } 34 | 35 | 36 | void PIT::PlaySound(common::uint32_t nFrequence) 37 | { 38 | uint32_t Div; 39 | uint8_t tmp; 40 | 41 | //Set the PIT to the desired frequency 42 | Div = 1193180 / nFrequence; 43 | outportb(0x43, 0xb6); 44 | outportb(0x42, (uint8_t) (Div) ); 45 | outportb(0x42, (uint8_t) (Div >> 8)); 46 | 47 | //And play the sound using the PC speaker 48 | tmp = inportb(0x61); 49 | if (tmp != (tmp | 3)) { 50 | outportb(0x61, tmp | 3); 51 | } 52 | } 53 | void PIT::NoSound() 54 | { 55 | uint8_t tmp = inportb(0x61) & 0xFC; 56 | 57 | outportb(0x61, tmp); 58 | } 59 | void PIT::Beep() 60 | { 61 | Beep(800); //800 is default beep frequency 62 | } 63 | 64 | void PIT::Beep(common::uint32_t freq) 65 | { 66 | Beep(freq, 200); //200 is default beep duration 67 | } 68 | void PIT::Beep(common::uint32_t freq, common::uint32_t duration) 69 | { 70 | if(duration == 0) 71 | return; 72 | if(freq == 0) 73 | return; 74 | 75 | PlaySound(freq); 76 | Sleep(duration); 77 | NoSound(); 78 | } 79 | 80 | uint64_t PIT::Ticks() 81 | { 82 | return this->timer_ticks; 83 | } -------------------------------------------------------------------------------- /kernel/src/system/components/systemcomponents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS; 4 | using namespace CactusOS::common; 5 | using namespace CactusOS::system; 6 | 7 | SystemComponent::SystemComponent(char* name, char* description) 8 | { 9 | this->Name = name; 10 | this->Description = description; 11 | } 12 | 13 | char* SystemComponent::GetComponentName() 14 | { 15 | return this->Name; 16 | } 17 | char* SystemComponent::GetComponentDescription() 18 | { 19 | return this->Description; 20 | } -------------------------------------------------------------------------------- /kernel/src/system/disks/disk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::system; 7 | 8 | Disk::Disk(uint32_t controllerIndex, DiskController* controller, DiskType type, uint64_t size, uint32_t blocks, uint32_t blocksize) 9 | { 10 | this->controllerIndex = controllerIndex; 11 | this->controller = controller; 12 | this->type = type; 13 | this->size = size; 14 | this->blockSize = blocksize; 15 | this->numBlocks = blocks; 16 | } 17 | char Disk::ReadSector(uint32_t lba, uint8_t* buf) 18 | { 19 | #if ENABLE_ADV_DEBUG 20 | System::statistics.diskReadOp += 1; 21 | #endif 22 | 23 | if(this->controller != 0) 24 | return this->controller->ReadSector(this->controllerIndex, lba, buf); 25 | return 1; 26 | } 27 | char Disk::WriteSector(uint32_t lba, uint8_t* buf) 28 | { 29 | #if ENABLE_ADV_DEBUG 30 | System::statistics.diskWriteOp += 1; 31 | #endif 32 | 33 | if(this->controller != 0) 34 | return this->controller->WriteSector(this->controllerIndex, lba, buf); 35 | return 1; 36 | } -------------------------------------------------------------------------------- /kernel/src/system/disks/diskcontroller.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS; 4 | using namespace CactusOS::common; 5 | using namespace CactusOS::system; 6 | 7 | DiskController::DiskController() 8 | { } 9 | char DiskController::ReadSector(uint16_t drive, uint32_t lba, uint8_t* buf) 10 | { return 1; } //Needs to be implemented by driver 11 | char DiskController::WriteSector(uint16_t drive, uint32_t lba, uint8_t* buf) 12 | { return 1; } //Needs to be implemented by driver 13 | bool DiskController::EjectDrive(uint8_t drive) 14 | { return false; } //Needs to be implemented by driver -------------------------------------------------------------------------------- /kernel/src/system/disks/diskmanager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | using namespace CactusOS; 7 | using namespace CactusOS::common; 8 | using namespace CactusOS::system; 9 | using namespace CactusOS::system::drivers; 10 | 11 | // VM86 Function to get info about a specific disk device 12 | // We must do it this way because the DS:SI gets used by the CallInterrupt() method 13 | extern "C" uint8_t diskInfo; 14 | 15 | DiskManager::DiskManager() 16 | { 17 | allDisks.Clear(); 18 | } 19 | 20 | char DiskManager::ReadSector(uint16_t drive, uint32_t lba, uint8_t* buf) 21 | { 22 | if(drive < allDisks.size()) 23 | return allDisks[drive]->ReadSector(lba, buf); 24 | return 1; 25 | } 26 | 27 | char DiskManager::WriteSector(uint16_t drive, uint32_t lba, uint8_t* buf) 28 | { 29 | if(drive < allDisks.size()) 30 | return allDisks[drive]->WriteSector(lba, buf); 31 | return 1; 32 | } 33 | 34 | void DiskManager::AddDisk(Disk* disk) 35 | { 36 | //Add Disk to list of all disk 37 | allDisks.push_back(disk); 38 | //Try to detect filesystems present on disk 39 | PartitionManager::DetectAndLoadFilesystem(disk); 40 | } 41 | void DiskManager::RemoveDisk(Disk* disk) 42 | { 43 | allDisks.Remove(disk); //Remove from list 44 | System::vfs->UnmountByDisk(disk); //And unmount all filesystems using that disk 45 | } 46 | 47 | BiosDriveParameters* DiskManager::GetDriveInfoBios(uint8_t drive) 48 | { 49 | System::vm86Manager->ExecuteCode((uint32_t)&diskInfo, drive); 50 | return (BiosDriveParameters*)0x7000; 51 | } -------------------------------------------------------------------------------- /kernel/src/system/drivers/driver.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::system; 6 | using namespace CactusOS::system::drivers; 7 | 8 | Driver::Driver(char* name, char* description) 9 | { 10 | this->Name = name; 11 | this->Description = description; 12 | } 13 | 14 | char* Driver::GetDriverName() { 15 | return this->Name; 16 | } 17 | char* Driver::GetDriverDescription() { 18 | return this->Description; 19 | } 20 | 21 | bool Driver::Initialize() 22 | { 23 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 24 | return false; 25 | } -------------------------------------------------------------------------------- /kernel/src/system/drivers/drivermanager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::system; 6 | using namespace CactusOS::system::drivers; 7 | 8 | DriverManager::DriverManager() 9 | { 10 | this->driverList.Clear(); 11 | } 12 | 13 | void DriverManager::AddDriver(Driver* drv) 14 | { 15 | this->driverList.push_back(drv); 16 | } 17 | 18 | void DriverManager::ActivateAll() 19 | { 20 | for(int i = 0; i < driverList.size(); i++) 21 | { 22 | Log(Info, "Activating driver %s", driverList[i]->GetDriverName()); 23 | 24 | if(driverList[i]->Initialize() == false) 25 | Log(Error, "driver initialize failed for driver -> %s ", driverList[i]->GetDriverName()); 26 | } 27 | } -------------------------------------------------------------------------------- /kernel/src/system/drivers/usb/usbdriver.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::core; 7 | using namespace CactusOS::system; 8 | using namespace CactusOS::system::drivers; 9 | 10 | USBDriver::USBDriver(USBDevice* dev, char* driverName) 11 | : Driver(driverName) 12 | { 13 | this->device = dev; 14 | } 15 | 16 | USBDriver::~USBDriver() 17 | { 18 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 19 | } 20 | 21 | void USBDriver::DeInitialize() 22 | { 23 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 24 | } 25 | 26 | bool USBDriver::HandleInterruptPacket(InterruptTransfer_t* transfer) 27 | { 28 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 29 | return false; 30 | } -------------------------------------------------------------------------------- /kernel/src/system/initrd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::system; 7 | 8 | void* locationInMemory = 0; 9 | 10 | void InitialRamDisk::Initialize(multiboot_info_t* mbi) 11 | { 12 | if(mbi->mods_count <= 0) 13 | { 14 | Log(Info, "Error mods count is 0 or less"); 15 | return; 16 | } 17 | 18 | uint32_t ramdiskLocation = *(uint32_t*)mbi->mods_addr; 19 | uint32_t ramdiskEnd = *(uint32_t*)(mbi->mods_addr + 4); 20 | 21 | Log(Info, "Ramdisk is at: %x", ramdiskLocation); 22 | Log(Info, "Ramdisk size: %d", ramdiskEnd - ramdiskLocation); 23 | 24 | locationInMemory = (void*)ramdiskLocation; 25 | } 26 | 27 | void* InitialRamDisk::ReadFile(const char* path, uint32_t* fileSizeReturn) 28 | { 29 | InitrdFileHeader* header = (InitrdFileHeader*)locationInMemory; 30 | while(header->size != 0) 31 | { 32 | if(String::strcmp(header->path, path)) 33 | { 34 | if(fileSizeReturn != 0) 35 | *fileSizeReturn = header->size; 36 | return (void*)((uint32_t)header + sizeof(InitrdFileHeader)); 37 | } 38 | 39 | header = (InitrdFileHeader*)((uint32_t)header + sizeof(InitrdFileHeader) + header->size); 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /kernel/src/system/input/keyboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::system; 7 | 8 | Keyboard::Keyboard(KeyboardType type) 9 | { 10 | this->type = type; 11 | MemoryOperations::memset(&this->status, 0, sizeof(this->status)); 12 | } 13 | 14 | void Keyboard::UpdateLEDS() 15 | { 16 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 17 | } 18 | 19 | bool Keyboard::ContainsKey(uint8_t key, uint8_t* packet, int* pos) 20 | { 21 | for(int i = 2; i < 8; i++) 22 | if(packet[i] == key) { *pos = i; return true; } 23 | return false; 24 | } -------------------------------------------------------------------------------- /kernel/src/system/interruptmanager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS; 4 | using namespace CactusOS::common; 5 | using namespace CactusOS::system; 6 | 7 | 8 | InterruptHandler::InterruptHandler(uint8_t interruptNumber) 9 | { 10 | InterruptManager::AddHandler(this, interruptNumber); 11 | } 12 | 13 | uint32_t InterruptHandler::HandleInterrupt(uint32_t esp) 14 | { 15 | return esp; 16 | } 17 | 18 | 19 | 20 | List* InterruptManager::interruptCallbacks[256]; //Allows for multiple interrupt handlers per interrupt 21 | 22 | void InterruptManager::Initialize() 23 | { 24 | for(int i = 0; i < 256; i++) 25 | { 26 | interruptCallbacks[i] = 0; 27 | } 28 | } 29 | 30 | uint32_t InterruptManager::HandleInterrupt(uint8_t num, uint32_t esp) 31 | { 32 | if(interruptCallbacks[num] == 0) //No list of callbacks present for specific interrupt 33 | return esp; 34 | 35 | if(interruptCallbacks[num]->size() == 0) //The list contains no handlers 36 | return esp; 37 | 38 | for(int i = 0; i < interruptCallbacks[num]->size(); i++) 39 | { 40 | InterruptHandler* handler = interruptCallbacks[num]->GetAt(i); 41 | esp = handler->HandleInterrupt(esp); 42 | } 43 | 44 | return esp; 45 | } 46 | 47 | void InterruptManager::AddHandler(InterruptHandler* handler, uint8_t interrupt) 48 | { 49 | if(interruptCallbacks[interrupt] == 0) 50 | interruptCallbacks[interrupt] = new List(); //Create new list 51 | 52 | interruptCallbacks[interrupt]->push_back(handler); 53 | } 54 | void InterruptManager::RemoveHandler(InterruptHandler* handler, uint8_t interrupt) 55 | { 56 | interruptCallbacks[interrupt]->Remove(handler); 57 | if(interruptCallbacks[interrupt]->size() == 0) { 58 | delete interruptCallbacks[interrupt]; 59 | interruptCallbacks[interrupt] = 0; 60 | } 61 | } -------------------------------------------------------------------------------- /kernel/src/system/listings/directorylisting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::core; 7 | using namespace CactusOS::system; 8 | 9 | // List which holds the files in the current requested directory. 10 | List* currentDirectoryList = 0; 11 | 12 | DirectoryListing::DirectoryListing() 13 | : ListingController() { } 14 | 15 | int DirectoryListing::BeginListing(Thread* thread, uint32_t pathPtr) 16 | { 17 | char* path = (char*)pathPtr; 18 | if(!System::vfs->DirectoryExists(path)) 19 | return -1; 20 | 21 | if(requestBusy) 22 | { 23 | waitingQueue.push_back(thread); 24 | System::scheduler->Block(thread); 25 | } 26 | 27 | requestBusy = true; 28 | currentReqThread = thread; 29 | 30 | currentDirectoryList = System::vfs->DirectoryList(path); 31 | return currentDirectoryList->size(); 32 | } 33 | int DirectoryListing::GetEntry(Thread* thread, int entry, uint32_t bufPtr) 34 | { 35 | char* buf = (char*)bufPtr; 36 | if(currentReqThread != thread) 37 | { 38 | Log(Error, "Thread requested entry while it was not the original requestor"); 39 | return 0; 40 | } 41 | 42 | if(entry >= 0 && currentDirectoryList->size() > entry && buf != 0) 43 | { 44 | LIBCactusOS::VFSEntry item = currentDirectoryList->GetAt(entry); 45 | MemoryOperations::memcpy(buf, &item, sizeof(LIBCactusOS::VFSEntry)); 46 | 47 | return 1; 48 | } 49 | 50 | // End of items 51 | return 0; 52 | } 53 | void DirectoryListing::EndListing(Thread* thread) 54 | { 55 | if(currentReqThread != thread || currentReqThread == 0) 56 | { 57 | Log(Error, "Thread requested listing end while it was not the original requestor"); 58 | return; 59 | } 60 | 61 | requestBusy = false; 62 | currentReqThread = 0; 63 | delete currentDirectoryList; 64 | 65 | if(waitingQueue.size() > 0) //Unblock first thread from queue. 66 | System::scheduler->Unblock(waitingQueue[0]); 67 | } -------------------------------------------------------------------------------- /kernel/src/system/listings/listingcontroller.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::core; 7 | using namespace CactusOS::system; 8 | 9 | ListingController::ListingController() 10 | : waitingQueue(), currentReqThread(), requestBusy(false) {} 11 | 12 | int ListingController::BeginListing(Thread* thread, uint32_t arg1) { 13 | Log(Error, "ListingController Class is used directly while it is virtual"); 14 | return 0; 15 | } 16 | int ListingController::GetEntry(Thread* thread, int entry, uint32_t bufPtr) { 17 | Log(Error, "ListingController Class is used directly while it is virtual"); 18 | return 0; 19 | } 20 | void ListingController::EndListing(Thread* thread) { 21 | Log(Error, "ListingController Class is used directly while it is virtual"); 22 | } -------------------------------------------------------------------------------- /kernel/src/system/memory/deviceheap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace CactusOS; 6 | using namespace CactusOS::common; 7 | using namespace CactusOS::core; 8 | using namespace CactusOS::system; 9 | 10 | uint32_t DeviceHeap::currentAddress = DEVICE_HEAP_START; 11 | 12 | uint32_t DeviceHeap::AllocateChunk(uint32_t size) 13 | { 14 | uint32_t ret = DeviceHeap::currentAddress; 15 | DeviceHeap::currentAddress += pageRoundUp(size); 16 | 17 | // Will propably never happen 18 | if(DeviceHeap::currentAddress >= DEVICE_HEAP_END) 19 | Log(Error, "Device heap is getting to big!"); 20 | 21 | return ret; 22 | } -------------------------------------------------------------------------------- /kernel/src/system/memory/fifostream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::system; 7 | 8 | FIFOStream::FIFOStream(int capacity) 9 | { 10 | this->buffer = new char[capacity * sizeof(char)]; 11 | this->buffer_end = (char*)this->buffer + capacity * sizeof(char); 12 | this->count = 0; 13 | this->capacity = capacity; 14 | this->head = this->buffer; 15 | this->tail = this->buffer; 16 | } 17 | 18 | FIFOStream::~FIFOStream() 19 | { 20 | delete this->buffer; 21 | } 22 | 23 | void FIFOStream::Write(char item) 24 | { 25 | if(this->count == this->capacity) { 26 | Log(Error, "Item count has reached capacity for this stream, data will be ignored. Capacity=%d", this->capacity); 27 | return; 28 | } 29 | 30 | MemoryOperations::memcpy((void*)this->head, (void*)&item, sizeof(char)); 31 | this->head = (char*)(this->head + sizeof(char)); 32 | if(this->head == this->buffer_end) 33 | this->head = this->buffer; 34 | 35 | this->count++; 36 | } 37 | 38 | char FIFOStream::Read() 39 | { 40 | char result = 0; 41 | if(this->count == 0) 42 | return result; 43 | 44 | MemoryOperations::memcpy((void*)&result, (void*)this->tail, sizeof(char)); 45 | this->tail = (char*)(this->tail + sizeof(char)); 46 | if(this->tail == this->buffer_end) 47 | this->tail = this->buffer; 48 | 49 | this->count--; 50 | return result; 51 | } 52 | 53 | int FIFOStream::Available() 54 | { 55 | return this->count; 56 | } -------------------------------------------------------------------------------- /kernel/src/system/memory/stream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::common; 6 | using namespace CactusOS::system; 7 | 8 | Stream::Stream() {} 9 | Stream::~Stream() {} 10 | 11 | char Stream::Read() 12 | { 13 | Log(Error, "Virtual stream function called"); 14 | return 0; 15 | } 16 | 17 | void Stream::Write(char byte) 18 | { 19 | Log(Error, "Virtual stream function called"); 20 | } 21 | 22 | int Stream::Available() 23 | { 24 | Log(Error, "Virtual stream function called"); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /kernel/src/system/serialport.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS; 4 | using namespace CactusOS::common; 5 | using namespace CactusOS::core; 6 | using namespace CactusOS::system; 7 | 8 | /*///////////////// 9 | // Static variable initialisations 10 | /*///////////////// 11 | COMPort Serialport::PortAddress = COMPort::COM1; 12 | bool Serialport::Initialized = false; 13 | 14 | /*///////////////// 15 | // Private functions 16 | /*///////////////// 17 | int Serialport::SerialReceiveReady() 18 | { 19 | return inportb(PortAddress + 5) & 1; 20 | } 21 | int Serialport::SerialSendReady() 22 | { 23 | return inportb(PortAddress + 5) & 0x20; 24 | } 25 | 26 | /*///////////////// 27 | // Public functions 28 | /*///////////////// 29 | char Serialport::Read() 30 | { 31 | while (SerialReceiveReady() == 0); 32 | 33 | return inportb(PortAddress); 34 | } 35 | void Serialport::Write(char a) 36 | { 37 | while (SerialSendReady() == 0); 38 | 39 | outportb(PortAddress, a); 40 | } 41 | void Serialport::WriteStr(char* str) 42 | { 43 | for(int i = 0; str[i] != '\0'; ++i) 44 | Write(str[i]); 45 | } 46 | 47 | void Serialport::Init(COMPort port) 48 | { 49 | Serialport::PortAddress = port; 50 | 51 | outportb(PortAddress + 1, 0x00); // Disable all interrupts 52 | outportb(PortAddress + 3, 0x80); // Enable DLAB (set baud rate divisor) 53 | outportb(PortAddress + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud 54 | outportb(PortAddress + 1, 0x00); // (hi byte) 55 | outportb(PortAddress + 3, 0x03); // 8 bits, no parity, one stop bit 56 | outportb(PortAddress + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold 57 | outportb(PortAddress + 4, 0x0B); // IRQs enabled, RTS/DSR set 58 | 59 | Serialport::Initialized = true; 60 | } -------------------------------------------------------------------------------- /kernel/src/system/syscalls/implementations/linux.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | using namespace CactusOS; 6 | using namespace CactusOS::common; 7 | using namespace CactusOS::core; 8 | using namespace CactusOS::system; 9 | 10 | CPUState* LinuxSyscalls::HandleSyscall(CPUState* state) 11 | { 12 | switch (state->EAX) 13 | { 14 | case 0xFFFF: //We use this systemcall for setting the CactusOS Syscall implementation for this process since linux is the default one 15 | //From now on this uses CactusOS Systemcalls 16 | System::scheduler->CurrentProcess()->syscallID = 1; 17 | //Return a succes 18 | state->EAX = System::scheduler->CurrentProcess()->id; //Return the pid 19 | break; 20 | 21 | default: 22 | state->EAX = 0; 23 | break; 24 | } 25 | 26 | return state; 27 | } -------------------------------------------------------------------------------- /kernel/src/system/syscalls/syscalls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace CactusOS; 8 | using namespace CactusOS::common; 9 | using namespace CactusOS::system; 10 | using namespace CactusOS::core; 11 | 12 | SystemCallHandler::SystemCallHandler() 13 | : InterruptHandler(0x80) { 14 | 15 | } 16 | 17 | uint32_t SystemCallHandler::HandleInterrupt(uint32_t esp) 18 | { 19 | //Interrupts need to be enabled for io system calls 20 | InterruptDescriptorTable::EnableInterrupts(); 21 | 22 | int ID = System::scheduler->CurrentProcess()->syscallID; 23 | 24 | switch (ID) 25 | { 26 | case 0: //Linux Systemcall 27 | return (uint32_t)LinuxSyscalls::HandleSyscall((CPUState*)esp); 28 | break; 29 | case 1: //CactusOS Systemcall 30 | return (uint32_t)CactusOSSyscalls::HandleSyscall((CPUState*)esp); 31 | break; 32 | default: 33 | Log(Error, "Process %d has unkown syscallID %d", System::scheduler->CurrentProcess()->syscallID, ID); 34 | break; 35 | } 36 | 37 | //Restore previous state 38 | InterruptDescriptorTable::DisableInterrupts(); 39 | 40 | return esp; 41 | } -------------------------------------------------------------------------------- /kernel/src/system/tasking/atomic.s: -------------------------------------------------------------------------------- 1 | .globl TestAndSet 2 | TestAndSet: 3 | movl 4(%esp),%eax # get new_value into %eax 4 | movl 8(%esp),%edx # get lock_pointer into %edx 5 | lock # next instruction is locked 6 | xchgl %eax,(%edx) # swap %eax with what is stored in (%edx) 7 | # ... and don't let any other cpu touch that 8 | # ... memory location while you're swapping 9 | ret # return the old value that's in %eax -------------------------------------------------------------------------------- /kernel/src/system/tasking/lock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS; 5 | using namespace CactusOS::system; 6 | 7 | extern "C" int TestAndSet(int newValue, int* ptr); 8 | 9 | MutexLock::MutexLock() 10 | { 11 | this->value = 0; 12 | } 13 | void MutexLock::Lock() 14 | { 15 | while (TestAndSet(1, &this->value) == 1) { 16 | if(System::scheduler && System::scheduler->Enabled) 17 | System::scheduler->ForceSwitch(); 18 | else 19 | asm ("pause"); 20 | } 21 | } 22 | void MutexLock::Unlock() 23 | { 24 | this->value = 0; 25 | } -------------------------------------------------------------------------------- /kernel/src/system/tasking/userspace.asm: -------------------------------------------------------------------------------- 1 | GLOBAL enter_usermode 2 | enter_usermode: 3 | ;push ebp 4 | mov ebp, esp 5 | cli 6 | 7 | mov ax, 0x20 | 3 8 | mov ds, ax 9 | mov es, ax 10 | mov fs, ax 11 | mov gs, ax 12 | 13 | push 0x20 | 3 ; push ss3 14 | 15 | mov ecx, [ebp+8] 16 | push ecx ; push esp3 17 | 18 | pushf ; push flags onto stack 19 | pop eax ; pop into eax 20 | or eax, [ebp+12] ; Copy EFLAGS from arg 3 21 | push eax ; push eflags 22 | push 0x18 | 3 ; push CS, requested priv. level = 3 23 | 24 | xor eax, eax ; Clear eax 25 | mov eax, [ebp+4] ; Load new IP into eax 26 | push eax ; Push EIP onto stack 27 | 28 | iret -------------------------------------------------------------------------------- /kernel/src/system/usb/usbendpoint.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace CactusOS; 4 | using namespace CactusOS::common; 5 | using namespace CactusOS::system; 6 | 7 | USBEndpoint::USBEndpoint(struct ENDPOINT_DESC* src) 8 | { 9 | this->endpointNumber = src->end_point & 0xF; 10 | this->dir = (src->end_point & (1<<7)) ? EndpointDirection::In : EndpointDirection::Out; 11 | this->type = (EndpointType)(src->bm_attrbs & 0b11); 12 | this->maxPacketSize = src->max_packet_size; 13 | this->interval = src->interval; 14 | } 15 | 16 | bool USBEndpoint::Toggle() 17 | { 18 | this->toggleState = !this->toggleState; 19 | return !this->toggleState; // Return original value 20 | } 21 | 22 | void USBEndpoint::SetToggle(bool v) 23 | { 24 | this->toggleState = v; 25 | } -------------------------------------------------------------------------------- /kernel/src/system/vfs/virtualfilesystem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace CactusOS::common; 5 | using namespace CactusOS::core; 6 | using namespace CactusOS::system; 7 | 8 | VirtualFileSystem::VirtualFileSystem(Disk* disk, common::uint32_t start, common::uint32_t size, char* name) 9 | { 10 | this->disk = disk; 11 | this->SizeInSectors = size; 12 | this->StartLBA = start; 13 | this->Name = name; 14 | } 15 | 16 | VirtualFileSystem::~VirtualFileSystem() 17 | { 18 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 19 | } 20 | 21 | bool VirtualFileSystem::Initialize() 22 | { 23 | return false; 24 | } 25 | 26 | int VirtualFileSystem::ReadFile(const char* filename, uint8_t* buffer, uint32_t offset, uint32_t len) 27 | { 28 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 29 | return -1; 30 | } 31 | int VirtualFileSystem::WriteFile(const char* filename, uint8_t* buffer, uint32_t len, bool create) 32 | { 33 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 34 | return -1; 35 | } 36 | bool VirtualFileSystem::FileExists(const char* filename) 37 | { 38 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 39 | return false; 40 | } 41 | bool VirtualFileSystem::DirectoryExists(const char* filename) 42 | { 43 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 44 | return false; 45 | } 46 | int VirtualFileSystem::CreateFile(const char* path) 47 | { 48 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 49 | return -1; 50 | } 51 | int VirtualFileSystem::CreateDirectory(const char* path) 52 | { 53 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 54 | return -1; 55 | } 56 | uint32_t VirtualFileSystem::GetFileSize(const char* filename) 57 | { 58 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 59 | return -1; 60 | } 61 | List* VirtualFileSystem::DirectoryList(const char* path) 62 | { 63 | Log(Error, "Virtual function called directly %s:%d", __FILE__, __LINE__); 64 | return 0; 65 | } -------------------------------------------------------------------------------- /kernel/src/system/virtual8086/VM8086Code.asm: -------------------------------------------------------------------------------- 1 | [bits 16] 2 | 3 | global VM86CodeStart 4 | VM86CodeStart: 5 | 6 | ; FIXME: uses self modifying code 7 | global Int86 8 | Int86: 9 | push cs 10 | pop ds 11 | 12 | ; modify the int n instruction 13 | mov byte [Int86.doInt - VM86CodeStart + 1], al 14 | 15 | ; load registers 16 | mov ax, word [0x8000] 17 | mov bx, word [0x8002] 18 | mov cx, word [0x8004] 19 | mov dx, word [0x8006] 20 | 21 | mov di, word [0x8008] 22 | ; do the int n instruction 23 | .doInt: 24 | int 0x0 ; dummy int instruction 25 | ; will be overwritten 26 | ; store registers 27 | push ds 28 | push cs 29 | pop ds 30 | 31 | mov word [0x8000], ax 32 | mov word [0x8002], bx 33 | mov word [0x8004], cx 34 | mov word [0x8006], dx 35 | 36 | mov word [0x8008], di 37 | 38 | ; return to kernel 39 | int 0xFE 40 | 41 | global diskInfo 42 | diskInfo: 43 | mov dl, al ; Drive 44 | mov ax, 0x4800 ; Function 0x48 45 | 46 | ; Setup buffer 47 | mov word [0x7000], 0x42 48 | mov si, 0x7000 49 | 50 | int 0x13 ; Call Interupt 51 | jc diskInfoError 52 | 53 | ; return to kernel 54 | int 0xFE 55 | 56 | diskInfoError: 57 | mov word [0x7000], 0 ; Indicate error in buffer 58 | ; return to kernel 59 | int 0xFE 60 | 61 | global VM86CodeEnd 62 | VM86CodeEnd: 63 | -------------------------------------------------------------------------------- /kernel/src/system/virtual8086/VM8086Helper.asm: -------------------------------------------------------------------------------- 1 | global cpuGetEIP 2 | cpuGetEIP: 3 | pop eax 4 | jmp eax 5 | 6 | global cpuGetESP 7 | cpuGetESP: 8 | mov eax, esp 9 | add eax, 4 10 | ret 11 | 12 | # VM86 Code 13 | global cpuEnterV86Int 14 | cpuEnterV86Int: 15 | push ebp 16 | mov ebp, esp 17 | push ebx 18 | push esi 19 | push edi 20 | mov eax, [ebp + 8] 21 | mov ebx, [ebp + 12] 22 | mov ecx, [ebp + 16] 23 | mov edx, [ebp + 20] 24 | mov esi, [ebp + 24] 25 | mov edi, [ebp + 28] 26 | int 0xFD ; MUST match interrupt number registered in vm86.c 27 | pop edi 28 | pop esi 29 | pop ebx 30 | mov esp, ebp 31 | pop ebp 32 | ret 33 | 34 | global cpuEnterV86 35 | cpuEnterV86: 36 | mov ebp, esp 37 | push 0 ; GS 38 | push 0 ; FS 39 | push 0 ; DS 40 | push 0 ; ES 41 | push dword [ebp + 4] ; SS 42 | push dword [ebp + 8] ; ESP 43 | pushfd ; EFLAGS 44 | or dword [esp], (1 << 17) 45 | push dword [ebp + 12] ; CS 46 | push dword [ebp + 16] ; EIP 47 | mov eax, dword [ebp + 20] 48 | ; hlt 49 | iretd -------------------------------------------------------------------------------- /lib/include/api.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__API_H 2 | #define __CACTUSOSLIB__API_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | class API 9 | { 10 | public: 11 | /** 12 | * Initialize the CactusOS Api for this process 13 | */ 14 | static void Initialize(); 15 | }; 16 | } 17 | 18 | #endif -------------------------------------------------------------------------------- /lib/include/bitreader.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__BITREADER_H 2 | #define __LIBCACTUSOS__BITREADER_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | // Used to read specific bits of a datastream 9 | class BitReader 10 | { 11 | private: 12 | uint8_t* dataPtr = 0; 13 | uint32_t pos = 0; 14 | uint8_t byte = 0; 15 | uint32_t numBits = 0; 16 | public: 17 | BitReader(uint8_t* data) 18 | { 19 | this->dataPtr = data; 20 | this->pos = 0; 21 | this->byte = 0; 22 | this->numBits = 0; 23 | } 24 | 25 | // Read single byte 26 | uint8_t ReadByte() 27 | { 28 | // Discard other bits 29 | this->numBits = 0; 30 | uint8_t b = this->dataPtr[this->pos]; 31 | this->pos += 1; 32 | return b; 33 | } 34 | 35 | // Read single bit 36 | uint8_t ReadBit() 37 | { 38 | if(this->numBits <= 0) { 39 | this->byte = this->ReadByte(); 40 | this->numBits = 8; 41 | } 42 | this->numBits -= 1; 43 | uint8_t bit = this->byte & 1; 44 | this->byte >>= 1; 45 | return bit; 46 | } 47 | 48 | // Read bits as type 49 | template 50 | T ReadBits(uint32_t n) 51 | { 52 | T ret = 0; 53 | for(uint32_t i = 0; i < n; i++) 54 | ret |= (this->ReadBit() << i); 55 | 56 | return ret; 57 | } 58 | 59 | // Read bytes as type 60 | template 61 | T ReadBytes(uint32_t n) 62 | { 63 | T ret = 0; 64 | for(uint32_t i = 0; i < n; i++) 65 | ret |= (this->ReadByte() << (i*8)); 66 | 67 | return ret; 68 | } 69 | }; 70 | } 71 | 72 | #endif -------------------------------------------------------------------------------- /lib/include/convert.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__CONVERT_H 2 | #define __LIBCACTUSOS__CONVERT_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | class Convert 9 | { 10 | public: 11 | static char* IntToString(int i); 12 | 13 | static char* IntToHexString(uint8_t w); 14 | static char* IntToHexString(uint16_t w); 15 | static char* IntToHexString(uint32_t w); 16 | 17 | static int StringToInt(char* string); 18 | }; 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /lib/include/datetime.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__DATETIME_H 2 | #define __LIBCACTUSOS__DATETIME_H 3 | 4 | namespace LIBCactusOS 5 | { 6 | class DateTime 7 | { 8 | public: 9 | signed char Day = -1; 10 | signed char Month = -1; 11 | int Year = -1; 12 | 13 | signed char Seconds = -1; 14 | signed char Minutes = -1; 15 | signed char Hours = -1; 16 | 17 | /** 18 | * Get the current date and time of this system 19 | */ 20 | static DateTime Current(); 21 | 22 | /** 23 | * Convert DateTime into a readable string 24 | */ 25 | char* ToString(); 26 | }; 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /lib/include/gui/canvas.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__CANVAS_H 2 | #define __LIBCACTUSOS__GUI__CANVAS_H 3 | 4 | #include 5 | #include 6 | 7 | namespace LIBCactusOS 8 | { 9 | class Canvas 10 | { 11 | private: 12 | void DrawCircleHelper(int x, int y, int radius, uint32_t corner, uint32_t color); 13 | void FillCircleHelper(int x, int y, int radius, uint32_t corner, int delta, uint32_t color); 14 | public: 15 | void* bufferPointer; 16 | int Width; 17 | int Height; 18 | 19 | Canvas(void* buffer, int w, int h); 20 | 21 | void SetPixel(int x, int y, uint32_t color); 22 | uint32_t GetPixel(int x, int y); 23 | 24 | void Clear(); 25 | void Clear(uint32_t color); 26 | void DrawHorizontalLine(uint32_t color, int dx, int x1, int y1); 27 | void DrawVerticalLine(uint32_t color, int dx, int x1, int y1); 28 | void DrawLine(uint32_t color, int x1, int y1, int x2, int y2); 29 | void DrawDiagonalLine(uint32_t color, int dx, int dy, int x1, int y1); 30 | void DrawRect(uint32_t color, int x, int y, int width, int height); 31 | void DrawRoundedRect(uint32_t color, int x, int y, int width, int height, int radius); 32 | void DrawFillRoundedRect(uint32_t color, int x, int y, int width, int height, int radius); 33 | void DrawFillRect(uint32_t color, int x_start, int y_start, int width, int height); 34 | void DrawCircle(uint32_t color, int x_center, int y_center, int radius); 35 | void DrawFillCircle(uint32_t color, int x_center, int y_center, int radius); 36 | void DrawEllipse(uint32_t color, int x_center, int y_center, int x_radius, int y_radius); 37 | 38 | void DrawString(Font* font, char* string, int x, int y, uint32_t color); 39 | }; 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /lib/include/gui/colors.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__COLORS_H 2 | #define __LIBCACTUSOS__GUI__COLORS_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | // Union describing a ARGB color in the following format: 9 | // 0xAARRGGBB 10 | typedef union Color4Tag 11 | { 12 | uint32_t c; 13 | struct ColorComponents 14 | { 15 | uint8_t b; 16 | uint8_t g; 17 | uint8_t r; 18 | uint8_t a; 19 | } argb; 20 | } Color4; 21 | 22 | class Colors 23 | { 24 | public: 25 | static const uint32_t Black = 0xFF000000; 26 | static const uint32_t White = 0xFFFFFFFF; 27 | static const uint32_t Red = 0xFFFF0000; 28 | static const uint32_t Green = 0xFF00FF00; 29 | static const uint32_t Blue = 0xFF0000FF; 30 | static const uint32_t Transparent = 0x00000000; 31 | public: 32 | /** 33 | * Blend to colors using alpha blending 34 | * Color1 is background 35 | * Color2 is foreground 36 | */ 37 | static const uint32_t AlphaBlend(uint32_t color1, uint32_t color2); 38 | 39 | /** 40 | * Convert a ARGB color to 0xAARRGGBB format 41 | */ 42 | static const uint32_t FromARGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b); 43 | }; 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /lib/include/gui/contextheap.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__CONTEXTHEAP_H 2 | #define __LIBCACTUSOS__GUI__CONTEXTHEAP_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | //Class that provides functions for allocating memory space for contexts. 9 | //Note: Memory region is not allocated, just a block that is reserved after allocating. 10 | class ContextHeap 11 | { 12 | public: 13 | static void Init(); 14 | //Allocate a area of memory, blocks is in units per 4096 bytes 15 | static uint32_t AllocateArea(uint32_t blocks); 16 | //Free area of memory 17 | static void FreeArea(uint32_t address, uint32_t blocks); 18 | //Get amount of memory used as factor [0-1] 19 | static double MemoryUsage(); 20 | }; 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /lib/include/gui/directgui.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__GUI__DIRECTGUI_H 2 | #define __CACTUSOSLIB__GUI__DIRECTGUI_H 3 | 4 | #include 5 | #include 6 | 7 | namespace LIBCactusOS 8 | { 9 | class DirectGUI 10 | { 11 | public: 12 | static bool RequestFramebuffer(); 13 | static Canvas* GetCanvas(); 14 | 15 | static void SetPixel(int x, int y, uint32_t color); 16 | static uint32_t GetPixel(int x, int y); 17 | 18 | static void Clear(); 19 | static void Clear(uint32_t color); 20 | static void DrawHorizontalLine(uint32_t color, int dx, int x1, int y1); 21 | static void DrawVerticalLine(uint32_t color, int dx, int x1, int y1); 22 | static void DrawLine(uint32_t color, int x1, int y1, int x2, int y2); 23 | static void DrawDiagonalLine(uint32_t color, int dx, int dy, int x1, int y1); 24 | static void DrawRect(uint32_t color, int x, int y, int width, int height); 25 | static void DrawFillRect(uint32_t color, int x_start, int y_start, int width, int height); 26 | static void DrawCircle(uint32_t color, int x_center, int y_center, int radius); 27 | static void DrawFillCircle(uint32_t color, int x_center, int y_center, int radius); 28 | static void DrawEllipse(uint32_t color, int x_center, int y_center, int x_radius, int y_radius); 29 | 30 | static void DrawChar(char character, int x, int y, uint32_t color); 31 | static void DrawString(char* string, int x, int y, uint32_t color); 32 | }; 33 | } 34 | 35 | #endif -------------------------------------------------------------------------------- /lib/include/gui/fonts/font.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__FONTS__FONT_H 2 | #define __LIBCACTUSOS__GUI__FONTS__FONT_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | struct Font 9 | { 10 | uint8_t* data = 0; // Raw font data including header 11 | char* name = 0; // Name of this font, stored inside data buffer 12 | int size = 0; // Size of this font in points 13 | uint32_t* offsetTable = 0; // Offsets for each character data sorted by character 14 | 15 | void BoundingBox(char* str, int* retW, int* retH); 16 | }; 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /lib/include/gui/fonts/fontparser.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__FONTS__FONTPARSER_H 2 | #define __LIBCACTUSOS__GUI__FONTS__FONTPARSER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace LIBCactusOS 8 | { 9 | // Header of a CactusOS Font File (CFF) 10 | struct CFFHeader 11 | { 12 | uint32_t Magic; // Magic number containing 0xCFF 13 | uint8_t Version; // Version of this font file, propably 1 14 | uint16_t FontSize; // Size of font in dots 15 | uint32_t FontNameOffset; // Offset in file data where font name is stored 16 | 17 | uint32_t CharacterOffsets[127-32]; // Table which contains offsets to the data for each character 18 | } __attribute__((packed)); 19 | 20 | class FontParser 21 | { 22 | public: 23 | static Font* FromFile(char* filename); 24 | }; 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /lib/include/gui/widgets/button.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__BUTTON_H 2 | #define __LIBCACTUSOS__GUI__BUTTON_H 3 | 4 | #include 5 | #include 6 | 7 | namespace LIBCactusOS 8 | { 9 | /** 10 | * A GUI button 11 | */ 12 | class Button : public Control 13 | { 14 | public: 15 | /** 16 | * The text of this label 17 | */ 18 | GUIProperty label = GUIProperty(this, 0); 19 | 20 | /** 21 | * Create a new button with a peice of text 22 | */ 23 | Button(char* text = 0); 24 | 25 | /** 26 | * Draw this button 27 | */ 28 | void DrawTo(Canvas* context, int x_abs, int y_abs) override; 29 | 30 | /*///////// 31 | // Events 32 | *////////// 33 | friend class Window; 34 | friend class Context; 35 | protected: 36 | /** 37 | * Called when mouse is down on control 38 | */ 39 | void OnMouseDown(int x_abs, int y_abs, uint8_t button) override; 40 | /** 41 | * Called when mouse is up on control 42 | */ 43 | void OnMouseUp(int x_abs, int y_abs, uint8_t button) override; 44 | /** 45 | * Called when mouse enters control 46 | */ 47 | void OnMouseEnter(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) override; 48 | /** 49 | * Called when mouse leaves control 50 | */ 51 | void OnMouseLeave(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) override; 52 | }; 53 | } 54 | 55 | #endif -------------------------------------------------------------------------------- /lib/include/gui/widgets/label.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__LABEL_H 2 | #define __LIBCACTUSOS__GUI__LABEL_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | class Label : public Control 9 | { 10 | public: 11 | GUIProperty text = GUIProperty(this, 0); 12 | 13 | /** 14 | * Create a new label with a peice of text 15 | */ 16 | Label(char* text = 0); 17 | 18 | /** 19 | * Draw this label 20 | */ 21 | void DrawTo(Canvas* context, int x_abs, int y_abs) override; 22 | }; 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /lib/include/gui/widgets/listview.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__LISTVIEW_H 2 | #define __LIBCACTUSOS__GUI__LISTVIEW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace LIBCactusOS 9 | { 10 | class ListViewItem 11 | { 12 | public: 13 | char* title; 14 | Imaging::Image* icon; 15 | public: 16 | ListViewItem(); 17 | ~ListViewItem(); 18 | }; 19 | 20 | class ListView : public Control 21 | { 22 | private: 23 | List items; 24 | public: 25 | ListView(); 26 | ~ListView(); 27 | 28 | /** 29 | * Draw this button 30 | */ 31 | void DrawTo(Canvas* context, int x_abs, int y_abs) override; 32 | 33 | /*///////// 34 | // Events 35 | *////////// 36 | friend class Window; 37 | friend class Context; 38 | protected: 39 | /** 40 | * Called when mouse is down on control 41 | */ 42 | void OnMouseDown(int x_abs, int y_abs, uint8_t button) override; 43 | /** 44 | * Called when mouse is up on control 45 | */ 46 | void OnMouseUp(int x_abs, int y_abs, uint8_t button) override; 47 | }; 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /lib/include/gui/widgets/scrollbox.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__SCROLLBOX_H 2 | #define __LIBCACTUSOS__GUI__SCROLLBOX_H 3 | 4 | #include 5 | #include 6 | 7 | namespace LIBCactusOS 8 | { 9 | class ScrollBox : public Control 10 | { 11 | public: 12 | ScrollBar* scrollVertical = 0; 13 | ScrollBar* scrollHorizontal = 0; 14 | public: 15 | ScrollBox(); 16 | 17 | // Draw this scrollbox 18 | void DrawTo(Canvas* context, int x_abs, int y_abs) override; 19 | }; 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /lib/include/gui/widgets/slider.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__GUI__SLIDER_H 2 | #define __LIBCACTUSOS__GUI__SLIDER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace LIBCactusOS 10 | { 11 | class Slider : public Control 12 | { 13 | private: 14 | bool mouseDown = false; 15 | public: 16 | GUIProperty minValue = GUIProperty(this, 0); 17 | GUIProperty maxValue = GUIProperty(this, 0); 18 | GUIProperty position = GUIProperty(this, 0); 19 | GUIProperty knobColor = GUIProperty(this, Colors::Blue); 20 | GUIProperty knobSize = GUIProperty(this, 10); 21 | 22 | EventHandlerList OnValueChanged; 23 | public: 24 | Slider(int min = 0, int max = 100, int current = 50); 25 | 26 | // Called when mouse is down on this control 27 | void OnMouseDown(int x_abs, int y_abs, uint8_t button) override; 28 | 29 | // Called when mouse is up this control 30 | void OnMouseUp(int x_abs, int y_abs, uint8_t button) override; 31 | 32 | // Called when mouse is moved this control 33 | void OnMouseMove(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) override; 34 | 35 | // Called when mouse enters control 36 | void OnMouseEnter(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) override; 37 | 38 | // Called when mouse leaves control 39 | void OnMouseLeave(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) override; 40 | 41 | // Draw this slider 42 | void DrawTo(Canvas* context, int x_abs, int y_abs) override; 43 | }; 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /lib/include/heap.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__HEAP_H 2 | #define __CACTUSOSLIB__HEAP_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | #ifndef align_up 9 | #define align_up(num, align) \ 10 | (((num) + ((align) - 1)) & ~((align) - 1)) 11 | #endif 12 | 13 | uint32_t pageRoundUp(uint32_t address); 14 | uint32_t pageRoundDown(uint32_t address); 15 | 16 | #define HEAP_INCREASE_SIZE 10_MB 17 | 18 | struct MemoryHeader 19 | { 20 | MemoryHeader* next; 21 | MemoryHeader* prev; 22 | bool allocated; 23 | uint32_t size; 24 | } __attribute__((packed)); 25 | 26 | class UserHeap 27 | { 28 | private: 29 | static uint32_t startAddress; 30 | static uint32_t endAddress; 31 | static uint32_t maxAddress; 32 | 33 | static MemoryHeader* firstHeader; 34 | 35 | public: 36 | static void Initialize(); 37 | static void PrintMemoryLayout(); 38 | 39 | static void* Malloc(uint32_t size); 40 | static void Free(void* ptr); 41 | 42 | static void* alignedMalloc(uint32_t size, uint32_t align); 43 | static void allignedFree(void* ptr); 44 | }; 45 | } 46 | 47 | #endif -------------------------------------------------------------------------------- /lib/include/imaging/bmpformat.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__IMAGING__BMPIMAGE_H 2 | #define __CACTUSOSLIB__IMAGING__BMPIMAGE_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | namespace Imaging 9 | { 10 | struct BMPFileHeader { 11 | uint16_t fileType; 12 | uint32_t fileSize; 13 | uint16_t Reserved1; 14 | uint16_t Reserved2; 15 | uint32_t dataOffset; 16 | } __attribute__((packed)); 17 | 18 | struct BMPInfoHeader { 19 | uint32_t headerSize; 20 | int32_t Width; 21 | int32_t Height; 22 | uint16_t Planes; 23 | uint16_t BitCount; 24 | uint32_t Compression; 25 | uint32_t SizeImage; 26 | int32_t XPelsPerMeter; 27 | int32_t YPelsPerMeter; 28 | uint32_t ClrUsed; 29 | uint32_t ClrImportant; 30 | } __attribute__((packed)); 31 | 32 | struct BMPColorHeader { 33 | uint32_t redMask; 34 | uint32_t greenMask; 35 | uint32_t blueMask; 36 | uint32_t alphaMask; 37 | uint32_t colorSpaceType; 38 | uint32_t unused[16]; 39 | } __attribute__((packed)); 40 | 41 | // Convert image file into image buffer 42 | Image* ConvertBMP(const char* filepath); 43 | // Create image from array of bytes in bmp format 44 | Image* ConvertBMPRaw(const uint8_t* rawData); 45 | } 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /lib/include/imaging/image.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__IMAGING_IMAGE_H 2 | #define __CACTUSOSLIB__IMAGING_IMAGE_H 3 | 4 | #include 5 | #include 6 | 7 | namespace LIBCactusOS 8 | { 9 | namespace Imaging 10 | { 11 | // Enable alpha for bilinear image scaling or not? 12 | #define BILINEAR_ALPHA 1 13 | 14 | enum ResizeMethod 15 | { 16 | NearestNeighbor, 17 | Bilinear 18 | }; 19 | 20 | class Image 21 | { 22 | private: 23 | int width = 0; 24 | int height = 0; 25 | Canvas* canvas = 0; 26 | 27 | uint32_t* buffer = 0; 28 | public: 29 | // Create new image using a width and height 30 | Image(const int width, const int height); 31 | // Destructor 32 | ~Image(); 33 | 34 | // Generate a canvas for this image and return it 35 | // It will only get generated once for each image and will get destroyed automatically 36 | Canvas* GetCanvas(); 37 | 38 | // Get width of image 39 | int GetWidth(); 40 | 41 | // Get height of image 42 | int GetHeight(); 43 | 44 | // Receive pointer to raw buffer 45 | uint32_t* GetBufferPtr(); 46 | 47 | // Draw this image directly to a canvas 48 | void DrawTo(Canvas* target, int x = 0, int y = 0); 49 | 50 | // Create image from a file present on disk 51 | static Image* CreateFromFile(const char* filepath, const char* ext = 0); 52 | 53 | // Resize source image and return result 54 | static Image* Resize(Image* source, int newWidth, int newHeight, ResizeMethod method = NearestNeighbor); 55 | private: 56 | static Image* ResizeNearestNeighbor(Image* source, int newWidth, int newHeight); 57 | static Image* ResizeBilinear(Image* source, int newWidth, int newHeight); 58 | }; 59 | } 60 | } 61 | 62 | #endif -------------------------------------------------------------------------------- /lib/include/ipc.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__IPC_H 2 | #define __LIBCACTUSOS__IPC_H 3 | 4 | namespace LIBCactusOS 5 | { 6 | enum IPCMessageType : int 7 | { 8 | None = 0, 9 | GUIRequest = 1, 10 | GUIEvent = 2 11 | }; 12 | 13 | struct IPCMessage 14 | { 15 | int source; // Who has sended this message? 16 | int dest; // Who is it for 17 | 18 | int type; // What type of message is it? 19 | 20 | // Arguments 21 | unsigned int arg1; 22 | unsigned int arg2; 23 | unsigned int arg3; 24 | unsigned int arg4; 25 | unsigned int arg5; 26 | unsigned int arg6; 27 | }; 28 | 29 | /** 30 | * Send a message to a other process 31 | */ 32 | int IPCSend(int dest, int type = IPCMessageType::None, unsigned int arg1 = 0, unsigned int arg2 = 0, unsigned int arg3 = 0, unsigned int arg4 = 0, unsigned int arg5 = 0, unsigned int arg6 = 0); 33 | /** 34 | * Send a message to a other process 35 | */ 36 | int IPCSend(IPCMessage message); 37 | 38 | /** 39 | * How many messages are ready for receiving? 40 | */ 41 | int IPCAvailable(); 42 | 43 | /** 44 | * Receive a single IPCMessage, blocks if none availible 45 | * FromID: Only receive a message from specified process 46 | */ 47 | IPCMessage ICPReceive(int fromID = -1, int* errOut = 0, int type = -1); 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /lib/include/listing.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__LISTING_H 2 | #define __LIBCACTUSOS__LISTING_H 3 | 4 | namespace LIBCactusOS 5 | { 6 | #define DIRECTORY_LISTING 0 7 | #define DISK_LISTING 1 8 | } 9 | 10 | #endif -------------------------------------------------------------------------------- /lib/include/log.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__LOG_H 2 | #define __CACTUSOSLIB__LOG_H 3 | 4 | namespace LIBCactusOS 5 | { 6 | enum LogLevel 7 | { 8 | Info, 9 | Warning, 10 | Error 11 | }; 12 | 13 | /** 14 | * Send a log message to the system 15 | */ 16 | void Log(LogLevel level, char* msg); 17 | /** 18 | * Print a message to the standard output stream 19 | */ 20 | void Print(const char* __restrict__ format, ...); 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /lib/include/math.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__MATH_H 2 | #define __CACTUSOSLIB__MATH_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | #define MATH_PI 3.14159265358979323846 9 | 10 | struct MXCSR_StatusRegister 11 | { 12 | uint8_t InvalidOperationFlag : 1; 13 | uint8_t DenormalFlag : 1; 14 | uint8_t DevideByZeroFlag : 1; 15 | uint8_t OverflowFlag : 1; 16 | uint8_t UnderflowFlag : 1; 17 | uint8_t PrecisionFlag : 1; 18 | uint8_t DemormalsAreZeros : 1; 19 | uint8_t InvalidOperationMask : 1; 20 | uint8_t DenormalOperationMask : 1; 21 | uint8_t DevideByZeroMask : 1; 22 | uint8_t OverflowMask : 1; 23 | uint8_t UnderflowMask : 1; 24 | uint8_t PrecisionMask : 1; 25 | uint8_t RoundingControl : 2; 26 | uint8_t FlushToZero : 1; 27 | uint16_t Reserved; 28 | } __attribute__((packed)); 29 | 30 | class Math 31 | { 32 | public: 33 | static void EnableFPU(); 34 | 35 | static long Abs(long v); 36 | static double fAbs(double x); 37 | static long Sign(long v); 38 | static double sin(double x); 39 | static double cos(double x); 40 | 41 | static long Max (long a, long b); 42 | static long Min (long a, long b); 43 | static long Constrain(long x, long a, long b); 44 | static long Map(long x, long in_min, long in_max, long out_min, long out_max); 45 | 46 | static float fMod(float a, float b); 47 | static double floor(double x); 48 | static double sqrt(double n); 49 | 50 | static double Round(double n, uint32_t digits); 51 | }; 52 | } 53 | #endif -------------------------------------------------------------------------------- /lib/include/new.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__NEW_H 2 | #define __LIBCACTUSOS__NEW_H 3 | 4 | #include 5 | #include 6 | 7 | using namespace LIBCactusOS; 8 | 9 | void *operator new(size_t size) 10 | { 11 | return UserHeap::Malloc(size); 12 | } 13 | 14 | void *operator new[](size_t size) 15 | { 16 | return UserHeap::Malloc(size); 17 | } 18 | 19 | void* operator new(size_t size, void* ptr) 20 | { 21 | return ptr; 22 | } 23 | 24 | void* operator new[](size_t size, void* ptr) 25 | { 26 | return ptr; 27 | } 28 | 29 | void operator delete(void *p) 30 | { 31 | UserHeap::Free(p); 32 | } 33 | 34 | void operator delete[](void *p) 35 | { 36 | UserHeap::Free(p); 37 | } 38 | 39 | void operator delete(void* ptr, size_t size) 40 | { 41 | UserHeap::Free(ptr); 42 | } 43 | void operator delete[](void* ptr, size_t size) 44 | { 45 | UserHeap::Free(ptr); 46 | } 47 | 48 | #endif -------------------------------------------------------------------------------- /lib/include/random.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBCACTUSOS__RANDOM_H 2 | #define LIBCACTUSOS__RANDOM_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | class Random 9 | { 10 | public: 11 | static int Next(uint32_t max = 32767); 12 | static int Next(uint32_t min, uint32_t max); 13 | static void SetSeed(uint32_t seed); 14 | }; 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /lib/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__MEMORYOPERATIONS_H 2 | #define __CACTUSOSLIB__MEMORYOPERATIONS_H 3 | 4 | #include 5 | #include 6 | 7 | extern "C" 8 | { 9 | int memcmp(const void* aptr, const void* bptr, size_t size); 10 | void* memcpy(void* __restrict__ dstptr, const void* __restrict__ srcptr, size_t size); 11 | void* memmove(void* dstptr, const void* srcptr, size_t size); 12 | void* memset(void* bufptr, int value, size_t size); 13 | size_t strlen(const char* str); 14 | int strcmp(const char *s1, const char *s2); 15 | 16 | int str_IndexOf(const char* str, char c, int skip = 0); 17 | bool str_Contains(const char* str, char c); 18 | List str_Split(const char* str, char d); 19 | char* str_Uppercase(char* str); 20 | char* str_Lowercase(char* str); 21 | char* str_Add(char* str, char c); 22 | char* str_Combine(char* part1, char* part2); 23 | 24 | bool isvalid(unsigned char key); 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /lib/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__TIME_H 2 | #define __LIBCACTUSOS__TIME_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | class Time 9 | { 10 | public: 11 | /** 12 | * Make this thread sleep for a specific amount of ms 13 | */ 14 | static void Sleep(uint32_t ms); 15 | /** 16 | * Get the current amount of ticks from the timer 17 | */ 18 | static uint64_t Ticks(); 19 | }; 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /lib/include/types.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__TYPES_H 2 | #define __CACTUSOSLIB__TYPES_H 3 | 4 | namespace LIBCactusOS 5 | { 6 | #define STATIC_ASSERT(condition) typedef char p__LINE__[ (condition) ? 1 : -1]; 7 | 8 | typedef char int8_t; 9 | typedef unsigned char uint8_t; 10 | typedef short int16_t; 11 | typedef unsigned short uint16_t; 12 | typedef int int32_t; 13 | typedef unsigned int uint32_t; 14 | typedef long long int int64_t; 15 | typedef unsigned long long int uint64_t; 16 | typedef unsigned long long uintptr_t; 17 | 18 | constexpr uint32_t operator"" _KB(unsigned long long no) 19 | { 20 | return no * 1024; 21 | } 22 | constexpr uint32_t operator"" _MB(unsigned long long no) 23 | { 24 | return no * (1024_KB); 25 | } 26 | constexpr uint32_t operator"" _GB(unsigned long long no) 27 | { 28 | return no * (1024_MB); 29 | } 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /lib/include/vector.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBCACTUSOS__VECTOR_H 2 | #define __LIBCACTUSOS__VECTOR_H 3 | 4 | #include 5 | 6 | namespace LIBCactusOS 7 | { 8 | template 9 | class Vector 10 | { 11 | private: 12 | uint32_t size = 0; 13 | uint32_t capacity = 0; 14 | T* buffer = 0; 15 | 16 | void reserve(int capacity) 17 | { 18 | T* newBuf = new T[capacity]; 19 | memcpy(newBuf, this->buffer, sizeof(T) * this->size); 20 | 21 | this->capacity = capacity; 22 | 23 | if(this->buffer) 24 | delete this->buffer; 25 | this->buffer = newBuf; 26 | } 27 | public: 28 | Vector() 29 | { 30 | this->size = 0; 31 | this->capacity = 0; 32 | this->buffer = 0; 33 | } 34 | ~Vector() 35 | { this->clear(); } 36 | 37 | int Size() 38 | { return this->size; } 39 | 40 | void push_back(const T& item) 41 | { 42 | if(this->capacity == 0) 43 | reserve(10); 44 | else if(this->size == this->capacity) 45 | reserve(2 * this->size); 46 | 47 | this->buffer[this->size] = item; 48 | this->size++; 49 | } 50 | 51 | void pop_back() 52 | { this->size--; } 53 | 54 | void clear() 55 | { 56 | this->capacity = 0; 57 | this->size = 0; 58 | 59 | if(this->buffer) 60 | delete this->buffer; 61 | this->buffer = 0; 62 | } 63 | 64 | T& GetAt(int n) 65 | { return this->buffer[n]; } 66 | 67 | T& operator[](int n) 68 | { return this->buffer[n]; } 69 | 70 | T* data() 71 | { return this->buffer; } 72 | 73 | /////////////////// 74 | // Iterators 75 | /////////////////// 76 | 77 | typedef T* iterator; 78 | iterator begin() 79 | { 80 | return this->buffer; 81 | } 82 | 83 | iterator end() 84 | { 85 | return this->buffer + this->size; 86 | } 87 | }; 88 | } 89 | 90 | #endif -------------------------------------------------------------------------------- /lib/include/vfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACTUSOSLIB__VFS_H 2 | #define __CACTUSOSLIB__VFS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace LIBCactusOS 9 | { 10 | // Read file contents into buffer 11 | int ReadFile(char* filename, uint8_t* buffer, uint32_t offset = 0, uint32_t len = -1); 12 | // Write buffer to file, file will be created when create equals true 13 | int WriteFile(char* filename, uint8_t* buffer, uint32_t len, bool create = true); 14 | 15 | // Check if file exist 16 | bool FileExists(char* filename); 17 | // Check if directory exist 18 | bool DirectoryExists(char* filename); 19 | 20 | // Create a file at the filepath 21 | int CreateFile(char* path); 22 | // Create a new directory 23 | int CreateDirectory(char* path); 24 | 25 | // Get size of specified file in bytes 26 | uint32_t GetFileSize(char* filename); 27 | 28 | // Get list of files/directories in specified path 29 | List DirectoryListing(char* path); 30 | 31 | // Request to eject a specific disk (only works for CD's at the moment, TODO: usb as well?) 32 | bool EjectDisk(char* path); 33 | } 34 | 35 | #endif -------------------------------------------------------------------------------- /lib/makefile: -------------------------------------------------------------------------------- 1 | CONFIG = ../makefile.config 2 | include ${CONFIG} 3 | 4 | INCLUDEDIRS := include 5 | DEBUG := -g 6 | 7 | GCCPARAMS := -m32 $(DEBUG) -I $(INCLUDEDIRS) $(OPTIMIZE_FLAGS) -Wall -fno-omit-frame-pointer -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-exceptions -fno-rtti -fno-leading-underscore -Wno-write-strings -fpermissive -Wno-unknown-pragmas 8 | ASPARAMS := --32 9 | 10 | SRCDIR := src 11 | OBJDIR := obj 12 | 13 | SRCFILES := $(shell find $(SRCDIR) -type f \( -name \*.cpp -o -name \*.s -o -name \*.asm \)) #Find all the files that end with .cpp/.s/.asm 14 | OBJFILES := $(patsubst %.cpp,%.o,$(patsubst %.s,%.o,$(patsubst %.asm,%.o,$(SRCFILES)))) #Replace the .cpp/.s/.asm extension with .o 15 | OBJFILES := $(subst $(SRCDIR),$(OBJDIR),$(OBJFILES)) #Replace the "src" part with "obj" 16 | 17 | 18 | #################################### 19 | #C++ source files 20 | #################################### 21 | $(OBJDIR)/%.o: $(SRCDIR)/%.cpp 22 | mkdir -p $(@D) 23 | i686-elf-g++ $(GCCPARAMS) -c -o $@ $< 24 | 25 | #################################### 26 | #GAS assembly files 27 | #################################### 28 | $(OBJDIR)/%.o: $(SRCDIR)/%.s 29 | mkdir -p $(@D) 30 | i686-elf-as $(ASPARAMS) -o $@ $< 31 | 32 | #################################### 33 | #NASM assembly files 34 | #################################### 35 | $(OBJDIR)/%.o: $(SRCDIR)/%.asm 36 | mkdir -p $(@D) 37 | nasm -f elf32 -O0 $< -o $@ 38 | 39 | libcactusos.a: $(OBJFILES) 40 | i686-elf-ar r libcactusos.a $(OBJFILES) 41 | 42 | .PHONY: clean filelist 43 | clean: 44 | rm -rf $(OBJDIR) libcactusos.a 45 | 46 | filelist: 47 | @echo "Source Files:" 48 | @echo -$(SRCFILES) 49 | @echo "Object Files:" 50 | @echo -$(OBJFILES) 51 | -------------------------------------------------------------------------------- /lib/src/api.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace LIBCactusOS; 8 | 9 | void API::Initialize() 10 | { 11 | //Call kernel to set this process as a cactusos process 12 | Process::ID = DoSyscall(SYSCALL_SET_CACTUSOS_LIB); 13 | 14 | Log(Info, "CactusOS API Initialized for this process"); 15 | } -------------------------------------------------------------------------------- /lib/src/crt/crt0.asm: -------------------------------------------------------------------------------- 1 | BITS 32 2 | 3 | extern libMain 4 | 5 | global _start 6 | _start: 7 | call libMain ; Defined in lib/src/main.cpp 8 | _wait: ; enter infinite loop in the case we don't exit for some reason 9 | hlt 10 | jmp _wait -------------------------------------------------------------------------------- /lib/src/gui/colors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace LIBCactusOS; 4 | 5 | static const int AMASK = 0xFF000000; 6 | static const int RBMASK = 0x00FF00FF; 7 | static const int GMASK = 0x0000FF00; 8 | static const int AGMASK = AMASK | GMASK; 9 | static const int ONEALPHA = 0x01000000; 10 | 11 | const uint32_t Colors::AlphaBlend(uint32_t color1, uint32_t color2) 12 | { 13 | uint32_t a = (color2 & AMASK) >> 24; 14 | 15 | if(a == 0) 16 | return color1; 17 | else if(a == 255) 18 | return color2; 19 | else 20 | { 21 | uint32_t na = 255 - a; 22 | uint32_t rb = ((na * (color1 & RBMASK)) + (a * (color2 & RBMASK))) >> 8; 23 | uint32_t ag = (na * ((color1 & AGMASK) >> 8)) + (a * (ONEALPHA | ((color2 & GMASK) >> 8))); 24 | 25 | return ((rb & RBMASK) | (ag & AGMASK)); 26 | } 27 | } 28 | 29 | const uint32_t Colors::FromARGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b) 30 | { 31 | return ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | (uint32_t)b; 32 | } -------------------------------------------------------------------------------- /lib/src/gui/fonts/font.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace LIBCactusOS; 4 | 5 | void Font::BoundingBox(char* string, int* retW, int* retH) 6 | { 7 | if(string == 0 || retW == 0 || retH == 0) 8 | return; // Error with arguments 9 | 10 | if(this->data == 0) 11 | return; // Not initialized 12 | 13 | // Reset variables 14 | *retW = 0; 15 | *retH = 0; 16 | 17 | 18 | int xOffset = 0; 19 | int yOffset = 0; 20 | while(*string) 21 | { 22 | // Get the character we need to draw for this string 23 | char c = *string++; 24 | 25 | // Set initial values for first character 26 | if(xOffset == 0 && yOffset == 0) 27 | yOffset = ((uint8_t*)(this->data + this->offsetTable[0]))[1]; 28 | 29 | // Check for newline 30 | if(c == '\n') { 31 | if(xOffset > *retW) 32 | *retW = xOffset; 33 | 34 | xOffset = 0; 35 | 36 | // Add the height of the space character. TODO: Update this! 37 | yOffset += ((uint8_t*)(this->data + this->offsetTable[0]))[1] + 1; 38 | continue; 39 | } 40 | 41 | // Load data for this char from the font 42 | const uint8_t* charData = (uint8_t*)(this->data + this->offsetTable[(int)c - 32]); 43 | xOffset += charData[0]; 44 | } 45 | 46 | // Update return values 47 | // retW might already be correctly set by another line of text 48 | if(xOffset > *retW) 49 | *retW = xOffset; 50 | 51 | *retH = yOffset; 52 | } -------------------------------------------------------------------------------- /lib/src/gui/fonts/fontparser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | using namespace LIBCactusOS; 8 | 9 | Font* FontParser::FromFile(char* filename) 10 | { 11 | if(FileExists(filename) == false) 12 | return 0; 13 | 14 | uint32_t fileSize = GetFileSize(filename); 15 | if((int)fileSize == -1) 16 | return 0; 17 | 18 | uint8_t* filebuffer = new uint8_t[fileSize]; 19 | if(ReadFile(filename, filebuffer) != 0) { 20 | delete filebuffer; 21 | return 0; 22 | } 23 | 24 | 25 | // Place CFF header over buffer 26 | CFFHeader* header = (CFFHeader*)filebuffer; 27 | if(header->Magic != 0xCFF || header->Version != 1) { 28 | delete filebuffer; 29 | return 0; 30 | } 31 | 32 | Print("Parsing font %s, size = %d Points\n", (char*)(filebuffer + header->FontNameOffset), header->FontSize); 33 | 34 | Font* result = new Font(); 35 | result->data = filebuffer; 36 | result->name = (char*)(filebuffer + header->FontNameOffset); 37 | result->offsetTable = header->CharacterOffsets; 38 | result->size = header->FontSize; 39 | 40 | return result; 41 | } -------------------------------------------------------------------------------- /lib/src/gui/property.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace LIBCactusOS; 5 | 6 | void LIBCactusOS::UpdateGUIPropertyTargetGUI(Control* target) 7 | { 8 | if(target) target->ForcePaint(); 9 | } -------------------------------------------------------------------------------- /lib/src/gui/widgets/button.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace LIBCactusOS; 5 | 6 | Button::Button(char* text) 7 | : Control(80, 40) 8 | { 9 | this->label = text; 10 | this->backColor = 0xFF190A39; 11 | this->borderColor = 0xFF479BFF; 12 | this->textAlignment = { Alignment::Horizontal::Center, Alignment::Vertical::Center }; 13 | this->textColor = 0xFF479BFF; 14 | this->cornerRadius = 10; 15 | this->cornerStyle = CornerStyle::Rounded; 16 | } 17 | void Button::DrawTo(Canvas* context, int x_abs, int y_abs) 18 | { 19 | Rectangle visual = Control::GetParentsBounds(x_abs, y_abs); 20 | if(visual.Area() == 0) 21 | return; // No need to draw something if it isn't going to be visible anyway 22 | 23 | if(this->cornerStyle == CornerStyle::Rounded) { 24 | context->DrawFillRoundedRect(this->backColor, visual.x, visual.y, visual.width, visual.height, this->cornerRadius); 25 | context->DrawRoundedRect(this->borderColor, visual.x, visual.y, visual.width, visual.height, this->cornerRadius); 26 | } 27 | else if(this->cornerStyle == CornerStyle::Sharp) { 28 | context->DrawFillRect(this->backColor, visual.x, visual.y, visual.width, visual.height); 29 | context->DrawRect(this->borderColor, visual.x, visual.y, visual.width, visual.height); 30 | } 31 | 32 | if(this->label != 0) 33 | Context::DrawStringAligned(context, this->font, this->label, this->textColor, *this, this->textAlignment, x_abs, y_abs - 2); 34 | 35 | for(Control* c : this->childs) 36 | c->DrawTo(context, x_abs + c->x, y_abs + c->y); 37 | } 38 | void Button::OnMouseDown(int x_abs, int y_abs, uint8_t button) 39 | { 40 | this->backColor = 0xFF606060; 41 | Control::OnMouseDown(x_abs, y_abs, button); 42 | } 43 | void Button::OnMouseUp(int x_abs, int y_abs, uint8_t button) 44 | { 45 | this->backColor = 0xFF190A39; 46 | Control::OnMouseUp(x_abs, y_abs, button); 47 | } 48 | void Button::OnMouseEnter(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) 49 | { } 50 | void Button::OnMouseLeave(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) 51 | { } -------------------------------------------------------------------------------- /lib/src/gui/widgets/label.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace LIBCactusOS; 4 | 5 | Label::Label(char* text) 6 | : Control(80, 20) 7 | { 8 | this->text = text; 9 | } 10 | 11 | void Label::DrawTo(Canvas* context, int x_abs, int y_abs) 12 | { 13 | if(this->text) 14 | context->DrawString(this->font, this->text, x_abs + 2, y_abs + 2, this->textColor); 15 | 16 | for(Control* c : this->childs) 17 | c->DrawTo(context, x_abs + c->x, y_abs + c->y); 18 | } -------------------------------------------------------------------------------- /lib/src/gui/widgets/scrollbar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace LIBCactusOS; 5 | 6 | ScrollBar::ScrollBar(ScrollBarType type, int min, int max, int dragSize) 7 | : Control(type == Horizontal ? SCROLLBAR_DEFAULT_WIDTH : SCROLLBAR_DEFAULT_HEIGHT, type == Vertical ? SCROLLBAR_DEFAULT_WIDTH : SCROLLBAR_DEFAULT_HEIGHT) 8 | { } 9 | 10 | void ScrollBar::DrawTo(Canvas* context, int x_abs, int y_abs) 11 | { 12 | Rectangle visual = Control::GetParentsBounds(x_abs, y_abs); 13 | if(visual.Area() == 0) 14 | return; // No need to draw something if it isn't going to be visible anyway 15 | 16 | // Calculate percentage of completion 17 | double factor = (double)Math::Constrain(this->value, this->minValue, this->maxValue) / (double)(this->maxValue - this->minValue); 18 | 19 | context->DrawFillRect(this->backColor, visual.x, visual.y, visual.width, visual.height); 20 | if(this->type == Horizontal) 21 | context->DrawFillRect(this->dragColor, visual.x + (double)(this->width - this->dragSize) * factor, visual.y, this->dragSize, this->height); 22 | else 23 | context->DrawFillRect(this->dragColor, visual.x, visual.y + (double)(this->height - this->dragSize) * factor, this->width, this->dragSize); 24 | 25 | context->DrawRect(this->borderColor, visual.x, visual.y, visual.width, visual.height); 26 | } 27 | 28 | void ScrollBar::OnScroll(int32_t deltaZ, int x_abs, int y_abs) 29 | { 30 | this->value = Math::Constrain(this->value + ((double)deltaZ * this->scrollFactor), this->minValue, this->maxValue); 31 | } 32 | 33 | 34 | void ScrollBar::OnMouseDown(int x_abs, int y_abs, uint8_t button) 35 | { 36 | 37 | } 38 | 39 | void ScrollBar::OnMouseUp(int x_abs, int y_abs, uint8_t button) 40 | { 41 | 42 | } 43 | 44 | void ScrollBar::OnMouseMove(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) 45 | { 46 | 47 | } -------------------------------------------------------------------------------- /lib/src/gui/widgets/slider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace LIBCactusOS; 7 | 8 | Slider::Slider(int min, int max, int current) 9 | : Control(200, 15) 10 | { 11 | this->minValue = min; 12 | this->maxValue = max; 13 | this->position = current; 14 | } 15 | 16 | void Slider::DrawTo(Canvas* context, int x_abs, int y_abs) 17 | { 18 | Rectangle visual = Control::GetParentsBounds(x_abs, y_abs); 19 | if(visual.Area() == 0) 20 | return; // No need to draw something if it isn't going to be visible anyway 21 | 22 | context->DrawFillRect(this->backColor, visual.x, visual.y, visual.width, visual.height); 23 | context->DrawRect(this->borderColor, visual.x, visual.y, visual.width, visual.height); 24 | 25 | double percent = (double)position / (double)(this->maxValue - this->minValue); 26 | context->DrawFillCircle(this->knobColor, x_abs + (int)((double)this->width * percent), y_abs + this->height/2, this->knobSize); 27 | 28 | for(Control* c : this->childs) 29 | c->DrawTo(context, x_abs + c->x, y_abs + c->y); 30 | } 31 | 32 | void Slider::OnMouseDown(int x_abs, int y_abs, uint8_t button) 33 | { 34 | this->knobColor -= 0x00333333; 35 | this->mouseDown = true; 36 | } 37 | void Slider::OnMouseUp(int x_abs, int y_abs, uint8_t button) 38 | { 39 | this->knobColor += 0x00333333; 40 | this->mouseDown = false; 41 | } 42 | void Slider::OnMouseMove(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) 43 | { 44 | if(mouseDown) { 45 | this->position += ((double)(newX_abs - prevX_abs) / (double)this->width) * (this->maxValue - this->minValue); 46 | this->position = Math::Max(this->minValue, Math::Min(this->maxValue, this->position)); 47 | this->OnValueChanged.Invoke(this, this->position); 48 | } 49 | } 50 | void Slider::OnMouseEnter(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) 51 | { 52 | this->knobColor -= 0x00111111; 53 | } 54 | 55 | void Slider::OnMouseLeave(int prevX_abs, int prevY_abs, int newX_abs, int newY_abs) 56 | { 57 | this->knobColor += 0x00111111; 58 | } -------------------------------------------------------------------------------- /lib/src/ipc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace LIBCactusOS; 6 | 7 | int LIBCactusOS::IPCSend(int dest, int type, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5, unsigned int arg6) 8 | { 9 | //Create IPCMessage 10 | IPCMessage message; 11 | message.dest = dest; 12 | message.type = type; 13 | message.source = Process::ID; 14 | 15 | //Copy args 16 | message.arg1 = arg1; 17 | message.arg2 = arg2; 18 | message.arg3 = arg3; 19 | message.arg4 = arg4; 20 | message.arg5 = arg5; 21 | message.arg6 = arg6; 22 | 23 | return IPCSend(message); 24 | } 25 | 26 | int LIBCactusOS::IPCSend(IPCMessage message) 27 | { 28 | return DoSyscall(SYSCALL_IPC_SEND, (uint32_t)&message); 29 | } 30 | 31 | int LIBCactusOS::IPCAvailable() 32 | { 33 | return DoSyscall(SYSCALL_IPC_AVAILABLE); 34 | } 35 | 36 | IPCMessage LIBCactusOS::ICPReceive(int fromID, int* errOut, int type) 37 | { 38 | IPCMessage result; 39 | DoSyscall(SYSCALL_IPC_RECEIVE, (uint32_t)&result, fromID, (uint32_t)errOut, type); 40 | return result; 41 | } -------------------------------------------------------------------------------- /lib/src/random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace LIBCactusOS; 4 | 5 | uint32_t next = 12; 6 | 7 | int Random::Next(uint32_t max) 8 | { 9 | next = next * 1103515245 + 12345; 10 | return (unsigned int)(next / 65536) % (max+1); 11 | } 12 | 13 | int Random::Next(uint32_t min, uint32_t max) 14 | { 15 | return Next(max-min) + min; 16 | } 17 | 18 | void Random::SetSeed(uint32_t seed) 19 | { 20 | next = seed; 21 | } -------------------------------------------------------------------------------- /lib/src/syscall.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | +---+--------------------+ 5 | | r | Register(s) | 6 | +---+--------------------+ 7 | | a | %eax, %ax, %al | 8 | | b | %ebx, %bx, %bl | 9 | | c | %ecx, %cx, %cl | 10 | | d | %edx, %dx, %dl | 11 | | S | %esi, %si | 12 | | D | %edi, %di | 13 | +---+--------------------+ 14 | */ 15 | 16 | int LIBCactusOS::DoSyscall(unsigned int intNum, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5) 17 | { 18 | int a; 19 | asm volatile("int $0x80" : "=a" (a) : "0" (intNum), "b" ((int)arg1), "c" ((int)arg2), "d" ((int)arg3), "S" ((int)arg4), "D" ((int)arg5)); 20 | return a; 21 | } -------------------------------------------------------------------------------- /lib/src/time.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | using namespace LIBCactusOS; 6 | 7 | void Time::Sleep(uint32_t ms) 8 | { 9 | DoSyscall(SYSCALL_SLEEP_MS, ms); 10 | } 11 | 12 | uint64_t Time::Ticks() 13 | { 14 | uint64_t r = 0; 15 | DoSyscall(SYSCALL_GET_TICKS, (uint32_t)&r); 16 | return r; 17 | } -------------------------------------------------------------------------------- /lib/src/vfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | using namespace LIBCactusOS; 7 | 8 | bool LIBCactusOS::FileExists(char* path) 9 | { 10 | return (bool)DoSyscall(SYSCALL_FILE_EXISTS, (uint32_t)path); 11 | } 12 | uint32_t LIBCactusOS::GetFileSize(char* path) 13 | { 14 | return (uint32_t)DoSyscall(SYSCALL_GET_FILESIZE, (uint32_t)path); 15 | } 16 | int LIBCactusOS::ReadFile(char* path, uint8_t* buffer, uint32_t offset, uint32_t len) 17 | { 18 | return (int)DoSyscall(SYSCALL_READ_FILE, (uint32_t)path, (uint32_t)buffer, offset, len); 19 | } 20 | int LIBCactusOS::WriteFile(char* path, uint8_t* buffer, uint32_t len, bool create) 21 | { 22 | return (int)DoSyscall(SYSCALL_WRITE_FILE, (uint32_t)path, (uint32_t)buffer, len, (uint32_t)create); 23 | } 24 | int LIBCactusOS::CreateFile(char* path) 25 | { 26 | return (int)DoSyscall(SYSCALL_CREATE_FILE, (uint32_t)path); 27 | } 28 | int LIBCactusOS::CreateDirectory(char* path) 29 | { 30 | return (int)DoSyscall(SYSCALL_CREATE_DIRECTORY, (uint32_t)path); 31 | } 32 | bool LIBCactusOS::DirectoryExists(char* path) 33 | { 34 | return (bool)DoSyscall(SYSCALL_DIR_EXISTS, (uint32_t)path); 35 | } 36 | bool LIBCactusOS::EjectDisk(char* path) 37 | { 38 | return (bool)DoSyscall(SYSCALL_EJECT_DISK, (uint32_t)path); 39 | } 40 | List LIBCactusOS::DirectoryListing(char* path) 41 | { 42 | List result; 43 | 44 | int items = DoSyscall(SYSCALL_BEGIN_LISTING, DIRECTORY_LISTING, (uint32_t)path); 45 | if(items == -1) 46 | return result; 47 | 48 | for(int i = 0; i < items; i++) { 49 | VFSEntry entry; 50 | int strLen = DoSyscall(SYSCALL_LISTING_ENTRY, DIRECTORY_LISTING, (uint32_t)i, (uint32_t)&entry); 51 | if(strLen == 0) 52 | return result; // End of items 53 | 54 | result += entry; 55 | } 56 | DoSyscall(SYSCALL_END_LISTING, DIRECTORY_LISTING); 57 | return result; 58 | } -------------------------------------------------------------------------------- /makefile.config: -------------------------------------------------------------------------------- 1 | #OPTIMIZE_FLAGS := -O0 -msse2 2 | 3 | #OPTIMIZE_FLAGS := -O0 -msse2 4 | 5 | #OPTIMIZE_FLAGS := -O1 -msse2 6 | 7 | #OPTIMIZE_FLAGS := -O2 -msse2 8 | 9 | OPTIMIZE_FLAGS := -O3 -msse2 -------------------------------------------------------------------------------- /qemu-usb-config.cfg: -------------------------------------------------------------------------------- 1 | ########################################################################### 2 | # 3 | # You can pass this file directly to qemu using the -readconfig 4 | # command line switch. 5 | # 6 | # This config file creates a EHCI adapter with companion UHCI 7 | # controllers as multifunction device in PCI slot "1d". 8 | # 9 | # Specify "bus=ehci.0" when creating usb devices to hook them up 10 | # there. 11 | # 12 | 13 | [device "ehci"] 14 | driver = "ich9-usb-ehci1" 15 | addr = "1d.7" 16 | multifunction = "on" 17 | 18 | [device "uhci-1"] 19 | driver = "ich9-usb-uhci1" 20 | addr = "1d.0" 21 | multifunction = "on" 22 | masterbus = "ehci.0" 23 | firstport = "0" 24 | 25 | [device "uhci-2"] 26 | driver = "ich9-usb-uhci2" 27 | addr = "1d.1" 28 | multifunction = "on" 29 | masterbus = "ehci.0" 30 | firstport = "2" 31 | 32 | [device "uhci-3"] 33 | driver = "ich9-usb-uhci3" 34 | addr = "1d.2" 35 | multifunction = "on" 36 | masterbus = "ehci.0" 37 | firstport = "4" 38 | -------------------------------------------------------------------------------- /rungdb: -------------------------------------------------------------------------------- 1 | pkexec /usr/local/bin/gdb --baud 38400 "$@" 2 | --------------------------------------------------------------------------------