├── .gitignore ├── screenshots ├── boot_screen.png ├── command_showcase.png ├── filesystem_showcase.png └── kernel_panic_screen.png ├── include ├── memory.h ├── panic.h ├── power.h ├── banner.h ├── io.h ├── keyboard.h ├── shell.h ├── audio.h ├── cpu.h ├── stdlib.h ├── string.h ├── ffs.h └── vga.h ├── src ├── power.c ├── io.c ├── kernel.c ├── panic.c ├── audio.c ├── banner.c ├── memory.c ├── cpu.c ├── string.c ├── vga.c ├── ffs.c ├── stdlib.c ├── bootloader │ └── boot.asm ├── keyboard.c └── shell.c ├── linker.ld ├── README.md ├── Makefile └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore build directories 2 | build 3 | obj 4 | -------------------------------------------------------------------------------- /screenshots/boot_screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeltMacaroon389/Feltix/HEAD/screenshots/boot_screen.png -------------------------------------------------------------------------------- /screenshots/command_showcase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeltMacaroon389/Feltix/HEAD/screenshots/command_showcase.png -------------------------------------------------------------------------------- /screenshots/filesystem_showcase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeltMacaroon389/Feltix/HEAD/screenshots/filesystem_showcase.png -------------------------------------------------------------------------------- /screenshots/kernel_panic_screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FeltMacaroon389/Feltix/HEAD/screenshots/kernel_panic_screen.png -------------------------------------------------------------------------------- /include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMORY_H 2 | #define MEMORY_H 3 | 4 | char* get_accessible_memory(); 5 | 6 | #endif // MEMORY_H 7 | 8 | -------------------------------------------------------------------------------- /include/panic.h: -------------------------------------------------------------------------------- 1 | #ifndef PANIC_H 2 | #define PANIC_H 3 | 4 | void kernel_panic(const char* message); 5 | 6 | #endif // PANIC_H 7 | 8 | -------------------------------------------------------------------------------- /include/power.h: -------------------------------------------------------------------------------- 1 | #ifndef POWER_H 2 | #define POWER_H 3 | 4 | #include 5 | 6 | void reboot_system(void); 7 | 8 | #endif // POWER_H 9 | 10 | -------------------------------------------------------------------------------- /include/banner.h: -------------------------------------------------------------------------------- 1 | #ifndef BANNER_H 2 | #define BANNER_H 3 | 4 | void print_banner_white(void); 5 | void print_banner_rainbow(void); 6 | 7 | #endif // BANNER_H 8 | 9 | -------------------------------------------------------------------------------- /include/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | 4 | #include 5 | 6 | uint8_t inb(uint16_t port); 7 | void outb(uint16_t port, uint8_t data); 8 | 9 | #endif // IO_H 10 | 11 | -------------------------------------------------------------------------------- /include/keyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef KEYBOARD_H 2 | #define KEYBOARD_H 3 | 4 | #include 5 | 6 | uint8_t keyboard_get_scancode(void); 7 | char scancode_to_ascii(uint8_t scancode); 8 | char keyboard_getchar(void); 9 | 10 | #endif // KEYBOARD_H 11 | 12 | -------------------------------------------------------------------------------- /include/shell.h: -------------------------------------------------------------------------------- 1 | #ifndef SHELL_H 2 | #define SHELL_H 3 | 4 | #include 5 | 6 | void process_command(int argc, char** argv); 7 | void parse_user_input(char* input); 8 | void shell_start(const char* prompt, uint8_t color); 9 | 10 | #endif // SHELL_H 11 | 12 | -------------------------------------------------------------------------------- /include/audio.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_H 2 | #define AUDIO_H 3 | 4 | #include 5 | #include 6 | 7 | #define PIT_CHANNEL2 0x42 8 | #define PIT_COMMAND 0x43 9 | #define SPEAKER_CONTROL 0x61 10 | 11 | void beep(uint32_t frequency); 12 | void stop_beep(void); 13 | void short_beep(void); 14 | 15 | #endif // AUDIO_H 16 | 17 | -------------------------------------------------------------------------------- /include/cpu.h: -------------------------------------------------------------------------------- 1 | #ifndef CPU_H 2 | #define CPU_H 3 | 4 | #include 5 | 6 | void cpuid(int code, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d); 7 | char* get_cpu_threads(void); 8 | uint32_t cpu_supports_64bit(void); 9 | void get_cpu_vendor(char *vendor_buffer); 10 | void get_cpu_brand(char *brand_buffer); 11 | 12 | #endif // CPU_H 13 | 14 | -------------------------------------------------------------------------------- /include/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef STDLIB_H 2 | #define STDLIB_H 3 | 4 | #include 5 | 6 | float atof(const char *str); 7 | int is_valid_float(const char *str); 8 | void reverse_string(char* str, int len); 9 | int int_to_str(int num, char* str, int precision); 10 | void float_to_str(float num, char* str, int precision); 11 | 12 | #endif // STDLIB_H 13 | 14 | -------------------------------------------------------------------------------- /src/power.c: -------------------------------------------------------------------------------- 1 | // Simple power control 2 | 3 | #include 4 | 5 | #include 6 | 7 | // Trigger a hardware reboot via the PS/2 controller 8 | void reboot_system(void) { 9 | outb(0x64, 0xFE); 10 | 11 | // If that fails, try unknown instruction to force a triple fault 12 | __asm__ __volatile__("ud2"); 13 | 14 | // If that *still* doesn't work, settle with a halt 15 | __asm__ __volatile__("hlt"); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/io.c: -------------------------------------------------------------------------------- 1 | // Simple Input/Output port access 2 | 3 | #include 4 | 5 | #include 6 | 7 | // Function to read a byte from an I/O port 8 | uint8_t inb(uint16_t port) { 9 | uint8_t ret; 10 | asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port)); 11 | return ret; 12 | } 13 | 14 | // Function to write a byte to an I/O port 15 | void outb(uint16_t port, uint8_t data) { 16 | asm volatile ("outb %0, %1" : : "a"(data), "Nd"(port)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /linker.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386") 2 | ENTRY(_start) 3 | 4 | SECTIONS { 5 | . = 0x7C00; /* Start at 0x7C00, where the BIOS expects it */ 6 | 7 | .text : { 8 | *(.bootloader) 9 | *(.text) 10 | } :text 11 | 12 | .rodata : { 13 | *(.rodata) 14 | } :text 15 | 16 | .data : { 17 | *(.data) 18 | } :data 19 | 20 | .bss : { 21 | *(.bss) 22 | *(COMMON) 23 | } :data 24 | } 25 | 26 | /* Define program headers with permissions */ 27 | PHDRS { 28 | text PT_LOAD FLAGS(0x5); /* Read + Execute */ 29 | data PT_LOAD FLAGS(0x6); /* Read + Write */ 30 | } 31 | 32 | -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H 2 | #define STRING_H 3 | 4 | #include 5 | 6 | char* strchr(const char* str, int c); 7 | size_t strlen(const char* str); 8 | void memcpy(char* dest, const char* src, size_t n); 9 | void* memset(void* ptr, int value, size_t num); 10 | int memcmp(const void* ptr1, const void* ptr2, size_t num); 11 | int strcmp(const char* str1, const char* str2); 12 | int strncmp(const char* s1, const char* s2, size_t n); 13 | char* strtok(char* str, const char* delim); 14 | char* strcat(char* dest, const char* src); 15 | 16 | #endif // STRING_H 17 | 18 | -------------------------------------------------------------------------------- /src/kernel.c: -------------------------------------------------------------------------------- 1 | // --- FELTIX KERNEL --- 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // Kernel main function 9 | void kernel_main() { 10 | 11 | // Clear the screen 12 | clear_screen(); 13 | 14 | // Print white ASCII art banner 15 | print_banner_white(); 16 | 17 | // Print credits 18 | print_string("\n By ", VGA_COLOR_WHITE); 19 | print_string("FeltMacaroon389", VGA_COLOR_LIGHT_GREY); 20 | 21 | // Print welcome message 22 | print_string("\n\n Welcome to ", VGA_COLOR_WHITE); 23 | print_string("Feltix!\n", VGA_COLOR_LIGHT_GREEN); 24 | 25 | print_string(" Type ", VGA_COLOR_WHITE); 26 | print_string("help", VGA_COLOR_CYAN); 27 | print_string(" for a list of commands!\n\n", VGA_COLOR_WHITE); 28 | 29 | // Hand off control to the shell 30 | shell_start("Feltix> ", VGA_COLOR_LIGHT_GREEN); 31 | 32 | // Trigger a kernel panic when there's nothing to do 33 | kernel_panic("KernelHasReturned"); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/panic.c: -------------------------------------------------------------------------------- 1 | // Kernel panic handling 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // Function to trigger a kernel panic with a custom message 11 | void kernel_panic(const char* message) { 12 | 13 | clear_screen(); 14 | 15 | // Default banner obtained from: https://ascii.co.uk/art/skulls 16 | print_string(" _____ \n", VGA_COLOR_LIGHT_RED); 17 | print_string(" / \\ \n", VGA_COLOR_LIGHT_RED); 18 | print_string(" | () () | \n", VGA_COLOR_LIGHT_RED); 19 | print_string(" \\ ^ / \n", VGA_COLOR_LIGHT_RED); 20 | print_string(" ||||| \n", VGA_COLOR_LIGHT_RED); 21 | print_string(" ||||| \n", VGA_COLOR_LIGHT_RED); 22 | 23 | print_string("\n KERNEL PANIC: ", VGA_COLOR_RED); 24 | print_string(message, VGA_COLOR_LIGHT_BLUE); 25 | 26 | print_string("\n\n Press any key to reboot...", VGA_COLOR_WHITE); 27 | 28 | // Short beep to get the user's attention 29 | short_beep(); 30 | 31 | // Wait for keypress 32 | keyboard_getchar(); 33 | 34 | // Reboot 35 | reboot_system(); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /include/ffs.h: -------------------------------------------------------------------------------- 1 | #ifndef FFS_H 2 | #define FFS_H 3 | 4 | #include 5 | #include 6 | 7 | #define FFS_MAX_FILES 128 8 | #define FFS_MAX_FILENAME_LENGTH 64 9 | #define FFS_MAX_FILE_SIZE 4096 // 4KB 10 | 11 | // Error Codes 12 | #define FFS_SUCCESS 0 13 | #define FFS_FILE_EXISTS -1 14 | #define FFS_NO_SPACE -2 15 | #define FFS_FILE_NOT_FOUND -3 16 | #define FFS_INVALID_NAME -4 17 | #define FFS_SIZE_EXCEEDS_LIMIT -5 18 | #define FFS_BUFFER_TOO_SMALL -6 19 | #define FFS_INVALID_OPERATION -8 20 | 21 | // File structure 22 | typedef struct { 23 | char name[FFS_MAX_FILENAME_LENGTH]; 24 | char data[FFS_MAX_FILE_SIZE]; 25 | size_t size; 26 | int is_used; 27 | } File; 28 | 29 | // Filesystem structure 30 | typedef struct { 31 | File files[FFS_MAX_FILES]; 32 | } FeltFileSystem; 33 | 34 | extern FeltFileSystem fs; 35 | 36 | int ffs_create_file(const char *name); 37 | int ffs_delete_file(const char *name); 38 | int ffs_write_file(const char *name, const char *data); 39 | int ffs_read_file(const char *name, char *buffer, size_t buffer_size); 40 | int ffs_are_files_present(void); 41 | void ffs_list_files(void); 42 | 43 | #endif // FFS_H 44 | 45 | -------------------------------------------------------------------------------- /include/vga.h: -------------------------------------------------------------------------------- 1 | #ifndef VGA_H 2 | #define VGA_H 3 | 4 | #include 5 | #include 6 | 7 | #define VGA_WIDTH 80 8 | #define VGA_HEIGHT 25 9 | #define VGA_MEMORY ((uint16_t*)0xB8000) 10 | 11 | static uint16_t* const vga_buffer = VGA_MEMORY; 12 | static size_t cursor_row = 0; 13 | static size_t cursor_column = 0; 14 | 15 | // Define VGA colors 16 | typedef enum { 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 | } vga_color; 34 | 35 | uint16_t vga_entry(unsigned char uc, vga_color color); 36 | 37 | void clear_screen(void); 38 | void scroll(void); 39 | void update_cursor(size_t row, size_t col); 40 | void print_char(char c, vga_color color); 41 | void print_string(const char* str, vga_color color); 42 | void shell_backspace(void); 43 | 44 | #endif // VGA_H 45 | 46 | -------------------------------------------------------------------------------- /src/audio.c: -------------------------------------------------------------------------------- 1 | // Basic PC speaker driver 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | // Function to beep the PC speaker at a frequency in MHz 9 | void beep(uint32_t frequency) { 10 | 11 | // Refuse to beep at 0MHz, to prevent a division by zero 12 | if (frequency == 0) { 13 | return; 14 | } 15 | 16 | uint32_t divisor = 1193180 / frequency; 17 | 18 | // Set PIT channel 2 to square wave mode (mode 3) 19 | outb(PIT_COMMAND, 0xB6); // 1011 0110 20 | outb(PIT_CHANNEL2, divisor & 0xFF); // Low byte 21 | outb(PIT_CHANNEL2, (divisor >> 8) & 0xFF); // High byte 22 | 23 | // Read speaker control 24 | uint8_t tmp = inb(SPEAKER_CONTROL); 25 | 26 | // Enable speaker (bits 0 and 1) 27 | if ((tmp & 3) != 3) { 28 | outb(SPEAKER_CONTROL, tmp | 3); 29 | } 30 | } 31 | 32 | // Function to stop beeping 33 | void stop_beep(void) { 34 | uint8_t tmp = inb(SPEAKER_CONTROL) & 0xFC; 35 | outb(SPEAKER_CONTROL, tmp); // Clear bits 0 and 1 36 | } 37 | 38 | // Function to execute a quick short beep 39 | void short_beep(void) { 40 | // Beep to alert the user 41 | beep(1000); 42 | 43 | // Short delay, as this executes absurdly fast 44 | int delay = 0; 45 | while (delay < 3000000) { 46 | delay++; 47 | } 48 | 49 | // Stop beeping 50 | stop_beep(); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/banner.c: -------------------------------------------------------------------------------- 1 | // Basic ASCII art banner display control 2 | 3 | #include 4 | 5 | #include 6 | 7 | // Banner lines definitions 8 | // Default banner generated with: https://www.asciiart.eu/text-to-ascii-art 9 | const char* banner_line_1 = " _____ _ _ _ \n"; 10 | const char* banner_line_2 = " | ___|__| | |_(_)_ __ \n"; 11 | const char* banner_line_3 = " | |_ / _ \\ | __| \\ \\/ / \n"; 12 | const char* banner_line_4 = " | _| __/ | |_| |> < \n"; 13 | const char* banner_line_5 = " |_| \\___|_|\\__|_/_/\\_\\ \n"; 14 | 15 | // Print all-white banner 16 | void print_banner_white(void) { 17 | print_string(banner_line_1, VGA_COLOR_WHITE); 18 | print_string(banner_line_2, VGA_COLOR_WHITE); 19 | print_string(banner_line_3, VGA_COLOR_WHITE); 20 | print_string(banner_line_4, VGA_COLOR_WHITE); 21 | print_string(banner_line_5, VGA_COLOR_WHITE); 22 | } 23 | 24 | // Print rainbow banner 25 | void print_banner_rainbow(void) { 26 | print_string(banner_line_1, VGA_COLOR_RED); 27 | print_string(banner_line_2, VGA_COLOR_LIGHT_RED); 28 | print_string(banner_line_3, VGA_COLOR_GREEN); 29 | print_string(banner_line_4, VGA_COLOR_BLUE); 30 | print_string(banner_line_5, VGA_COLOR_MAGENTA); 31 | } 32 | 33 | 34 | /* Please feel free to request other options or color patterns 35 | * To do so, open an issue or pull request on the project's GitHub: 36 | * https://github.com/FeltMacaroon389/Feltix 37 | */ 38 | 39 | -------------------------------------------------------------------------------- /src/memory.c: -------------------------------------------------------------------------------- 1 | // For memory/RAM related information and functionality 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | // Function that returns the amount of accessible memory in megabytes (MB) 10 | char* get_accessible_memory() { 11 | uint32_t total_memory_bytes = 0; 12 | uint32_t memory_block_size = 1024 * 1024; // Check in 1MB increments 13 | uint32_t current_address = 0; 14 | 15 | while (1) { 16 | volatile uint32_t *ptr = (uint32_t *)current_address; 17 | 18 | // Try accessing the memory block 19 | uint32_t original_value; 20 | uint32_t test_value = 0xA5A5A5A5; 21 | 22 | // Test read and write access 23 | __asm__ volatile("" ::: "memory"); // Compiler barrier 24 | original_value = *ptr; // Read the original value 25 | *ptr = test_value; // Attempt to write a test value 26 | 27 | // Check if the write succeeded 28 | if (*ptr == test_value) { 29 | total_memory_bytes += memory_block_size; // Memory is accessible 30 | *ptr = original_value; // Restore original value 31 | } else { 32 | break; // Stop if memory is inaccessible 33 | } 34 | 35 | current_address += memory_block_size; // Move to the next block 36 | } 37 | 38 | // Convert bytes to MB 39 | uint32_t total_memory_mb = total_memory_bytes / (1024 * 1024); 40 | 41 | // Convert the total memory to a string and return it 42 | static char memory_str[16]; 43 | int_to_str(total_memory_mb, memory_str, 0); 44 | 45 | return memory_str; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Feltix 2 | 3 | Feltix is an operating system written in C, with the primary focus on simplicity, modularity, and usablility. 4 | Feltix is not intended for production use. 5 | 6 | --- 7 | 8 | ![Feltix boot screen](screenshots/boot_screen.png) 9 | 10 | ### Feltix currently supports the following hardware: 11 | - i386 (x86) or AMD64 (x86_64) CPU 12 | - Depending on the firmware, around 3 gigabytes of RAM 13 | - BIOS firmware (not EFI/UEFI) 14 | - Standard PS/2 and USB keyboards (US layout) 15 | - 16-color 80*25 VGA text mode display 16 | - Standard PC speaker/beeper 17 | 18 | **MORE TO COME** 19 | 20 | --- 21 | 22 | ### Build instructions 23 | 24 | - Install dependencies (see below). 25 | 26 | - Clone the repository: `git clone https://github.com/FeltMacaroon389/Feltix.git` 27 | 28 | - Build with: `make` 29 | 30 | For a list of Make commands and targets, run: `make help` 31 | 32 | The output image will be located in the `build` directory. 33 | 34 | ### Dependency installation 35 | 36 | #### **Required**: 37 | 38 | **Arch Linux**: 39 | - Run: `sudo pacman -Sy git nasm make` 40 | - You will also require **GNU GCC** for the **i386** CPU architecture. 41 | 42 | - First, we need [i386-elf-binutils](https://aur.archlinux.org/packages/i386-elf-binutils) 43 | - Do: `git clone https://aur.archlinux.org/i386-elf-binutils.git` 44 | - Next, `cd i386-elf-binutils` 45 | - Finally, `makepkg -si` 46 | - You may be prompted for your password during this. 47 | 48 | - As for [i386-elf-gcc](https://aur.archlinux.org/packages/i386-elf-gcc) 49 | - Run: `git clone https://aur.archlinux.org/i386-elf-gcc.git` 50 | - Next, `cd i386-elf-gcc` 51 | - Finally, `makepkg -si` 52 | - You may be prompted for your password during this. 53 | 54 | **Debian/Ubuntu**: 55 | - Run: `sudo apt update && sudo apt install git nasm make` 56 | - You will also require **GNU GCC** for the **i386** CPU architecture. I suggest you follow [this guide](https://wiki.osdev.org/GCC_Cross-Compiler) 57 | 58 | #### **Optional**: 59 | 60 | **Arch Linux**: 61 | - Run: `sudo pacman -Sy qemu-full` 62 | 63 | **Debian/Ubuntu**: 64 | - Run: `sudo apt update && sudo apt install qemu` 65 | 66 | ## License 67 | Feltix is licensed under the **GNU GPLv3** license. A copy of this license can be found at `LICENSE` -------------------------------------------------------------------------------- /src/cpu.c: -------------------------------------------------------------------------------- 1 | // For CPU-related information and functionality 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | // Helper function for CPUID 9 | void cpuid(int code, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) { 10 | __asm__ volatile("cpuid" 11 | : "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d) 12 | : "a"(code), "c"(0)); 13 | } 14 | 15 | // Function that returns the number of accessible CPU threads 16 | char* get_cpu_threads(void) { 17 | static char threads_str[16]; 18 | uint32_t eax, ebx, ecx, edx; 19 | 20 | // Call CPUID to get the number of threads 21 | cpuid(0x1, &eax, &ebx, &ecx, &edx); 22 | 23 | // Extract number of logical processors (threads) from bits 23:16 in EBX register 24 | uint32_t cpu_threads = (ebx >> 16) & 0xFF; 25 | 26 | // If 0, set to 1 27 | if (cpu_threads == 0) { 28 | cpu_threads = 1; 29 | } 30 | 31 | // Convert the number of threads to a string and return it 32 | int_to_str(cpu_threads, threads_str, 0); 33 | 34 | return threads_str; 35 | } 36 | 37 | // Function to check if the CPU supports 64-bit 38 | uint32_t cpu_supports_64bit(void) { 39 | uint32_t eax, ebx, ecx, edx; 40 | 41 | // Check CPUID for 64-bit mode support 42 | cpuid(0x80000001, &eax, &ebx, &ecx, &edx); 43 | 44 | // Check bit 29 of EDX for 64-bit support 45 | uint32_t is_64bit_supported = (edx >> 29) & 1; 46 | 47 | return is_64bit_supported; 48 | } 49 | 50 | // Function to get the CPU manufacturer/vendor 51 | void get_cpu_vendor(char *vendor_buffer) { 52 | uint32_t eax, ebx, ecx, edx; 53 | 54 | cpuid(0, &eax, &ebx, &ecx, &edx); 55 | 56 | // The vendor string is stored in EBX, EDX, ECX in that order 57 | *(uint32_t *)(vendor_buffer + 0) = ebx; 58 | *(uint32_t *)(vendor_buffer + 4) = edx; 59 | *(uint32_t *)(vendor_buffer + 8) = ecx; 60 | vendor_buffer[12] = '\0'; // Null-terminate string 61 | } 62 | 63 | // Function to get the CPU brand (name) 64 | void get_cpu_brand(char *brand_buffer) { 65 | uint32_t *brand_u = (uint32_t*)brand_buffer; 66 | 67 | cpuid(0x80000002, &brand_u[0], &brand_u[1], &brand_u[2], &brand_u[3]); 68 | cpuid(0x80000003, &brand_u[4], &brand_u[5], &brand_u[6], &brand_u[7]); 69 | cpuid(0x80000004, &brand_u[8], &brand_u[9], &brand_u[10], &brand_u[11]); 70 | 71 | brand_buffer[48] = '\0'; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Feltix Makefile 2 | 3 | # Tools 4 | AS = nasm 5 | CC = i386-elf-gcc 6 | LD = i386-elf-ld 7 | OBJCOPY = i386-elf-objcopy 8 | 9 | # Parameters 10 | ASFLAGS = -f elf32 11 | CCFLAGS = -nostdlib -ffreestanding -std=gnu99 -T linker.ld -I./include 12 | LDFLAGS = -T linker.ld 13 | OBJCOPYFLAGS = -O binary 14 | 15 | # Directories 16 | SRC_DIR = src 17 | OBJ_DIR = obj 18 | BUILD_DIR = build 19 | 20 | # C source files to compile 21 | SRC_C := $(wildcard $(SRC_DIR)/*.c) 22 | 23 | # C objects after compilation 24 | OBJ_C := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC_C)) 25 | 26 | # Output image name 27 | OUT_IMG = feltix.img 28 | 29 | # Emulator and flags 30 | EMU = qemu-system-i386 31 | EMUFLAGS = -drive format=raw,file=$(BUILD_DIR)/$(OUT_IMG) -smp 2 -m 64M -audiodev pa,id=speaker -machine pcspk-audiodev=speaker 32 | 33 | # Device to flash image to with "flash" target 34 | # IMPORTANT: All data on this device will be LOST! 35 | # Make sure this is fine before proceeding 36 | FLASH_DEV = /dev/sda 37 | 38 | # Phony targets 39 | .PHONY: all help run flash clean 40 | 41 | # By default, build the image 42 | all: $(OUT_IMG) 43 | 44 | # Display help about this Makefile and its options 45 | help: 46 | @echo "Usage: make " 47 | @echo " " 48 | @echo "Targets:" 49 | @echo " - same as $(OUT_IMG)" 50 | @echo " help - Display this help menu" 51 | @echo " $(OUT_IMG) - Compile the final output image" 52 | @echo " run - Compile the image and run it in an emulator (QEMU by default)" 53 | @echo " flash - flash the image to a storage medium (currently $(FLASH_DEV))" 54 | @echo " clean - Remove build files" 55 | @echo " " 56 | 57 | # Build the image 58 | $(OUT_IMG): $(OBJ_C) 59 | mkdir -p $(OBJ_DIR) $(BUILD_DIR) 60 | 61 | $(AS) $(ASFLAGS) $(SRC_DIR)/bootloader/boot.asm -o $(OBJ_DIR)/boot.o 62 | $(LD) $(LDFLAGS) $(OBJ_C) $(OBJ_DIR)/boot.o -o $(BUILD_DIR)/kernel.elf 63 | 64 | $(OBJCOPY) $(OBJCOPYFLAGS) $(BUILD_DIR)/kernel.elf $(BUILD_DIR)/$(OUT_IMG) 65 | 66 | # Compile C source files 67 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) 68 | $(CC) $(CCFLAGS) -c $< -o $@ 69 | 70 | # Create obj directory if missing 71 | $(OBJ_DIR): 72 | mkdir -p $(OBJ_DIR) 73 | 74 | # Run the image in an emulator 75 | run: $(OUT_IMG) 76 | $(EMU) $(EMUFLAGS) 77 | 78 | flash: $(OUT_IMG) 79 | dd if=$(BUILD_DIR)/$(OUT_IMG) of=$(FLASH_DEV) status=progress oflag=sync 80 | sync 81 | eject $(FLASH_DEV) 82 | 83 | @echo -e "\n$(OUT_IMG) successfully flashed to $(FLASH_DEV)!" 84 | @echo "You may now safely remove your device" 85 | 86 | # Clean build files 87 | clean: 88 | rm -rf $(OBJ_DIR) $(BUILD_DIR) 89 | 90 | -------------------------------------------------------------------------------- /src/string.c: -------------------------------------------------------------------------------- 1 | // Basic string manipulation library 2 | 3 | #include 4 | 5 | #include 6 | 7 | // Minimal implementation of strchr 8 | char* strchr(const char* str, int c) { 9 | while (*str) { 10 | if (*str == (char)c) { 11 | return (char*)str; 12 | } 13 | str++; 14 | } 15 | 16 | return NULL; 17 | } 18 | 19 | // Minimal implementation of strlen 20 | size_t strlen(const char* str) { 21 | size_t len = 0; 22 | while (str[len] != '\0') { 23 | len++; 24 | } 25 | 26 | return len; 27 | } 28 | 29 | // Minimal implementation of memcpy 30 | void memcpy(char* dest, const char* src, size_t n) { 31 | for (size_t i = 0; i < n; i++) { 32 | dest[i] = src[i]; 33 | } 34 | } 35 | 36 | // Minimal implementation of memset 37 | void* memset(void* ptr, int value, size_t num) { 38 | unsigned char* p = (unsigned char*)ptr; 39 | for (size_t i = 0; i < num; i++) { 40 | p[i] = (unsigned char)value; 41 | } 42 | 43 | return ptr; 44 | } 45 | 46 | // Minimal implementation of memcmp 47 | int memcmp(const void* ptr1, const void* ptr2, size_t num) { 48 | const unsigned char* p1 = (const unsigned char*)ptr1; 49 | const unsigned char* p2 = (const unsigned char*)ptr2; 50 | 51 | for (size_t i = 0; i < num; i++) { 52 | if (p1[i] != p2[i]) { 53 | return p1[i] - p2[i]; 54 | } 55 | } 56 | 57 | return 0; 58 | } 59 | 60 | // Minimal implementation of strcmp 61 | int strcmp(const char* str1, const char* str2) { 62 | while (*str1 && (*str1 == *str2)) { 63 | str1++; 64 | str2++; 65 | } 66 | 67 | return *(unsigned char*)str1 - *(unsigned char*)str2; 68 | } 69 | 70 | // Minimal implementation of strncmp 71 | int strncmp(const char* s1, const char* s2, size_t n) { 72 | for (size_t i = 0; i < n; i++) { 73 | if (s1[i] != s2[i]) { 74 | return (unsigned char)s1[i] - (unsigned char)s2[i]; 75 | } 76 | if (s1[i] == '\0') { 77 | return 0; 78 | } 79 | } 80 | 81 | return 0; 82 | } 83 | 84 | // Minimal implementation of strtok 85 | char* strtok(char* str, const char* delim) { 86 | static char* last; 87 | if (str == NULL) { 88 | str = last; 89 | } 90 | 91 | if (str == NULL) { 92 | return NULL; 93 | } 94 | 95 | // Skip leading delimiters 96 | while (*str && strchr(delim, *str)) { 97 | str++; 98 | } 99 | 100 | if (*str == '\0') { 101 | return NULL; 102 | } 103 | 104 | char* token = str; 105 | 106 | // Find the end of the token 107 | while (*str && !strchr(delim, *str)) { 108 | str++; 109 | } 110 | 111 | if (*str) { 112 | *str = '\0'; 113 | last = str + 1; 114 | 115 | } else { 116 | last = NULL; 117 | } 118 | 119 | return token; 120 | } 121 | 122 | // Minimal implementation of strcat 123 | char* strcat(char* dest, const char* src) { 124 | char* original = dest; 125 | 126 | // Move to the end of dest string 127 | while (*dest) { 128 | dest++; 129 | } 130 | 131 | // Copy src to the end of dest 132 | while (*src) { 133 | *dest++ = *src++; 134 | } 135 | 136 | *dest = '\0'; // Null-terminate the result 137 | 138 | return original; 139 | } 140 | 141 | -------------------------------------------------------------------------------- /src/vga.c: -------------------------------------------------------------------------------- 1 | // Basic VGA text mode driver 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | // Helper: Create a VGA entry from a character and color 9 | uint16_t vga_entry(unsigned char uc, vga_color color) { 10 | return (uint16_t) uc | (uint16_t) (color << 8); 11 | } 12 | 13 | // Function to clear the screen and reset the cursor 14 | void clear_screen(void) { 15 | for (size_t y = 0; y < VGA_HEIGHT; y++) { 16 | for (size_t x = 0; x < VGA_WIDTH; x++) { 17 | const size_t index = y * VGA_WIDTH + x; 18 | vga_buffer[index] = vga_entry(' ', VGA_COLOR_BLACK); // Fill the screen with black spaces 19 | } 20 | } 21 | 22 | // Reset the cursor 23 | cursor_row = 0; 24 | cursor_column = 0; 25 | } 26 | 27 | // Function to scroll the VGA screen by one line 28 | void scroll(void) { 29 | // Move each row up one row 30 | for (size_t row = 1; row < VGA_HEIGHT; row++) { 31 | for (size_t col = 0; col < VGA_WIDTH; col++) { 32 | VGA_MEMORY[(row - 1) * VGA_WIDTH + col] = VGA_MEMORY[row * VGA_WIDTH + col]; 33 | } 34 | } 35 | // Clear the last row 36 | for (size_t col = 0; col < VGA_WIDTH; col++) { 37 | VGA_MEMORY[(VGA_HEIGHT - 1) * VGA_WIDTH + col] = vga_entry(' ', VGA_COLOR_BLACK); 38 | } 39 | } 40 | 41 | // Function to update the hardware cursor 42 | void update_cursor(size_t row, size_t col) { 43 | uint16_t pos = row * VGA_WIDTH + col; 44 | 45 | outb(0x3D4, 0x0F); // Low byte of cursor 46 | outb(0x3D5, (uint8_t)(pos & 0xFF)); 47 | outb(0x3D4, 0x0E); // High byte of cursor 48 | outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF)); 49 | } 50 | 51 | // Print a single character with the specified color 52 | void print_char(char c, vga_color color) { 53 | if (c == '\n') { 54 | cursor_column = 0; 55 | cursor_row++; 56 | } else { 57 | const size_t index = cursor_row * VGA_WIDTH + cursor_column; 58 | vga_buffer[index] = vga_entry((unsigned char)c, color); 59 | cursor_column++; 60 | if (cursor_column >= VGA_WIDTH) { 61 | cursor_column = 0; 62 | cursor_row++; 63 | } 64 | } 65 | 66 | if (cursor_row >= VGA_HEIGHT) { 67 | scroll(); 68 | cursor_row = VGA_HEIGHT - 1; 69 | } 70 | 71 | update_cursor(cursor_row, cursor_column); 72 | } 73 | 74 | // Print a string with the specified color 75 | void print_string(const char* str, vga_color color) { 76 | while (*str) { 77 | if (*str == '\n') { 78 | cursor_column = 0; 79 | cursor_row++; 80 | } else { 81 | const size_t index = cursor_row * VGA_WIDTH + cursor_column; 82 | vga_buffer[index] = vga_entry((unsigned char)*str, color); 83 | cursor_column++; 84 | if (cursor_column >= VGA_WIDTH) { 85 | cursor_column = 0; 86 | cursor_row++; 87 | } 88 | } 89 | if (cursor_row >= VGA_HEIGHT) { 90 | scroll(); 91 | cursor_row = VGA_HEIGHT - 1; 92 | } 93 | str++; 94 | } 95 | 96 | update_cursor(cursor_row, cursor_column); 97 | } 98 | 99 | // Simple helper to handle a backspace in shell 100 | void shell_backspace(void) { 101 | if (cursor_column > 0) { 102 | cursor_column--; 103 | 104 | } else if (cursor_row > 0) { 105 | cursor_row--; 106 | cursor_column = VGA_WIDTH - 1; 107 | } 108 | 109 | VGA_MEMORY[cursor_row * VGA_WIDTH + cursor_column] = vga_entry(' ', VGA_COLOR_BLACK); 110 | } 111 | -------------------------------------------------------------------------------- /src/ffs.c: -------------------------------------------------------------------------------- 1 | // FFS (Felt File-System) 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | FeltFileSystem fs; 11 | 12 | // Create a file 13 | int ffs_create_file(const char *name) { 14 | if (strlen(name) >= FFS_MAX_FILENAME_LENGTH) { 15 | return FFS_INVALID_NAME; 16 | } 17 | 18 | for (int i = 0; i < FFS_MAX_FILES; i++) { 19 | if (fs.files[i].is_used && strcmp(fs.files[i].name, name) == 0) { 20 | return FFS_FILE_EXISTS; 21 | } 22 | } 23 | 24 | for (int i = 0; i < FFS_MAX_FILES; i++) { 25 | if (!fs.files[i].is_used) { 26 | fs.files[i].is_used = 1; 27 | memcpy(fs.files[i].name, name, strlen(name)); 28 | fs.files[i].name[strlen(name)] = '\0'; 29 | fs.files[i].size = 0; 30 | 31 | // Clear any residual data 32 | for (size_t j = 0; j < FFS_MAX_FILE_SIZE; j++) { 33 | fs.files[i].data[j] = '\0'; 34 | } 35 | 36 | return FFS_SUCCESS; 37 | } 38 | } 39 | 40 | return FFS_NO_SPACE; 41 | } 42 | 43 | 44 | // Delete a file 45 | int ffs_delete_file(const char *name) { 46 | for (int i = 0; i < FFS_MAX_FILES; i++) { 47 | if (fs.files[i].is_used && strcmp(fs.files[i].name, name) == 0) { 48 | fs.files[i].is_used = 0; 49 | fs.files[i].size = 0; 50 | 51 | for (int j = 0; j < FFS_MAX_FILENAME_LENGTH; j++) { 52 | fs.files[i].name[j] = '\0'; 53 | } 54 | for (int j = 0; j < FFS_MAX_FILE_SIZE; j++) { 55 | fs.files[i].data[j] = '\0'; 56 | } 57 | 58 | return FFS_SUCCESS; 59 | } 60 | } 61 | 62 | return FFS_FILE_NOT_FOUND; 63 | } 64 | 65 | // Write data to a file 66 | int ffs_write_file(const char *name, const char *data) { 67 | size_t data_length = strlen(data); 68 | 69 | if (data_length > FFS_MAX_FILE_SIZE) { 70 | return FFS_SIZE_EXCEEDS_LIMIT; 71 | } 72 | 73 | for (int i = 0; i < FFS_MAX_FILES; i++) { 74 | if (fs.files[i].is_used && strcmp(fs.files[i].name, name) == 0) { 75 | // Clear the buffer before writing to avoid leftover data 76 | memset(fs.files[i].data, 0, FFS_MAX_FILE_SIZE); 77 | 78 | memcpy(fs.files[i].data, data, data_length); 79 | fs.files[i].size = data_length; 80 | return FFS_SUCCESS; 81 | } 82 | } 83 | 84 | return FFS_FILE_NOT_FOUND; 85 | } 86 | 87 | 88 | // Read data from a file 89 | int ffs_read_file(const char *name, char *buffer, size_t buffer_size) { 90 | for (int i = 0; i < FFS_MAX_FILES; i++) { 91 | if (fs.files[i].is_used && strcmp(fs.files[i].name, name) == 0) { 92 | size_t file_size = fs.files[i].size; 93 | 94 | if (buffer_size < file_size + 1) { 95 | return FFS_BUFFER_TOO_SMALL; 96 | } 97 | 98 | memcpy(buffer, fs.files[i].data, file_size); 99 | buffer[file_size] = '\0'; 100 | return (int)file_size; 101 | } 102 | } 103 | return FFS_FILE_NOT_FOUND; 104 | } 105 | 106 | // Check if there are any files present in the filesystem 107 | int ffs_are_files_present(void) { 108 | for (int i = 0; i < FFS_MAX_FILES; i++) { 109 | if (fs.files[i].is_used) { 110 | return 1; // There is at least one file 111 | } 112 | } 113 | 114 | return 0; // No files present 115 | } 116 | 117 | // List all files (print to VGA) 118 | void ffs_list_files(void) { 119 | if (ffs_are_files_present() == 1) { 120 | 121 | for (int i = 0; i < FFS_MAX_FILES; i++) { 122 | if (fs.files[i].is_used) { 123 | print_string(fs.files[i].name, VGA_COLOR_LIGHT_GREY); 124 | print_string(" ", VGA_COLOR_BLACK); 125 | } 126 | } 127 | 128 | print_string("\n", VGA_COLOR_BLACK); 129 | } 130 | } 131 | 132 | -------------------------------------------------------------------------------- /src/stdlib.c: -------------------------------------------------------------------------------- 1 | // Minimal standard C library 2 | 3 | #include 4 | 5 | #include 6 | 7 | // Custom atof function as inline 8 | float atof(const char *str) { 9 | float result = 0.0f; 10 | float divisor = 1.0f; 11 | int sign = 1; 12 | 13 | // Handle leading whitespace 14 | while (*str == ' ') { 15 | str++; 16 | } 17 | 18 | // Handle optional sign 19 | if (*str == '-') { 20 | sign = -1; 21 | str++; 22 | } else if (*str == '+') { 23 | str++; 24 | } 25 | 26 | // Process integer part 27 | while (*str >= '0' && *str <= '9') { 28 | result = result * 10.0f + (*str - '0'); 29 | str++; 30 | } 31 | 32 | // Process fractional part 33 | if (*str == '.') { 34 | str++; 35 | while (*str >= '0' && *str <= '9') { 36 | result = result * 10.0f + (*str - '0'); 37 | divisor *= 10.0f; 38 | str++; 39 | } 40 | } 41 | 42 | return sign * result / divisor; 43 | } 44 | 45 | // Function to check if a string can be can be converted to a float 46 | int is_valid_float(const char *str) { 47 | const char *p = str; 48 | if (p == 0) { 49 | return 1; 50 | } 51 | 52 | while (*p == ' ' || *p == '\t' || *p == '\n' || 53 | *p == '\r' || *p == '\f' || *p == '\v') { 54 | p++; 55 | } 56 | 57 | if (*p == '+' || *p == '-') { 58 | p++; 59 | } 60 | 61 | int has_digits = 0; 62 | while (*p >= '0' && *p <= '9') { 63 | has_digits = 1; 64 | p++; 65 | } 66 | 67 | if (*p == '.') { 68 | p++; 69 | while (*p >= '0' && *p <= '9') { 70 | has_digits = 1; 71 | p++; 72 | } 73 | } 74 | 75 | if (!has_digits) { 76 | return 1; 77 | } 78 | 79 | if (*p == 'e' || *p == 'E') { 80 | p++; 81 | if (*p == '+' || *p == '-') { 82 | p++; 83 | } 84 | 85 | int exp_digits = 0; 86 | while (*p >= '0' && *p <= '9') { 87 | exp_digits = 1; 88 | p++; 89 | } 90 | 91 | if (!exp_digits) { 92 | return 1; 93 | } 94 | } 95 | 96 | while (*p == ' ' || *p == '\t' || *p == '\n' || 97 | *p == '\r' || *p == '\f' || *p == '\v') { 98 | p++; 99 | } 100 | 101 | return *p != '\0'; 102 | } 103 | 104 | // Function to reverse a string 105 | void reverse_string(char* str, int len) { 106 | int i = 0, j = len - 1; 107 | while (i < j) { 108 | char temp = str[i]; 109 | str[i] = str[j]; 110 | str[j] = temp; 111 | i++; 112 | j--; 113 | } 114 | } 115 | 116 | // Function to convert an integer to a string 117 | int int_to_str(int num, char* str, int precision) { 118 | int i = 0; 119 | if (num == 0) { 120 | str[i++] = '0'; 121 | } else { 122 | while (num) { 123 | str[i++] = (num % 10) + '0'; 124 | num /= 10; 125 | } 126 | } 127 | 128 | // Reverse the string since we build it backwards 129 | reverse_string(str, i); 130 | str[i] = '\0'; 131 | return i; 132 | } 133 | 134 | // Function to convert a float to a string 135 | void float_to_str(float num, char* str, int precision) { 136 | // Handle sign 137 | int i = 0; 138 | if (num < 0) { 139 | str[i++] = '-'; 140 | num = -num; 141 | } 142 | 143 | // Extract integer part 144 | int int_part = (int)num; 145 | 146 | // Extract fractional part 147 | float frac_part = num - (float)int_part; 148 | 149 | // Convert integer part to string 150 | i += int_to_str(int_part, str + i, 0); 151 | 152 | // Add decimal point 153 | str[i++] = '.'; 154 | 155 | // Process fractional part 156 | for (int p = 0; p < precision; p++) { 157 | frac_part *= 10; 158 | } 159 | int frac_as_int = (int)(frac_part + 0.5f); // Round the fractional part 160 | int_to_str(frac_as_int, str + i, precision); 161 | } 162 | 163 | -------------------------------------------------------------------------------- /src/bootloader/boot.asm: -------------------------------------------------------------------------------- 1 | ; --- FELTIX BOOTLOADER --- 2 | 3 | ; Bootloader section 4 | section .bootloader 5 | 6 | ; Start in 16-bit real mode 7 | BITS 16 8 | 9 | ; Define program entrypoint 10 | global _start 11 | 12 | ; Disk variable 13 | disk db 0 14 | 15 | ; Amount of sectors to load 16 | ; If something goes wrong without explanation, try incrementing this value 17 | ; If you get a disk error, lower it again 18 | sectors db 30 19 | 20 | ; Program entrypoint 21 | ; Here we generally just focus on loading additional sectors and getting 32-bit protected mode up and running 22 | _start: 23 | ; Disable hardware interrupts 24 | cli 25 | 26 | ; Null out segment registers 27 | xor ax, ax 28 | mov ds, ax 29 | mov es, ax 30 | 31 | ; Set a simple stack 32 | mov ax, 0x7A00 33 | mov ss, ax 34 | mov ax, 0xFFFE 35 | mov sp, ax 36 | mov bp, sp 37 | 38 | ; Enable hardware interrupts 39 | sti 40 | 41 | ; Print boot message 42 | mov si, boot_message 43 | call print_string_16 44 | 45 | ; Load sectors from disk 46 | mov [disk], dl ; Disk number 47 | mov ah, 0x2 ; BIOS interrupt for reading sectors from disk 48 | mov al, [sectors] ; Sectors to load 49 | mov ch, 0 ; Cylinder index 50 | mov dh, 0 ; Head index 51 | mov cl, 2 ; Sector index 52 | mov bx, kernel_wrapper ; Target pointer (MUST be after the boot sector) 53 | int 0x13 ; Call BIOS 54 | jc .disk_error ; Jump to .disk_error upon failure 55 | 56 | ; Set up the 32-bit GDT 57 | lgdt [gdt32_definition] 58 | 59 | ; Enable A20 line 60 | in al, 0x92 61 | or al, 00000010b ; Set bit 1 to enable A20 62 | out 0x92, al 63 | 64 | ; Set PE bit in EFLAGS to enable protected mode (32-bit) 65 | mov eax, cr0 ; Get the value of CR0 66 | or eax, 0x1 ; Set the PE (protected mode enable) bit 67 | mov cr0, eax ; Write back the modified CR0 68 | 69 | ; Jump to 32-bit entry 70 | jmp 0x08:protected_mode_entry 71 | 72 | ; Upon a disk error 73 | .disk_error: 74 | ; Disable hardware interrupts 75 | cli 76 | 77 | ; Print error message 78 | mov si, disk_error_message 79 | call print_string_16 80 | 81 | ; Wait for keypress 82 | call wait_for_keypress 83 | 84 | ; Reboot the system 85 | mov al, 0FEh ; Reset command for 8042 86 | out 64h, al ; Send to keyboard controller 87 | 88 | ; If that fails, try undefined 89 | ud2 90 | 91 | ; If that still doesn't do the trick, settle with a hlt 92 | hlt 93 | 94 | ; Boot message 95 | boot_message db "Booting Feltix...", 0x0A, 0x0A, 0 96 | 97 | ; Disk error message 98 | disk_error_message db "Fatal error: Error Loading From Disk", 0x0A, "Press any key to reboot...", 0 99 | 100 | 101 | ; Function for printing strings in 16-bit real mode 102 | print_string_16: 103 | lodsb ; Load byte at DS:SI into AL, increment SI 104 | or al, al ; Check for null terminator 105 | jz .done ; Jump to .done if null terminator 106 | 107 | cmp al, 0x0A ; Check for newline (LF) 108 | jz .newline ; Jump to .newline if newline 109 | 110 | mov ah, 0x0E ; BIOS teletype output function 111 | mov bh, 0x00 ; Page number 112 | mov bl, 0x07 ; Text attribute (light gray on black) 113 | int 0x10 ; Call BIOS 114 | jmp print_string_16 ; Continue the loop 115 | 116 | .newline: 117 | ; Print carriage return (\r) 118 | mov al, 0x0D 119 | mov ah, 0x0E 120 | mov bh, 0x00 121 | mov bl, 0x07 122 | int 0x10 123 | 124 | ; Print line feed (\n) 125 | mov al, 0x0A 126 | mov ah, 0x0E 127 | mov bh, 0x00 128 | mov bl, 0x07 129 | int 0x10 130 | 131 | jmp print_string_16 ; Continue the loop 132 | 133 | .done: 134 | ; Return from the function 135 | ret 136 | 137 | 138 | ; Function to wait for a keypress to continue 139 | wait_for_keypress: 140 | xor ah, ah 141 | int 16h 142 | ret 143 | 144 | 145 | ; Define the 32-bit GDT (Global Descriptor Table) structure 146 | gdt32_start: 147 | dq 0x0 ; Null descriptor 148 | 149 | ; Code segment 150 | gdt32_code: 151 | dw 0xFFFF 152 | dw 0x0 153 | db 0x0 154 | db 10011010b 155 | db 11001111b 156 | db 0x0 157 | 158 | ; Data segment 159 | gdt32_data: 160 | dw 0xFFFF 161 | dw 0x0 162 | db 0x0 163 | db 10010010b 164 | db 11001111b 165 | db 0x0 166 | 167 | ; End of 32-bit GDT 168 | gdt32_end: 169 | 170 | ; GDT descriptor containing necessary information for LGDT 171 | gdt32_definition: 172 | dw gdt32_end - gdt32_start 173 | dd gdt32_start 174 | 175 | 176 | ; 32-bit protected mode entry 177 | BITS 32 178 | protected_mode_entry: 179 | ; Refresh segment registers 180 | mov ax, 0x10 ; Load the data segment descriptor 181 | mov ds, ax 182 | mov es, ax 183 | mov ss, ax ; Stack segment 184 | 185 | ; Set up a stack (32-bit ESP) 186 | mov esp, 0x10000 ; Set the stack pointer 187 | 188 | ; Far jump to the kernel wrapper function 189 | jmp 0x08:kernel_wrapper 190 | 191 | 192 | ; Other BIOS boot sector formalities 193 | times 510 - ($ - $$) db 0 ; Pad to 510 bytes 194 | dw 0xAA55 ; Boot signature 195 | 196 | 197 | ; Start of sector 2 198 | BITS 32 199 | 200 | 201 | ; Kernel wrapper function 202 | kernel_wrapper: 203 | ; Disable hardware interrupts 204 | cli 205 | 206 | ; Call kernel_main 207 | extern kernel_main 208 | call kernel_main 209 | 210 | ; Any following code in this function will only execute if the kernel ever returns 211 | ; (which it probably shouldn't if you've set it up correctly) 212 | 213 | ; Just in case, halt the CPU 214 | hlt 215 | 216 | 217 | ; Pad to 1024 bytes 218 | times 1024 - ($ - $$) db 0 219 | 220 | -------------------------------------------------------------------------------- /src/keyboard.c: -------------------------------------------------------------------------------- 1 | // Simple keyboard driver 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | // Function to get a scancode from the keyboard 9 | uint8_t keyboard_get_scancode(void) { 10 | while (!(inb(0x64) & 0x01)) { 11 | // Wait until a key is pressed 12 | } 13 | 14 | return inb(0x60); 15 | } 16 | 17 | // Variables to track SHIFT and CAPS LOCK 18 | static int shift_pressed = 0; 19 | static int capslock_enabled = 0; 20 | 21 | // Function to convert a scancode to ASCII 22 | char scancode_to_ascii(uint8_t scancode) { 23 | // Handle SHIFT key 24 | if (scancode == 0x2A || scancode == 0x36) { // Shift pressed 25 | shift_pressed = 1; 26 | 27 | return 0; 28 | } 29 | if (scancode == 0xAA || scancode == 0xB6) { // Shift released 30 | shift_pressed = 0; 31 | 32 | return 0; 33 | } 34 | 35 | // Handle CAPS LOCK 36 | if (scancode == 0x3A) { 37 | capslock_enabled = !capslock_enabled; 38 | 39 | return 0; 40 | } 41 | 42 | // Ignore other break codes 43 | if (scancode & 0x80) 44 | 45 | return 0; 46 | 47 | // Base mapping, assign a default (unshifted) value 48 | char character = 0; 49 | switch (scancode) { 50 | 51 | // Number row 52 | case 0x02: character = '1'; break; 53 | case 0x03: character = '2'; break; 54 | case 0x04: character = '3'; break; 55 | case 0x05: character = '4'; break; 56 | case 0x06: character = '5'; break; 57 | case 0x07: character = '6'; break; 58 | case 0x08: character = '7'; break; 59 | case 0x09: character = '8'; break; 60 | case 0x0A: character = '9'; break; 61 | case 0x0B: character = '0'; break; 62 | 63 | // Backspace and TAB 64 | case 0x0E: character = '\b'; break; 65 | case 0x0F: character = '\t'; break; 66 | 67 | // Symbols beside numbers 68 | case 0x0C: character = '-'; break; 69 | case 0x0D: character = '='; break; 70 | 71 | // Top row letters and punctuation 72 | case 0x10: character = 'q'; break; 73 | case 0x11: character = 'w'; break; 74 | case 0x12: character = 'e'; break; 75 | case 0x13: character = 'r'; break; 76 | case 0x14: character = 't'; break; 77 | case 0x15: character = 'y'; break; 78 | case 0x16: character = 'u'; break; 79 | case 0x17: character = 'i'; break; 80 | case 0x18: character = 'o'; break; 81 | case 0x19: character = 'p'; break; 82 | case 0x1A: character = '['; break; 83 | case 0x1B: character = ']'; break; 84 | 85 | // Home row letters and punctuation 86 | case 0x1E: character = 'a'; break; 87 | case 0x1F: character = 's'; break; 88 | case 0x20: character = 'd'; break; 89 | case 0x21: character = 'f'; break; 90 | case 0x22: character = 'g'; break; 91 | case 0x23: character = 'h'; break; 92 | case 0x24: character = 'j'; break; 93 | case 0x25: character = 'k'; break; 94 | case 0x26: character = 'l'; break; 95 | case 0x27: character = ';'; break; 96 | case 0x28: character = '\''; break; 97 | case 0x29: character = ' '; break; 98 | 99 | // Bottom row letters and punctuation 100 | case 0x2C: character = 'z'; break; 101 | case 0x2D: character = 'x'; break; 102 | case 0x2E: character = 'c'; break; 103 | case 0x2F: character = 'v'; break; 104 | case 0x30: character = 'b'; break; 105 | case 0x31: character = 'n'; break; 106 | case 0x32: character = 'm'; break; 107 | case 0x33: character = ','; break; 108 | case 0x34: character = '.'; break; 109 | case 0x35: character = '/'; break; 110 | 111 | // SPACE and ENTER 112 | case 0x39: character = ' '; break; 113 | case 0x1C: character = '\n'; break; 114 | 115 | default: return 0; 116 | } 117 | 118 | // Handle SHIFT 119 | if (shift_pressed) { 120 | switch (scancode) { 121 | case 0x02: character = '!'; break; 122 | case 0x03: character = '@'; break; 123 | case 0x04: character = '#'; break; 124 | case 0x05: character = '$'; break; 125 | case 0x06: character = '%'; break; 126 | case 0x07: character = '^'; break; 127 | case 0x08: character = '&'; break; 128 | case 0x09: character = '*'; break; 129 | case 0x0A: character = '('; break; 130 | case 0x0B: character = ')'; break; 131 | case 0x0C: character = '_'; break; 132 | case 0x0D: character = '+'; break; 133 | case 0x1A: character = '{'; break; 134 | case 0x1B: character = '}'; break; 135 | case 0x27: character = ':'; break; 136 | case 0x28: character = '"'; break; 137 | case 0x29: character = '~'; break; 138 | case 0x33: character = '<'; break; 139 | case 0x34: character = '>'; break; 140 | case 0x35: character = '?'; break; 141 | 142 | default: 143 | // For letters, we'll adjust below 144 | break; 145 | } 146 | } 147 | 148 | // Handle CAPS LOCK to capitalize letters 149 | if (character >= 'a' && character <= 'z') { 150 | if (shift_pressed ^ capslock_enabled) { 151 | character = character - 'a' + 'A'; 152 | } 153 | } 154 | 155 | return character; 156 | } 157 | 158 | // Wait for a key press and return the corresponding ASCII value 159 | char keyboard_getchar(void) { 160 | char character = 0; 161 | while (!character) { 162 | uint8_t scancode = keyboard_get_scancode(); 163 | character = scancode_to_ascii(scancode); 164 | } 165 | 166 | return character; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /src/shell.c: -------------------------------------------------------------------------------- 1 | // Basic input handler and command processor 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // Function to process parsed shell commands 18 | void process_command(int argc, char** argv) { 19 | 20 | // Display supported commands and their descriptions 21 | if (strcmp(argv[0], "help") == 0) { 22 | print_string("Available commands:\n", VGA_COLOR_WHITE); 23 | 24 | print_string(" help ", VGA_COLOR_LIGHT_GREY); 25 | print_string("- Display this help menu\n", VGA_COLOR_WHITE); 26 | 27 | print_string(" exit ", VGA_COLOR_LIGHT_GREY); 28 | print_string("- Exit the shell\n", VGA_COLOR_WHITE); 29 | 30 | print_string(" license ", VGA_COLOR_LIGHT_GREY); 31 | print_string("- Display licensing information\n", VGA_COLOR_WHITE); 32 | 33 | print_string(" clear ", VGA_COLOR_LIGHT_GREY); 34 | print_string("- Clear the screen\n", VGA_COLOR_WHITE); 35 | 36 | print_string(" reboot ", VGA_COLOR_LIGHT_GREY); 37 | print_string("- Reboot the system\n", VGA_COLOR_WHITE); 38 | 39 | print_string(" beep ", VGA_COLOR_LIGHT_GREY); 40 | print_string("", VGA_COLOR_LIGHT_MAGENTA); 41 | print_string("/", VGA_COLOR_DARK_GREY); 42 | print_string("stop", VGA_COLOR_LIGHT_MAGENTA); 43 | print_string("/", VGA_COLOR_DARK_GREY); 44 | print_string("short ", VGA_COLOR_LIGHT_MAGENTA); 45 | print_string("- Beep the PC speaker, or stop beeping\n", VGA_COLOR_WHITE); 46 | 47 | print_string(" math ", VGA_COLOR_LIGHT_GREY); 48 | print_string(" ", VGA_COLOR_LIGHT_MAGENTA); 49 | print_string("- Perform a math operation\n", VGA_COLOR_WHITE); 50 | 51 | print_string(" ls ", VGA_COLOR_LIGHT_GREY); 52 | print_string("- List all files in filesystem\n", VGA_COLOR_WHITE); 53 | 54 | print_string(" touch ", VGA_COLOR_LIGHT_GREY); 55 | print_string(" ", VGA_COLOR_LIGHT_MAGENTA); 56 | print_string("- Create an empty file\n", VGA_COLOR_WHITE); 57 | 58 | print_string(" rm ", VGA_COLOR_LIGHT_GREY); 59 | print_string(" ", VGA_COLOR_LIGHT_MAGENTA); 60 | print_string("- Delete a file\n", VGA_COLOR_WHITE); 61 | 62 | print_string(" write ", VGA_COLOR_LIGHT_GREY); 63 | print_string(" ", VGA_COLOR_LIGHT_MAGENTA); 64 | print_string("- Write data to a file\n", VGA_COLOR_WHITE); 65 | 66 | print_string(" cat ", VGA_COLOR_LIGHT_GREY); 67 | print_string(" ", VGA_COLOR_LIGHT_MAGENTA); 68 | print_string("- Display the contents of a file\n", VGA_COLOR_WHITE); 69 | 70 | print_string(" panic ", VGA_COLOR_LIGHT_GREY); 71 | print_string("- Force a kernel panic\n", VGA_COLOR_WHITE); 72 | 73 | print_string(" cpuinfo ", VGA_COLOR_LIGHT_GREY); 74 | print_string("- Display some information about the CPU\n", VGA_COLOR_WHITE); 75 | 76 | print_string(" raminfo ", VGA_COLOR_LIGHT_GREY); 77 | print_string("- Display accessible memory in megabytes\n\n", VGA_COLOR_WHITE); 78 | 79 | // Exit is handled in shell_start 80 | 81 | // Display licensing information 82 | } else if (strcmp(argv[0], "license") == 0) { 83 | print_string("Feltix", VGA_COLOR_LIGHT_GREY); 84 | print_string(" is licensed under the ", VGA_COLOR_WHITE); 85 | print_string("GNU GPLv3", VGA_COLOR_LIGHT_GREY); 86 | print_string(" license\n", VGA_COLOR_WHITE); 87 | 88 | print_string("See the project's ", VGA_COLOR_WHITE); 89 | print_string("GitHub", VGA_COLOR_LIGHT_GREY); 90 | print_string(" page for more information:\n\n", VGA_COLOR_WHITE); 91 | 92 | print_string("https://github.com/FeltMacaroon389/Feltix\n\n", VGA_COLOR_LIGHT_BLUE); 93 | 94 | // Clear the VGA screen 95 | } else if (strcmp(argv[0], "clear") == 0) { 96 | clear_screen(); 97 | 98 | // Reboot the system 99 | } else if (strcmp(argv[0], "reboot") == 0) { 100 | reboot_system(); 101 | 102 | // Beep the PC speaker 103 | } else if (strcmp(argv[0], "beep") == 0) { 104 | 105 | // Check for sufficient arguments 106 | if (!argv[1]) { 107 | print_string("Usage: ", VGA_COLOR_WHITE); 108 | print_string("beep ", VGA_COLOR_LIGHT_GREY); 109 | print_string("", VGA_COLOR_LIGHT_MAGENTA); 110 | print_string("/", VGA_COLOR_DARK_GREY); 111 | print_string("stop", VGA_COLOR_LIGHT_MAGENTA); 112 | print_string("/", VGA_COLOR_DARK_GREY); 113 | print_string("short\n\n", VGA_COLOR_LIGHT_MAGENTA); 114 | return; 115 | } 116 | 117 | // Check for stop 118 | if (strcmp(argv[1], "stop") == 0) { 119 | stop_beep(); 120 | print_string("Successfully stopped beeping!\n\n", VGA_COLOR_WHITE); 121 | return; 122 | 123 | // Check for short 124 | } else if (strcmp(argv[1], "short") == 0) { 125 | short_beep(); 126 | return; 127 | 128 | } else { 129 | 130 | // Frequency must be a number 131 | if (is_valid_float(argv[1]) == 1) { 132 | print_string("Frequency must be a number!\n\n", VGA_COLOR_LIGHT_RED); 133 | return; 134 | } 135 | 136 | // Convert frequency to a double 137 | double frequency = atof(argv[1]); 138 | 139 | // Refuse to beep at 0MHz (to prevent dividing by zero) 140 | if (frequency == 0) { 141 | print_string("Beeping at 0MHz is not allowed!\n\n", VGA_COLOR_LIGHT_RED); 142 | return; 143 | } 144 | 145 | // Beep with the desired frequency 146 | beep(frequency); 147 | 148 | print_string("PC speaker beeping at ", VGA_COLOR_WHITE); 149 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 150 | print_string("MHz\n", VGA_COLOR_LIGHT_GREY); 151 | print_string("Run: ", VGA_COLOR_WHITE); 152 | print_string("beep ", VGA_COLOR_LIGHT_GREY); 153 | print_string("stop", VGA_COLOR_LIGHT_MAGENTA); 154 | print_string(" to stop beeping\n\n", VGA_COLOR_WHITE); 155 | } 156 | 157 | // Basic math operations 158 | } else if (strcmp(argv[0], "math") == 0) { 159 | 160 | // Check for sufficient arguments 161 | if (argc < 4) { 162 | print_string("Usage: ", VGA_COLOR_WHITE); 163 | print_string("math ", VGA_COLOR_LIGHT_GREY); 164 | print_string(" \n\n", VGA_COLOR_LIGHT_MAGENTA); 165 | return; 166 | 167 | } else { 168 | 169 | // Math can only be performed on numbers 170 | if (is_valid_float(argv[1]) || is_valid_float(argv[3]) == 1) { 171 | print_string("Math cannot be performed on non-numbers!\n\n", VGA_COLOR_LIGHT_RED); 172 | return; 173 | } 174 | 175 | // Convert arguments to their respective data types 176 | double num1 = atof(argv[1]); 177 | double num2 = atof(argv[3]); 178 | 179 | // Declare result and buffer 180 | double result; 181 | char result_buffer[8]; 182 | 183 | // Addition 184 | if (strcmp(argv[2], "+") == 0) { 185 | result = num1 + num2; 186 | 187 | // Subtraction 188 | } else if (strcmp(argv[2], "-") == 0) { 189 | result = num1 - num2; 190 | 191 | // Multiplication 192 | } else if (strcmp(argv[2], "*") == 0) { 193 | result = num1 * num2; 194 | 195 | // Division 196 | } else if (strcmp(argv[2], "/") == 0) { 197 | 198 | // Division by zero is not allowed 199 | if (num2 == 0) { 200 | print_string("Division by zero is not allowed!\n\n", VGA_COLOR_LIGHT_RED); 201 | return; 202 | 203 | } else { 204 | result = num1 / num2; 205 | } 206 | 207 | // If operation is unknown 208 | } else { 209 | print_string("Unsupported operation: ", VGA_COLOR_LIGHT_RED); 210 | print_string(argv[2], VGA_COLOR_LIGHT_GREY); 211 | print_string("\nSupported operations: ", VGA_COLOR_WHITE); 212 | print_string("+ - * /\n\n", VGA_COLOR_LIGHT_GREY); 213 | return; 214 | } 215 | 216 | // Result cannot be less than zero (for now) 217 | if (result < 0) { 218 | print_string("Result less than zero not supported!\n\n", VGA_COLOR_LIGHT_RED); 219 | return; 220 | } 221 | 222 | // Convert to string, and print 223 | int_to_str(result, result_buffer, 0); 224 | 225 | print_string("Result: ", VGA_COLOR_WHITE); 226 | print_string(result_buffer, VGA_COLOR_LIGHT_GREY); 227 | print_string("\n", VGA_COLOR_BLACK); 228 | } 229 | 230 | // List all files currently in Felt File System (FFS) 231 | } else if (strcmp(argv[0], "ls") == 0) { 232 | ffs_list_files(); 233 | 234 | // Create an empty file 235 | } else if (strcmp(argv[0], "touch") == 0) { 236 | 237 | // Check for sufficient arguments 238 | if (!argv[1]) { 239 | print_string("Usage: ", VGA_COLOR_WHITE); 240 | print_string("touch ", VGA_COLOR_LIGHT_GREY); 241 | print_string("\n\n", VGA_COLOR_LIGHT_MAGENTA); 242 | 243 | // Check return code from FFS 244 | } else { 245 | int ffs_return_code = ffs_create_file(argv[1]); 246 | 247 | // Invalid name 248 | if (ffs_return_code == FFS_INVALID_NAME) { 249 | print_string("Filename too long: ", VGA_COLOR_LIGHT_RED); 250 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 251 | print_string("\n\n", VGA_COLOR_BLACK); 252 | 253 | // File exists 254 | } else if (ffs_return_code == FFS_FILE_EXISTS) { 255 | print_string("File exists: ", VGA_COLOR_LIGHT_RED); 256 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 257 | print_string("\n\n", VGA_COLOR_BLACK); 258 | 259 | // No space 260 | } else if (ffs_return_code == FFS_NO_SPACE) { 261 | print_string("No space left. ", VGA_COLOR_LIGHT_RED); 262 | print_string("Please delete a file to make space", VGA_COLOR_WHITE); 263 | print_string("\n\n", VGA_COLOR_BLACK); 264 | } 265 | } 266 | 267 | // Delete a file from Felt File System 268 | } else if (strcmp(argv[0], "rm") == 0) { 269 | 270 | // Check for sufficient arguments 271 | if (!argv[1]) { 272 | print_string("Usage: ", VGA_COLOR_WHITE); 273 | print_string("rm ", VGA_COLOR_LIGHT_GREY); 274 | print_string("\n\n", VGA_COLOR_LIGHT_MAGENTA); 275 | 276 | // Check return code from FFS 277 | } else { 278 | int ffs_return_code = ffs_delete_file(argv[1]); 279 | 280 | // File not found 281 | if (ffs_return_code == FFS_FILE_NOT_FOUND) { 282 | print_string("File not found: ", VGA_COLOR_LIGHT_RED); 283 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 284 | print_string("\n\n", VGA_COLOR_BLACK); 285 | } 286 | } 287 | 288 | // Write data to a file in Felt File System 289 | } else if (strcmp(argv[0], "write") == 0) { 290 | 291 | // Check for sufficient arguments 292 | if (argc < 3) { 293 | print_string("Usage: ", VGA_COLOR_WHITE); 294 | print_string("write ", VGA_COLOR_LIGHT_GREY); 295 | print_string(" \n\n", VGA_COLOR_LIGHT_MAGENTA); 296 | 297 | // Combine all arguments after argv[1] into a single string 298 | } else { 299 | char data[4096] = {0}; // Max combined size (4KB) 300 | for (int i = 2; i < argc; ++i) { 301 | strcat(data, argv[i]); 302 | if (i < argc - 1) strcat(data, " "); 303 | } 304 | 305 | // Check return code from FFS 306 | int ffs_return_code = ffs_write_file(argv[1], data); 307 | 308 | // File not found 309 | if (ffs_return_code == FFS_FILE_NOT_FOUND) { 310 | print_string("File not found: ", VGA_COLOR_LIGHT_RED); 311 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 312 | print_string("\n\n", VGA_COLOR_BLACK); 313 | 314 | // Data size exceeds limit 315 | } else if (ffs_return_code == FFS_SIZE_EXCEEDS_LIMIT) { 316 | print_string("File exceeds limit: ", VGA_COLOR_LIGHT_RED); 317 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 318 | print_string("\n\n", VGA_COLOR_BLACK); 319 | } 320 | } 321 | 322 | // Read a file from Felt File System 323 | } else if (strcmp(argv[0], "cat") == 0) { 324 | 325 | // Check for sufficient arguments 326 | if (!argv[1]) { 327 | print_string("Usage: ", VGA_COLOR_WHITE); 328 | print_string("cat ", VGA_COLOR_LIGHT_GREY); 329 | print_string("\n\n", VGA_COLOR_LIGHT_MAGENTA); 330 | 331 | } else { 332 | // Declare buffer 333 | char cat_buffer[4096]; // 4KB 334 | size_t cat_buffer_size = sizeof(cat_buffer); 335 | 336 | // Check return code from FFS 337 | int ffs_return_code = ffs_read_file(argv[1], cat_buffer, cat_buffer_size); 338 | 339 | // File not found 340 | if (ffs_return_code == FFS_FILE_NOT_FOUND) { 341 | print_string("File not found: ", VGA_COLOR_LIGHT_RED); 342 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 343 | print_string("\n\n", VGA_COLOR_BLACK); 344 | 345 | // Buffer too small (file too large) 346 | } else if (ffs_return_code == FFS_BUFFER_TOO_SMALL) { 347 | print_string("File too large: ", VGA_COLOR_LIGHT_RED); 348 | print_string(argv[1], VGA_COLOR_LIGHT_GREY); 349 | print_string("\n", VGA_COLOR_BLACK); 350 | 351 | // If OK, print the buffer 352 | } else { 353 | print_string(cat_buffer, VGA_COLOR_LIGHT_GREY); 354 | print_string("\n\n", VGA_COLOR_BLACK); 355 | } 356 | } 357 | 358 | // Trigger kernel panic 359 | } else if (strcmp(argv[0], "panic") == 0) { 360 | kernel_panic("ManuallyTriggeredByUser"); 361 | 362 | // Display information about the CPU 363 | } else if (strcmp(argv[0], "cpuinfo") == 0) { 364 | 365 | // Print CPU manufacturer/vendor 366 | char vendor_buffer[13]; 367 | get_cpu_vendor(vendor_buffer); 368 | 369 | print_string("Vendor: ", VGA_COLOR_WHITE); 370 | print_string(vendor_buffer, VGA_COLOR_LIGHT_GREY); 371 | 372 | // Print CPU brand (model) 373 | char brand_buffer[48]; 374 | get_cpu_brand(brand_buffer); 375 | 376 | print_string("\nModel: ", VGA_COLOR_WHITE); 377 | print_string(brand_buffer, VGA_COLOR_LIGHT_GREY); 378 | 379 | // Print CPU threads 380 | char* cpu_threads = get_cpu_threads(); 381 | 382 | print_string("\nThreads: ", VGA_COLOR_WHITE); 383 | print_string(cpu_threads, VGA_COLOR_LIGHT_GREY); 384 | 385 | // Print CPU architecture 386 | print_string("\nArchitecture: ", VGA_COLOR_WHITE); 387 | 388 | uint32_t is_64bit_supported = cpu_supports_64bit(); 389 | 390 | if (is_64bit_supported == 0) { 391 | print_string("x86\n\n", VGA_COLOR_LIGHT_GREY); 392 | 393 | } else if (is_64bit_supported == 1) { 394 | print_string("x86_64\n\n", VGA_COLOR_LIGHT_GREY); 395 | } 396 | 397 | // Display all accessible memory in megabytes 398 | } else if (strcmp(argv[0], "raminfo") == 0) { 399 | char* memory_mb = get_accessible_memory(); 400 | 401 | print_string("Accessible memory: ", VGA_COLOR_WHITE); 402 | print_string(memory_mb, VGA_COLOR_LIGHT_GREY); 403 | print_string("MB\n\n", VGA_COLOR_LIGHT_GREY); 404 | 405 | // If command not recognized 406 | } else { 407 | print_string("Unknown command: ", VGA_COLOR_LIGHT_RED); 408 | print_string(argv[0], VGA_COLOR_LIGHT_GREY); 409 | print_string("\nType ", VGA_COLOR_WHITE); 410 | print_string("help", VGA_COLOR_CYAN); 411 | print_string(" for a list of commands\n\n", VGA_COLOR_WHITE); 412 | } 413 | } 414 | 415 | // Function to parse user input 416 | void parse_user_input(char* input) { 417 | char* argv[64] = { 0 }; 418 | int argc = 0; 419 | 420 | // Split on spaces 421 | char* token = strtok(input, " "); 422 | while (token != NULL && argc < 63) { 423 | argv[argc++] = token; 424 | token = strtok(NULL, " "); 425 | } 426 | 427 | // Make sure the list is NULL-terminated 428 | argv[argc] = NULL; 429 | 430 | if (argc > 0) { 431 | process_command(argc, argv); 432 | } 433 | } 434 | 435 | 436 | // Start of shell loop 437 | void shell_start(const char* prompt, uint8_t color) { 438 | while (1) { 439 | 440 | // Print prompt 441 | print_string(prompt, color); 442 | 443 | char input_buffer[2048]; 444 | size_t input_index = 0; 445 | 446 | // Read characters until ENTER is pressed 447 | while (1) { 448 | 449 | uint8_t scancode = keyboard_get_scancode(); 450 | char character = scancode_to_ascii(scancode); 451 | if (!character) 452 | continue; // Skip unmapped scancodes 453 | 454 | // On newline, print the newline character and break out 455 | if (character == '\n') { 456 | print_string("\n", VGA_COLOR_WHITE); 457 | break; 458 | 459 | // Handle backspace, remove last character if available 460 | } else if (character == '\b') { 461 | if (input_index > 0) { 462 | input_index--; 463 | shell_backspace(); 464 | } 465 | 466 | // Add the character to our input buffer if there is space 467 | } else { 468 | if (input_index < sizeof(input_buffer) - 1) { 469 | input_buffer[input_index++] = character; 470 | print_char(character, VGA_COLOR_WHITE); 471 | } 472 | } 473 | } 474 | 475 | // Null-terminate the string 476 | input_buffer[input_index] = '\0'; 477 | 478 | if (strcmp(input_buffer, "") != 0) { 479 | 480 | // Handle exit 481 | if (strcmp(input_buffer, "exit") == 0) { 482 | return; 483 | 484 | } else { 485 | parse_user_input(input_buffer); 486 | } 487 | } 488 | } 489 | } 490 | 491 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------