diff --git a/source/includes/algorithms/hashing.h b/source/includes/algorithms/hashing.h index e0d504b..f56fabe 100755 --- a/source/includes/algorithms/hashing.h +++ b/source/includes/algorithms/hashing.h @@ -27,7 +27,7 @@ void init_hashing(void); * @param data The string to be hashed. * @return [int64] Hashed value. */ -int64 hash_string(string data); +int64 hash_string(cstring data); /** * @brief A function to hash a string from BARANIUM ENTERTAINMENT diff --git a/source/includes/cc-asm.h b/source/includes/cc-asm.h index 72b573e..4c623da 100755 --- a/source/includes/cc-asm.h +++ b/source/includes/cc-asm.h @@ -39,4 +39,7 @@ void high_level_halt(void); * @brief Halt and catch fire function but doesn't print any text. * */ -void hcf2(void); \ No newline at end of file +void hcf2(void); +void wrmsr64(uint32_t msr, uint64_t value); +uint64_t rdmsr64(uint32_t msr); +uint64_t rdtsc64(void); diff --git a/source/includes/executables/elf.h b/source/includes/executables/elf.h index 127991e..33e4a6f 100755 --- a/source/includes/executables/elf.h +++ b/source/includes/executables/elf.h @@ -95,7 +95,7 @@ typedef int64_t Elf64_Sxword; #define R_X86_64_IRELATIVE 37 // Extract symbol and type from r_info -#define ELF64_R_SYM(info) ((info) >> 32) +#define ELF64_R_SYM(info) ((uint32_t)((info) >> 32)) #define ELF64_R_TYPE(info) ((uint32_t)(info)) // Program header diff --git a/source/includes/executables/fwde.h b/source/includes/executables/fwde.h index f1926fb..86588e9 100755 --- a/source/includes/executables/fwde.h +++ b/source/includes/executables/fwde.h @@ -12,9 +12,11 @@ #include #include #include +#include +#include typedef struct { - char signature[5]; // 0xCD + 0x31 + FWDE + char signature[6]; // 0xCD + 0x31 + FWDE int8 architecture; // 1 = 64 bits; 2 = 32 bits; 3 = 16 bits; 4 = 8 bits int16 raw_size; // size of just the executable part and not the header int8 endian; // 0 = error; 1 = little; 2 = big @@ -31,5 +33,6 @@ typedef struct typedef void(*entry_function)(kernel_data*); +bool verify_signature(const char* signature); void process_IFL(InterruptFrame* frame); void execute_fwde(int64* addr, kernel_data* data); \ No newline at end of file diff --git a/source/includes/graphics.h b/source/includes/graphics.h index ec587d2..69d099f 100755 --- a/source/includes/graphics.h +++ b/source/includes/graphics.h @@ -211,6 +211,6 @@ void print(cstring s); * @param pixels * @param color */ -void print_bitmap(int x, int y, int w, int h, bool* pixels, int32 color); +void print_bitmap(int x, int y, int w, int h, const bool* pixels, int32 color); #endif \ No newline at end of file diff --git a/source/includes/idt.h b/source/includes/idt.h index 1409a0c..eee1028 100755 --- a/source/includes/idt.h +++ b/source/includes/idt.h @@ -55,6 +55,7 @@ extern void syscall_entry(void); */ void init_syscall(void); +void remap_pic(void); void initIdt(void); void setIdtEntry(IDTEntry *target, uint64_t offset, uint16_t selector, uint8_t ist, uint8_t type_attributes); diff --git a/source/includes/kernel.h b/source/includes/kernel.h index b750f0e..87ddbca 100755 --- a/source/includes/kernel.h +++ b/source/includes/kernel.h @@ -92,4 +92,6 @@ extern int64* wm_addr; * @brief The main kernel function * @attention main() to something else, make sure to change the linker script accordingly. */ -void main(void); \ No newline at end of file +void main(void); +void shutdown(void); +void reboot(void); diff --git a/source/includes/keyboard.h b/source/includes/keyboard.h index a22a3b1..207ecff 100755 --- a/source/includes/keyboard.h +++ b/source/includes/keyboard.h @@ -16,17 +16,17 @@ #include #include -#define MOD_LCTRL 0b00000001 -#define MOD_RCTRL 0b00000010 -#define MOD_CTRL 0b00000011 -#define MOD_LSHIFT 0b00000100 -#define MOD_RSHIFT 0b00001000 -#define MOD_SHIFT 0b01001100 -#define MOD_LALT 0b00010000 -#define MOD_RALT 0b00100000 -#define MOD_ALT 0b00110000 -#define MOD_CAPSLOCK 0b01000000 -#define MOD_NUMLOCK 0b10000000 +#define MOD_LCTRL 0x01U +#define MOD_RCTRL 0x02U +#define MOD_CTRL 0x03U +#define MOD_LSHIFT 0x04U +#define MOD_RSHIFT 0x08U +#define MOD_SHIFT 0x4CU +#define MOD_LALT 0x10U +#define MOD_RALT 0x20U +#define MOD_ALT 0x30U +#define MOD_CAPSLOCK 0x40U +#define MOD_NUMLOCK 0x80U #define CUR_UP -1 #define CUR_DOWN -2 diff --git a/source/includes/pci.h b/source/includes/pci.h index 50bc25f..1a9dc8e 100755 --- a/source/includes/pci.h +++ b/source/includes/pci.h @@ -24,8 +24,8 @@ #include extern cstring display_adapter_name; -extern cstring GPUName[1]; //Max 2 GPUs allowed -extern string using_graphics_card; +extern cstring GPUName[2]; //Max 2 GPUs allowed +extern cstring using_graphics_card; extern int64* graphics_base_Address; extern int total_devices; @@ -94,6 +94,7 @@ int16 getClassId(int16 bus, int16 device, int16 function); * @return int16 Sub-class ID */ int16 getSubClassId(int16 bus, int16 device, int16 function); +int8 getRevision(int16 bus, int16 slot, int16 func); int8 getProgIF(int16 bus, int16 device, int16 function); /** @@ -101,6 +102,7 @@ int8 getProgIF(int16 bus, int16 device, int16 function); * */ void probe_pci(void); +void print_lspci(void); /** * @brief Function to read a 32-bit value from the PCI configuration space diff --git a/source/includes/pci_id.h b/source/includes/pci_id.h index 93544fc..a9452ba 100644 --- a/source/includes/pci_id.h +++ b/source/includes/pci_id.h @@ -33,7 +33,7 @@ typedef struct { * @param vendor vendor id * @return string vendor name */ -string parse_vendor(int16 vendor); +cstring parse_vendor(int16 vendor); /** * @brief Gets the class id and gives the appropriate class name. @@ -41,7 +41,7 @@ string parse_vendor(int16 vendor); * @param classid class id * @return string class name */ -string parse_class(int16 classid); +cstring parse_class(int16 classid); /** * @brief A Simplified and clean PCI lookup function. diff --git a/source/includes/pit.h b/source/includes/pit.h index 421eb9d..6fdb7a3 100755 --- a/source/includes/pit.h +++ b/source/includes/pit.h @@ -17,4 +17,6 @@ * * @param frame */ -void process_pit(InterruptFrame* frame); \ No newline at end of file +void process_pit(InterruptFrame* frame); +void init_pit(void); +void pit_sleep(uint32_t milliseconds); diff --git a/source/includes/ps2-mouse.h b/source/includes/ps2-mouse.h index 117b9d4..7499abf 100755 --- a/source/includes/ps2-mouse.h +++ b/source/includes/ps2-mouse.h @@ -17,13 +17,13 @@ #include #include -#define PS2_left_button 0b00000001 -#define PS2_middle_button 0b00000100 -#define PS2_right_button 0b00000010 -#define PS2_x 0b00010000 -#define PS2_y 0b00100000 -#define PS2_x_overflow 0b01000000 -#define PS2_y_overflow 0b10000000 +#define PS2_left_button 0x01U +#define PS2_middle_button 0x04U +#define PS2_right_button 0x02U +#define PS2_x 0x10U +#define PS2_y 0x20U +#define PS2_x_overflow 0x40U +#define PS2_y_overflow 0x80U #define MOUSE_BUTTON_LEFT PS2_left_button #define MOUSE_BUTTON_RIGHT PS2_right_button @@ -85,4 +85,5 @@ ivec2 GetLastMousePosition(void); * * @param frame */ -void process_mouse(InterruptFrame* frame); \ No newline at end of file +void process_mouse(InterruptFrame* frame); +void init_ps2_mouse(void); \ No newline at end of file diff --git a/source/includes/rtc.h b/source/includes/rtc.h index 133af27..503aa6e 100644 --- a/source/includes/rtc.h +++ b/source/includes/rtc.h @@ -14,6 +14,7 @@ #include #include +#include // I/O ports for RTC #define RTC_PORT 0x70 diff --git a/source/includes/sh_util.h b/source/includes/sh_util.h index 361e37d..2ad82d5 100644 --- a/source/includes/sh_util.h +++ b/source/includes/sh_util.h @@ -131,4 +131,4 @@ void execute(const char* buffer, int argc, char** argv); */ void user_main(char* buffer); -#endif \ No newline at end of file +#endif diff --git a/source/includes/strings.h b/source/includes/strings.h index 6d813cc..1f6cf23 100755 --- a/source/includes/strings.h +++ b/source/includes/strings.h @@ -30,7 +30,7 @@ * @param s The input string. * @return The length of the string. */ -int strlen(char s[]); +int strlen(cstring s); /** * @brief Copies a string from `src` to `dest` @@ -192,3 +192,5 @@ char* trim_inplace(char* s); char* strrchr(const char* s, int c); char* strdup(const char* str); + +int itoa(int num, string str, int len, int base); diff --git a/source/kernel/C/acpi-shutdown.c b/source/kernel/C/acpi-shutdown.c index 33eac1b..8a7c651 100755 --- a/source/kernel/C/acpi-shutdown.c +++ b/source/kernel/C/acpi-shutdown.c @@ -11,6 +11,7 @@ #include #include #include +#include struct facp { char signature[4]; @@ -59,7 +60,7 @@ static inline int8 parse_integer(int8* s5_addr, int64* value) { return 9; // 1 Type Byte, 8 Data Bytes case 0xFF: // OnesOp - *value = ~0; + *value = UINT64_MAX; return 1; // 1 Op Byte default: @@ -98,7 +99,7 @@ int acpi_shutdown_hack(uintptr_t direct_map_base, void *(*find_sdt)(cstring sign if (size == 0) // Wasn't able to parse it return -1; - int16 SLP_TYPa = value << 10; + int16 SLP_TYPa = (int16)((value & 0x7ULL) << 10); s5_addr += size; @@ -106,22 +107,22 @@ int acpi_shutdown_hack(uintptr_t direct_map_base, void *(*find_sdt)(cstring sign if (size == 0) // Wasn't able to parse it return -1; - int16 SLP_TYPb = value << 10; + int16 SLP_TYPb = (int16)((value & 0x7ULL) << 10); s5_addr += size; if(facp->SMI_CMD != 0 && facp->ACPI_ENABLE != 0) { // This PC has SMM and we need to enable ACPI mode first - outb(facp->SMI_CMD, facp->ACPI_ENABLE); + outb((int16)facp->SMI_CMD, facp->ACPI_ENABLE); for (int i = 0; i < 100; i++) inb(0x80); - while (!inw(facp->PM1a_CNT_BLK) & (1 << 0)) + while ((inw((int16)facp->PM1a_CNT_BLK) & 1U) == 0U) ; } - outw(facp->PM1a_CNT_BLK, SLP_TYPa | (1 << 13)); + outw((int16)facp->PM1a_CNT_BLK, (int16)(SLP_TYPa | (1U << 13))); if (facp->PM1b_CNT_BLK) - outw(facp->PM1b_CNT_BLK, SLP_TYPb | (1 << 13)); + outw((int16)facp->PM1b_CNT_BLK, (int16)(SLP_TYPb | (1U << 13))); for (int i = 0; i < 100; i++) inb(0x80); diff --git a/source/kernel/C/algorithms/hashing.c b/source/kernel/C/algorithms/hashing.c index 5190ad8..9e0e998 100755 --- a/source/kernel/C/algorithms/hashing.c +++ b/source/kernel/C/algorithms/hashing.c @@ -11,7 +11,7 @@ #include void init_hashing(void){ - string data = "PradoshGame"; + cstring data = "PradoshGame"; int64 hash = hash_string(data); if(hash == (int64)0x393e7fd){ @@ -22,12 +22,12 @@ void init_hashing(void){ } } -int64 hash_string(string data){ - int hash = 0; +int64 hash_string(cstring data){ + int64 hash = 0; while(*data){ - hash += *data++; + hash += (uint8_t)*data++; if(*data) - hash *= *data++; + hash *= (uint8_t)*data++; } return hash; } @@ -35,10 +35,10 @@ int64 hash_string(string data){ int64 baranium_hash(const char* name) { int64 identifier = 9780; - size_t length = strlen(name); + size_t length = (size_t)strlen(name); for (size_t i = 0; i < length; i++) { - char c = name[i]; + uint8_t c = (uint8_t)name[i]; identifier = ((identifier << 5) + identifier) + c; } return (int64)identifier; diff --git a/source/kernel/C/executables/elf.c b/source/kernel/C/executables/elf.c index 59fc3a3..b3225eb 100755 --- a/source/kernel/C/executables/elf.c +++ b/source/kernel/C/executables/elf.c @@ -30,6 +30,18 @@ static uint32_t* elf_vfs_pos_ptr(vfs_file_t* file) return &file->f.fat32.pos; case FS_ISO9660: return &file->f.iso9660.pos; + case FS_UNKNOWN: + case FS_FAT12: + case FS_EXFAT: + case FS_EXT2: + case FS_EXT3: + case FS_EXT4: + case FS_XFS: + case FS_BTRFS: + case FS_NTFS: + case FS_UDF: + case FS_PROC: + case FS_DEV: default: return NULL; } @@ -110,7 +122,7 @@ static int elf_load_tls_template_from_memory(void* file_base_address, uint64_t f return 0; } -static int elf_load_tls_template_from_vfs(const char* path, elf_image_info_t* info) +__attribute__((unused)) static int elf_load_tls_template_from_vfs(const char* path, elf_image_info_t* info) { if (!info || info->tls_filesz == 0) return 0; @@ -351,7 +363,7 @@ static uint64_t elf_runtime_addr_for_offset(Elf64_Phdr* headers, uint16_t phnum, return 0; } -static void elf_log_load_progress(uint16_t current, uint16_t total, Elf64_Phdr* ph) +__attribute__((unused)) static void elf_log_load_progress(uint16_t current, uint16_t total, Elf64_Phdr* ph) { if (!total) return; @@ -448,7 +460,7 @@ static int elf_map_program_header(Elf64_Phdr* ph, void* file_base, uint64_t file return 0; } -static int elf_map_program_header_from_vfs(Elf64_Phdr* ph, const char* path, uint64_t file_size, uint16_t seg_index, uint64_t load_bias) +__attribute__((unused)) static int elf_map_program_header_from_vfs(Elf64_Phdr* ph, const char* path, uint64_t file_size, uint16_t seg_index, uint64_t load_bias) { if (ph->p_type != PT_LOAD) return 0; @@ -531,7 +543,7 @@ void* elf_load_from_memory_ex(void* file_base_address, uint64_t file_size, elf_i return NULL; uint8_t* file_ptr = file_base_address; - Elf64_Ehdr header = {}; + Elf64_Ehdr header = {0}; memcpy(&header, file_ptr, sizeof(Elf64_Ehdr)); if (elf_validate_header(&header, file_size) != 0) @@ -599,6 +611,18 @@ void* elf_load_from_vfs_ex(const char* path, elf_image_info_t* info) case FS_ISO9660: size = file.f.iso9660.entry.size; break; + case FS_UNKNOWN: + case FS_FAT12: + case FS_EXFAT: + case FS_EXT2: + case FS_EXT3: + case FS_EXT4: + case FS_XFS: + case FS_BTRFS: + case FS_NTFS: + case FS_UDF: + case FS_PROC: + case FS_DEV: default: vfs_close(&file); return NULL; @@ -609,7 +633,7 @@ void* elf_load_from_vfs_ex(const char* path, elf_image_info_t* info) return NULL; } - Elf64_Ehdr header = {}; + Elf64_Ehdr header = {0}; if (elf_vfs_read_exact(&file, 0, &header, sizeof(header)) != 0) { eprintf("elf: failed to read header"); vfs_close(&file); diff --git a/source/kernel/C/executables/fwde.c b/source/kernel/C/executables/fwde.c index 96f304c..ab7d24b 100755 --- a/source/kernel/C/executables/fwde.c +++ b/source/kernel/C/executables/fwde.c @@ -11,8 +11,8 @@ #include -bool verify_signature(char* signature){ - char interrupt_opcode = 0xCD; +bool verify_signature(const char* signature){ + char interrupt_opcode = (char)0xCD; if(signature[0] == interrupt_opcode && signature[1] == '1' && signature[2] == 'F' && @@ -26,7 +26,8 @@ bool verify_signature(char* signature){ } void process_IFL(InterruptFrame* frame){ // process Invalid FWDE Loading - meltdown_screen("Frost Wing Deployed executable was not executed the way it should have!", __FILE__, __LINE__, 0xbadf1e, 0x0, 0xFfe); + (void)frame; + meltdown_screen("Frost Wing Deployed executable was not executed the way it should have!", __FILE__, __LINE__, 0xbadf1e, 0x0, 0xFfe, frame); hcf2(); } @@ -54,7 +55,7 @@ void execute_fwde(int64* addr, kernel_data* data){ local += sizeof(fwde_header); info("Starting executing the FrostWing deployed executable...", __FILE__); - entry_function execute_binary = (entry_function)local; + entry_function execute_binary = (entry_function)(uintptr_t)local; info("Function is ready! executing it..", __FILE__); printf("========================================================="); diff --git a/source/kernel/C/filesystems/iso9660.c b/source/kernel/C/filesystems/iso9660.c index 848a115..2307eae 100644 --- a/source/kernel/C/filesystems/iso9660.c +++ b/source/kernel/C/filesystems/iso9660.c @@ -2,6 +2,7 @@ #include #include #include +#include #pragma pack(push, 1) typedef struct { diff --git a/source/kernel/C/flanterm/flanterm.c b/source/kernel/C/flanterm/flanterm.c index 53ce7fa..b033813 100755 --- a/source/kernel/C/flanterm/flanterm.c +++ b/source/kernel/C/flanterm/flanterm.c @@ -32,6 +32,8 @@ // Tries to implement this standard for terminfo // https://man7.org/linux/man-pages/man4/console_codes.4.html + static int mk_wcwidth(uint32_t ucs); + static const uint32_t col256[] = { 0x000000, 0x00005f, 0x000087, 0x0000af, 0x0000d7, 0x0000ff, 0x005f00, 0x005f5f, 0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f, 0x008787, 0x0087af, @@ -104,7 +106,7 @@ void flanterm_write(struct flanterm_context *ctx, const char *buf, size_t count) { for (size_t i = 0; i < count; i++) { - flanterm_putchar(ctx, buf[i]); + flanterm_putchar(ctx, (uint8_t)buf[i]); } if (ctx->autoflush) { @@ -519,7 +521,7 @@ } for (size_t i = ctx->esc_values_i; i < FLANTERM_MAX_ESC_VALUES; i++) { - ctx->esc_values[i] = esc_default; + ctx->esc_values[i] = (uint32_t)esc_default; } if (ctx->dec_private == true) { @@ -538,7 +540,7 @@ // FALLTHRU case 'A': { if (ctx->esc_values[0] > y) - ctx->esc_values[0] = y; + ctx->esc_values[0] = (uint32_t)(y); size_t orig_y = y; size_t dest_y = y - ctx->esc_values[0]; bool will_be_in_scroll_region = false; @@ -558,7 +560,7 @@ case 'e': case 'B': { if (y + ctx->esc_values[0] > ctx->rows - 1) - ctx->esc_values[0] = (ctx->rows - 1) - y; + ctx->esc_values[0] = (uint32_t)((ctx->rows - 1) - y); size_t orig_y = y; size_t dest_y = y + ctx->esc_values[0]; bool will_be_in_scroll_region = false; @@ -575,12 +577,12 @@ case 'a': case 'C': if (x + ctx->esc_values[0] > ctx->cols - 1) - ctx->esc_values[0] = (ctx->cols - 1) - x; + ctx->esc_values[0] = (uint32_t)((ctx->cols - 1) - x); ctx->set_cursor_pos(ctx, x + ctx->esc_values[0], y); break; case 'D': if (ctx->esc_values[0] > x) - ctx->esc_values[0] = x; + ctx->esc_values[0] = (uint32_t)(x); ctx->set_cursor_pos(ctx, x - ctx->esc_values[0], y); break; case 'c': @@ -591,14 +593,14 @@ case 'd': ctx->esc_values[0] -= 1; if (ctx->esc_values[0] >= ctx->rows) - ctx->esc_values[0] = ctx->rows - 1; + ctx->esc_values[0] = (uint32_t)(ctx->rows - 1); ctx->set_cursor_pos(ctx, x, ctx->esc_values[0]); break; case 'G': case '`': ctx->esc_values[0] -= 1; if (ctx->esc_values[0] >= ctx->cols) - ctx->esc_values[0] = ctx->cols - 1; + ctx->esc_values[0] = (uint32_t)(ctx->cols - 1); ctx->set_cursor_pos(ctx, ctx->esc_values[0], y); break; case 'H': @@ -610,9 +612,9 @@ ctx->esc_values[1]--; } if (ctx->esc_values[1] >= ctx->cols) - ctx->esc_values[1] = ctx->cols - 1; + ctx->esc_values[1] = (uint32_t)(ctx->cols - 1); if (ctx->esc_values[0] >= ctx->rows) - ctx->esc_values[0] = ctx->rows - 1; + ctx->esc_values[0] = (uint32_t)(ctx->rows - 1); ctx->set_cursor_pos(ctx, ctx->esc_values[1], ctx->esc_values[0]); break; case 'M': { @@ -944,7 +946,7 @@ return 0; } - int mk_wcwidth(uint32_t ucs) { + static int mk_wcwidth(uint32_t ucs) { /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ static const struct interval combining[] = { @@ -1223,7 +1225,7 @@ int cc = unicode_to_cp437(ctx->code_point); if (cc == -1) { - size_t replacement_width = (size_t)mk_wcwidth(ctx->code_point); + size_t replacement_width = (size_t)mk_wcwidth((uint32_t)ctx->code_point); if (replacement_width > 0) { ctx->raw_putchar(ctx, 0xfe); } @@ -1231,7 +1233,7 @@ ctx->raw_putchar(ctx, ' '); } } else { - ctx->raw_putchar(ctx, cc); + ctx->raw_putchar(ctx, (uint8_t)cc); } return; } diff --git a/source/kernel/C/interrupts/idt.c b/source/kernel/C/interrupts/idt.c index dd2d15f..6cc6e18 100755 --- a/source/kernel/C/interrupts/idt.c +++ b/source/kernel/C/interrupts/idt.c @@ -23,20 +23,19 @@ extern void* irq_stub_table[]; IDTEntry idt_entries[256]; -IDTPointer idt_ptr = (IDTPointer) -{ - (uint16_t)sizeof(idt_entries) - 1, - (uintptr_t)&idt_entries[0] +IDTPointer idt_ptr = { + (uint16_t)(sizeof(idt_entries) - 1U), + 0U }; void setIdtEntry(IDTEntry *target, uint64_t offset, uint16_t selector, uint8_t ist, uint8_t type_attributes) { - target->offset_1 = offset & 0xFFFF; + target->offset_1 = (uint16_t)(offset & 0xFFFFU); target->selector = selector; target->ist = ist; target->type_attributes = type_attributes; - target->offset_2 = (offset >> 16) & 0xFFFF; - target->offset_3 = (offset >> 32) & 0xFFFFFFFF; + target->offset_2 = (uint16_t)((offset >> 16) & 0xFFFFU); + target->offset_3 = (uint32_t)((offset >> 32) & 0xFFFFFFFFU); target->zero = 0; } @@ -108,6 +107,7 @@ void initIdt(void) outb(0x21, 0xf8); // 0xfd for keyboard only and for mouse + keyboard 0xf8 (if sb 16 support then 0x??) outb(0xa1, 0xef); // 0xff for keyboard only and for mouse + keyboard 0xef + idt_ptr.offset = (uintptr_t)&idt_entries[0]; __asm__ volatile("lidt %0" : : "m"(idt_ptr)); set_interrupts(); init_syscall(); diff --git a/source/kernel/C/interrupts/isr.c b/source/kernel/C/interrupts/isr.c index 1eaa8b9..ce30ae7 100755 --- a/source/kernel/C/interrupts/isr.c +++ b/source/kernel/C/interrupts/isr.c @@ -17,6 +17,7 @@ #include #include #include +#include irq_handler interrupt_handlers[256]; @@ -93,6 +94,7 @@ void irqHandler(InterruptFrame* frame) } void rtl8139_handler(InterruptFrame* frame) { + (void)frame; uint16_t status = inw(RTL8139->io_base + 0x3e); outw(RTL8139->io_base + 0x3E, 0x05); if(status & TOK) { diff --git a/source/kernel/C/kernel.c b/source/kernel/C/kernel.c index 2656753..e1b031b 100755 --- a/source/kernel/C/kernel.c +++ b/source/kernel/C/kernel.c @@ -27,6 +27,8 @@ int64* wm_addr; int64* font_address = null; +extern void ksh_exec(void); + // The Limine requests can be placed anywhere, but it is important that // the compiler does not optimise them away, so, usually, they should // be made volatile or equivalent. @@ -51,7 +53,7 @@ static volatile struct limine_boot_time_request boot_time_request = { }; struct limine_module_request module_request = { - LIMINE_MODULE_REQUEST, 0, null + LIMINE_MODULE_REQUEST, 0, null, 0, null }; struct flanterm_context *ft_ctx = null; @@ -62,7 +64,7 @@ bool isBufferReady = no; int32 ctr = 0; -void ap_entry(struct limine_smp_info *info) { +static void ap_entry(struct limine_smp_info *info) { #if defined (__x86_64__) printf("LAPIC ID: 0x%x", info->lapic_id); #elif defined (__aarch64__) @@ -84,18 +86,20 @@ void ap_entry(struct limine_smp_info *info) { uint32_t mouseColor = MOUSE_COLOR_DEFAULT; -void mouseMovementHandler(int64_t xRel, int64_t yRel) +__attribute__((unused)) static void mouseMovementHandler(int64_t xRel, int64_t yRel) { + (void)xRel; + (void)yRel; ivec2 lastMousePos = GetLastMousePosition(); ivec2 mousePos = GetMousePosition(); // glDrawLine((uvec2){0, 0}, (uvec2){lastMousePos.x, lastMousePos.y}, 0x000000); // glDrawLine((uvec2){0, 0}, (uvec2){mousePos.x, mousePos.y}, mouseColor); - print_bitmap(lastMousePos.x, lastMousePos.y, 8, 16, mouse_cursor, 0x000000); - print_bitmap(mousePos.x, mousePos.y, 8, 16, mouse_cursor, mouseColor); + print_bitmap((int)lastMousePos.x, (int)lastMousePos.y, 8, 16, mouse_cursor, 0x000000); + print_bitmap((int)mousePos.x, (int)mousePos.y, 8, 16, mouse_cursor, mouseColor); } -void mouseButtonHandler(uint8_t button, uint8_t action) +__attribute__((unused)) static void mouseButtonHandler(uint8_t button, uint8_t action) { if (action == MOUSE_BUTTON_RELEASE) { @@ -144,8 +148,8 @@ void main(void) { info("Multiple framebuffers detected! using the first one.", __FILE__); } - terminal_rows = ft_ctx->rows; - terminal_columns = ft_ctx->cols; + terminal_rows = (int)ft_ctx->rows; + terminal_columns = (int)ft_ctx->cols; fb_width = framebuffer->width; fb_height = framebuffer->height; @@ -153,11 +157,8 @@ void main(void) { probe_serial(); } - int64 kernel_phys_start = ((int64)kstart) + (int64)KERNEL_OFFSET; - int64 kernel_phys_end = ((int64)kend) + (int64)KERNEL_OFFSET; - - debug_printf("KERNEL STR -> %z : %z\n", (int64)virtual_to_physical(kstart), kstart); - debug_printf("KERNEL END -> %z : %z\n", (int64)virtual_to_physical(kend), kend); + debug_printf("KERNEL STR -> %z : %z\n", (int64)virtual_to_physical((uint64_t)(uintptr_t)kstart), kstart); + debug_printf("KERNEL END -> %z : %z\n", (int64)virtual_to_physical((uint64_t)(uintptr_t)kend), kend); /** * ! In memory, kernel is loaded at higher half and at 0x8000000. @@ -214,9 +215,9 @@ void main(void) { } printf("Total CPU(s): %d", smp_request.response->cpu_count); - for(int i=0;icpu_count;i++){ - printf("Processor ID [%d] : 0x%X", i+1, smp_request.response->cpus[i]->processor_id); - printf("Local APIC ID [%d] : 0x%X", i+1, smp_request.response->cpus[i]->lapic_id); + for(uint64_t i=0;icpu_count;i++){ + printf("Processor ID [%d] : 0x%X", (int)(i+1U), smp_request.response->cpus[i]->processor_id); + printf("Local APIC ID [%d] : 0x%X", (int)(i+1U), smp_request.response->cpus[i]->lapic_id); if (smp_request.response->cpus[i]->lapic_id != smp_request.response->bsp_lapic_id) { uint32_t old_ctr = __atomic_load_n(&ctr, __ATOMIC_SEQ_CST); diff --git a/source/kernel/C/logger.c b/source/kernel/C/logger.c index ea3c8c7..2324cb0 100755 --- a/source/kernel/C/logger.c +++ b/source/kernel/C/logger.c @@ -437,7 +437,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap) return outpos; } -void print_bitmap(int x, int y, int w, int h, bool* pixels, int32 color) { +void print_bitmap(int x, int y, int w, int h, const bool* pixels, int32 color) { int i, j, l; for (l = j = 0; l < h; l++) { for (i = 0; i < w; i++, j++) { diff --git a/source/kernel/C/pci.c b/source/kernel/C/pci.c index 56a43fa..bee3ed8 100755 --- a/source/kernel/C/pci.c +++ b/source/kernel/C/pci.c @@ -14,10 +14,10 @@ int gpu_index = 0; int total_devices = 0; cstring display_adapter_name = "Frost Generic Display Adapter"; -cstring GPUName[1] = {"Frost Generic Display Driver for Graphics Processing Unit"}; // Max 2 GPUs allowed +cstring GPUName[2] = {"Frost Generic Display Driver for Graphics Processing Unit"}; // Max 2 GPUs allowed int64* graphics_base_Address = null; -string using_graphics_card = "unknown"; +cstring using_graphics_card = "unknown"; /** * @brief Function to read a 32-bit value from the PCI configuration space @@ -29,13 +29,13 @@ string using_graphics_card = "unknown"; * @return int32 */ int32 pci_config_read_dword(int8 bus, int8 slot, int8 func, int8 offset) { - int32 address = (1 << 31) | (bus << 16) | (slot << 11) | (func << 8) | (offset & 0xFC); + int32 address = (int32)((1U << 31) | ((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) | ((uint32_t)offset & 0xFCU)); outl(PCI_CONFIG_ADDRESS, address); return inl(PCI_CONFIG_DATA); } void pci_config_write_dword(int8 bus, int8 slot, int8 func, int8 offset, uint32_t value) { - int32 address = (1 << 31) | (bus << 16) | (slot << 11) | (func << 8) | (offset & 0xFC); + int32 address = (int32)((1U << 31) | ((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) | ((uint32_t)offset & 0xFCU)); outl(PCI_CONFIG_ADDRESS, address); outl(PCI_CONFIG_DATA, value); } @@ -52,7 +52,7 @@ void pci_config_write_dword(int8 bus, int8 slot, int8 func, int8 offset, uint32_ int32 get_ahci_bar_address(int8 bus, int slot, int func, int bar_num) { int bar_offset = 0x10 + (bar_num * 4); - return pci_config_read_dword(bus, slot, func, bar_offset); + return pci_config_read_dword(bus, (int8)slot, (int8)func, (int8)bar_offset); } /** @@ -69,12 +69,12 @@ int32 get_ahci_bar_address(int8 bus, int slot, int func, int bar_num) { */ int16 pci_read_word(int16 bus, int16 slot, int16 func, int16 offset) { - int64 address; - int64 lbus = (int64)bus; - int64 lslot = (int64)slot; - int64 lfunc = (int64)func; + uint32_t address; + uint32_t lbus = (uint32_t)bus; + uint32_t lslot = (uint32_t)slot; + uint32_t lfunc = (uint32_t)func; int16 tmp = 0; - address = (int64)((lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | ((int32)0x80000000)); + address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | ((uint32_t)offset & 0xfcU) | 0x80000000U); outl(0xCF8, address); tmp = (int16)((inl(0xCFC) >> ((offset & 2) * 8)) & 0xffff); return (tmp); @@ -92,7 +92,7 @@ int16 pci_read_word(int16 bus, int16 slot, int16 func, int16 offset) int16 getVendorID(int16 bus, int16 device, int16 function) { int32 r0 = pci_read_word(bus,device,function,0); - return r0; + return (int16)r0; } /** @@ -106,15 +106,15 @@ int16 getVendorID(int16 bus, int16 device, int16 function) int16 getDeviceID(int16 bus, int16 device, int16 function) { int32 r0 = pci_read_word(bus,device,function,2); - return r0; + return (int16)r0; } int8 getRevision(int16 bus, int16 slot, int16 func) { - return pci_read_word(bus, slot, func, 0x08) & 0xFF; + return (int8)(pci_read_word(bus, slot, func, 0x08) & 0xFFU); } int8 getProgIF(int16 bus, int16 slot, int16 func) { - return pci_config_read_dword(bus, slot, func, 0x08) >> 8; + return (int8)((pci_config_read_dword((int8)bus, (int8)slot, (int8)func, 0x08) >> 8U) & 0xFFU); } /** @@ -128,7 +128,7 @@ int8 getProgIF(int16 bus, int16 slot, int16 func) { int16 getClassId(int16 bus, int16 device, int16 function) { int32 r0 = pci_read_word(bus,device,function,0xA); - return (r0 & ~0x00FF) >> 8; + return (int16)((r0 & 0xFF00U) >> 8U); } /** @@ -142,7 +142,7 @@ int16 getClassId(int16 bus, int16 device, int16 function) int16 getSubClassId(int16 bus, int16 device, int16 function) { int32 r0 = pci_read_word(bus,device,function,0xA); - return (r0 & ~0xFF00); + return (int16)(r0 & 0x00FFU); } char vendorNames[MAX_PCI_DEVICES][64]; @@ -170,37 +170,35 @@ void probe_pci(void){ { for(int32 function = 0; function < 8; function++) { - int16 vendor = getVendorID(bus, slot, function); + int16 vendor = getVendorID((int16)bus, (int16)slot, (int16)function); if(vendor == 0xffff) continue; - int16 device = getDeviceID(bus, slot, function); - int16 classid = getClassId(bus, slot, function); - int16 subclassid = getSubClassId(bus, slot, function); - int16 revision = getRevision(bus, slot, function); - int8 prog_if = getProgIF(bus, slot, function); + int16 device = getDeviceID((int16)bus, (int16)slot, (int16)function); + int16 classid = getClassId((int16)bus, (int16)slot, (int16)function); + int16 subclassid = getSubClassId((int16)bus, (int16)slot, (int16)function); + int16 revision = getRevision((int16)bus, (int16)slot, (int16)function); + int8 prog_if = getProgIF((int16)bus, (int16)slot, (int16)function); - string vendorName = parse_vendor(vendor); - string className = parse_class(classid); + cstring vendorName = parse_vendor(vendor); + cstring className = parse_class(classid); char deviceName[64]; strcpy(deviceName, "Unknown Device"); - const pci_id_entry_t* entry = pci_lookup(vendor, device, classid); + const pci_id_entry_t* entry = pci_lookup(vendor, device, (uint8_t)classid); if (entry) { strncpy(deviceName, entry->name, sizeof(deviceName) - 1); if (entry->is_gpu) { - display_adapter_name = deviceName; - GPUName[gpu_index++] = deviceName; + /* assigned after device name is copied to stable storage */ } if (entry->probe) - entry->probe(bus, slot, function); + entry->probe((uint8_t)bus, (uint8_t)slot, (uint8_t)function); } else if (classid == 0x03) { cstring gpu = auto_name_gpu(vendor, device); strncpy(deviceName, gpu, sizeof(deviceName) - 1); - display_adapter_name = deviceName; - GPUName[gpu_index++] = deviceName; + /* assigned after device name is copied to stable storage */ } else { snprintf(deviceName, sizeof(deviceName), "Unknown Device (0x%04X)", device); } @@ -209,10 +207,10 @@ void probe_pci(void){ if (classid == 0x01 && subclassid == 0x06 && prog_if == 0x01) { done("AHCI controller detected (generic)", __FILE__); - probe_ahci(bus, slot, function); + probe_ahci((uint8_t)bus, (uint8_t)slot, (uint8_t)function); } else if (classid == 0x01 && subclassid == 0x08 && prog_if == 0x02) { done("NVMe controller detected (generic)", __FILE__); - probe_nvme(bus, slot, function); + probe_nvme((uint8_t)bus, (uint8_t)slot, (uint8_t)function); } print(green_color); @@ -226,17 +224,21 @@ void probe_pci(void){ strncpy(vendorNames[i], vendorName, 63); strncpy(deviceNames[i], deviceName, 63); strncpy(classNames[i], className, 63); - pciLocations[i] = (pci_location_t){bus, slot, function}; + pciLocations[i] = (pci_location_t){(int16)bus, (int16)slot, (int16)function}; vendors[i] = vendor; devices[i] = device; classes[i] = classid; subclasses[i] = subclassid; - revisions[i] = revision; + revisions[i] = (int8)revision; vendorNames[i][63] = 0; deviceNames[i][63] = 0; classNames[i][63] = 0; + if (classid == 0x03 && gpu_index < 2) { + display_adapter_name = deviceNames[i]; + GPUName[gpu_index++] = deviceNames[i]; + } i++; } } diff --git a/source/kernel/C/pci_id.c b/source/kernel/C/pci_id.c index 8770924..c615926 100644 --- a/source/kernel/C/pci_id.c +++ b/source/kernel/C/pci_id.c @@ -11,6 +11,7 @@ #include #include +#include static pci_id_entry_t pci_ids[] = { @@ -94,8 +95,9 @@ static pci_id_entry_t pci_ids[] = { {0, 0, 0, NULL, 0, NULL} }; -string parse_vendor(int16 vendor){ - string vendorName; +cstring parse_vendor(int16 vendor){ + cstring vendorName; + static char unknown_vendor[20]; switch (vendor) { case 0x8086: @@ -128,16 +130,16 @@ string parse_vendor(int16 vendor){ vendorName = "Red Hat, Inc."; break; default: - unsigned char str[20]; - itoa(vendor, str, sizeof(str), 16); - vendorName = str; + itoa((int)vendor, unknown_vendor, (int)sizeof(unknown_vendor), 16); + vendorName = unknown_vendor; } return vendorName; } -string parse_class(int16 classid){ - string className; +cstring parse_class(int16 classid){ + cstring className; + static char unknown_class[20]; switch (classid) { case 0x01: @@ -204,9 +206,8 @@ string parse_class(int16 classid){ className = "Unassigned"; break; default: - unsigned char str[20]; - itoa(classid, str, sizeof(str), 16); - className = str; + itoa((int)classid, unknown_class, (int)sizeof(unknown_class), 16); + className = unknown_class; } return className; @@ -252,7 +253,7 @@ cstring auto_name_gpu(int16 vendor, int16 device) void probe_ahci(uint8_t bus, uint8_t slot, uint8_t function) { - ahci_hba_mem_t* abar = (ahci_hba_mem_t*)(pci_config_read_dword(bus, slot, function, 0x24) & ~0xF); + ahci_hba_mem_t* abar = (ahci_hba_mem_t*)(uintptr_t)(pci_config_read_dword(bus, slot, function, 0x24) & 0xFFFFFFF0U); if (abar && abar != (void*)0xFFFFFFFF) { done("Found AHCI BAR!", __FILE__); @@ -266,7 +267,7 @@ void probe_rtl8139(uint8_t bus, uint8_t slot, uint8_t function) { RTL8139->io_base = (uint16_t)(pci_read_word(bus, slot, function, RTL8139_IOADDR1) & 0xFFFC); - int8_t irq = pci_read_word(bus, slot, function, RTL8139_IRQ_LINE); + uint8_t irq = (uint8_t)(pci_read_word(bus, slot, function, RTL8139_IRQ_LINE) & 0xFFU); printf("Handler number : 0x%x", irq); registerInterruptHandler(irq, rtl8139_handler); diff --git a/source/kernel/C/pit.c b/source/kernel/C/pit.c index d20ec07..1004c50 100755 --- a/source/kernel/C/pit.c +++ b/source/kernel/C/pit.c @@ -11,7 +11,7 @@ #include #include -volatile int pit_ticks = 0; +volatile uint64_t pit_ticks = 0; #define pit_freq 100 // Hz @@ -25,12 +25,12 @@ void init_pit(void) { uint32_t divisor = 1193180 / pit_freq; // PIT operates at 1193180 Hz outb(0x43, 0x36); // Command byte: Channel 0, lobyte/hibyte, mode 3 (square wave generator) - outb(0x40, divisor & 0xFF); // Set low byte of divisor - outb(0x40, (divisor >> 8) & 0xFF); // Set high byte of divisor + outb(0x40, (int8)(divisor & 0xFFU)); // Set low byte of divisor + outb(0x40, (int8)((divisor >> 8) & 0xFFU)); // Set high byte of divisor } void pit_sleep(uint32_t milliseconds) { - uint32_t target_ticks = pit_ticks + (milliseconds / (1000 / pit_freq)); + uint64_t target_ticks = pit_ticks + (uint64_t)(milliseconds / (1000U / pit_freq)); while (pit_ticks < target_ticks) { asm volatile("hlt"); diff --git a/source/kernel/C/rtc.c b/source/kernel/C/rtc.c index e013130..04d5d9a 100755 --- a/source/kernel/C/rtc.c +++ b/source/kernel/C/rtc.c @@ -13,7 +13,7 @@ // --- Helpers --- int8 bcd_to_bin(int8 val) { - return (val & 0x0F) + ((val >> 4) * 10); + return (int8)((val & 0x0FU) + (((val >> 4U) & 0x0FU) * 10U)); } int8 read_rtc_register(int8 reg) { @@ -41,7 +41,7 @@ void init_rtc(void) { // Enable periodic interrupts if desired, not strictly necessary int8 prev = read_rtc_register(0x0B); outb(RTC_PORT, 0x0B); - outb(RTC_DATA, prev | 0x40); // Set bit 6 = Update-Ended Interrupt Enable (optional) + outb(RTC_DATA, (int8)(prev | 0x40U)); // Set bit 6 = Update-Ended Interrupt Enable (optional) done("Initialized RTC", __FILE__); } @@ -57,7 +57,7 @@ void update_system_time(int8 *second, int8 *minute, int8 *hour, int8 *day, int8 int8 hr = rtc_read_stable(RTC_HOURS); int8 day_r = rtc_read_stable(RTC_DAY); int8 mon = rtc_read_stable(RTC_MONTH); - int16 yr = rtc_read_stable(RTC_YEAR); + int8 yr = rtc_read_stable(RTC_YEAR); int8 cent = rtc_read_stable(RTC_CENTURY); // optional if (is_bcd) { @@ -72,7 +72,7 @@ void update_system_time(int8 *second, int8 *minute, int8 *hour, int8 *day, int8 // Handle 12-hour mode if (!is_24h && (hr & 0x80)) { - hr = ((hr & 0x7F) + 12) % 24; + hr = (int8)(((hr & 0x7FU) + 12U) % 24U); } *second = sec; @@ -80,7 +80,7 @@ void update_system_time(int8 *second, int8 *minute, int8 *hour, int8 *day, int8 *hour = hr; *day = day_r; *month = mon; - *year = yr; + *year = (int16)yr; } void display_time(void) { diff --git a/source/kernel/C/strings.c b/source/kernel/C/strings.c index e491235..e59c40e 100755 --- a/source/kernel/C/strings.c +++ b/source/kernel/C/strings.c @@ -20,7 +20,7 @@ const char caps_hex_digits[] = "0123456789ABCDEF"; * @param s (char[]) The string to know the length of. * @return int */ -int strlen(char s[]) { +int strlen(cstring s) { int i = 0; while (s[i] != '\0') ++i; return i; diff --git a/source/kernel/C/user-input/keyboard.c b/source/kernel/C/user-input/keyboard.c index 1fe4d63..8398d6a 100755 --- a/source/kernel/C/user-input/keyboard.c +++ b/source/kernel/C/user-input/keyboard.c @@ -15,6 +15,7 @@ #include #include #include +#include bool enable_keyboard = yes; static ring_buffer_t kb_rb; @@ -76,6 +77,7 @@ uint8_t modifiers = 0; void process_keyboard(InterruptFrame* frame) { + (void)frame; if (!enable_keyboard) { outb(0x20, 0x20); return; @@ -97,7 +99,7 @@ uint8_t getmodifiers(void) return modifiers; } -extern volatile int pit_ticks; +extern volatile uint64_t pit_ticks; uint8_t getc(void) { uint8_t sc; @@ -105,7 +107,7 @@ uint8_t getc(void) for (;;) { if (rb_pop(&kb_rb, &sc) == 0) { - return handle_char_from_scancode(sc); + return (uint8_t)handle_char_from_scancode(sc); } if (pit_ticks != last_tick) { @@ -146,18 +148,18 @@ int handle_char_from_scancode(uint8_t data) switch (key) { case 0x2A: // LSHIFT release - modifiers &= ~MOD_LSHIFT; + modifiers = (uint8_t)(modifiers & (uint8_t)~MOD_LSHIFT); return 0; case 0x36: // RSHIFT release - modifiers &= ~MOD_RSHIFT; + modifiers = (uint8_t)(modifiers & (uint8_t)~MOD_RSHIFT); return 0; case 0x1D: // CTRL release - modifiers &= ~MOD_LCTRL; + modifiers = (uint8_t)(modifiers & (uint8_t)~MOD_LCTRL); return 0; case 0x38: // ALT release - modifiers &= ~MOD_LALT; + modifiers = (uint8_t)(modifiers & (uint8_t)~MOD_LALT); return 0; } @@ -221,10 +223,10 @@ int handle_char_from_scancode(uint8_t data) return 0; // -------- Character conversion -------- - bool use_shift = (modifiers & (MOD_LSHIFT | MOD_RSHIFT)); + bool use_shift = (modifiers & (uint8_t)(MOD_LSHIFT | MOD_RSHIFT)) != 0U; // Caps lock XOR shift logic - bool uppercase = use_shift ^ (modifiers & MOD_CAPSLOCK); + bool uppercase = use_shift ^ ((modifiers & MOD_CAPSLOCK) != 0U); char c = scancode_to_char(data, uppercase); diff --git a/source/kernel/C/user-input/ps2-mouse.c b/source/kernel/C/user-input/ps2-mouse.c index cf79076..94e81b6 100755 --- a/source/kernel/C/user-input/ps2-mouse.c +++ b/source/kernel/C/user-input/ps2-mouse.c @@ -11,38 +11,42 @@ extern int64 fb_width; extern int64 fb_height; -void ps2_mouse_wait(void){ +static void handle_ps2_mouse(int8 data); +static void process_mouse_packet(void); +static void handle_click(uint8_t type, ivec2 position); + +static void ps2_mouse_wait(void){ int64 timeout = 100000; while (timeout--){ - if ((inb(0x64) & 0b10) == 0){ + if ((inb(0x64) & 0x02U) == 0){ return; } } } -void ps2_mouse_wait_input(void){ +static void ps2_mouse_wait_input(void){ int64 timeout = 100000; while (timeout--){ - if (inb(0x64) & 0b1){ + if (inb(0x64) & 0x01U){ return; } } } -void ps2_mouse_write(int8 value){ +static void ps2_mouse_write(int8 value){ ps2_mouse_wait(); outb(0x64, 0xD4); ps2_mouse_wait(); outb(0x60, value); } -int8 ps2_mouse_read(void){ +static int8 ps2_mouse_read(void){ ps2_mouse_wait_input(); return inb(0x60); } int8 mouse_cycle = 0; -int64 mouse_packet[4]; +uint8_t mouse_packet[4]; bool isMousePacketReady = false; ivec2 current_mouse_position; ivec2 previous_mouse_position; @@ -70,6 +74,7 @@ const bool mouse_cursor[] = { }; void process_mouse(InterruptFrame* frame){ + (void)frame; int8 data = inb(0x60); handle_ps2_mouse(data); @@ -77,7 +82,7 @@ void process_mouse(InterruptFrame* frame){ outb(0xA0, 0x20); // End PIC Slave } -void handle_ps2_mouse(int8 data){ +static void handle_ps2_mouse(int8 data){ process_mouse_packet(); static bool skip = true; if (skip) { @@ -87,7 +92,7 @@ void handle_ps2_mouse(int8 data){ switch(mouse_cycle){ case 0: - if ((data & 0b00001000) == 0) break; + if ((data & 0x08U) == 0) break; mouse_packet[0] = data; mouse_cycle++; break; @@ -123,50 +128,48 @@ ivec2 GetLastMousePosition(void) return previous_mouse_position; } -void process_mouse_packet(void){ +static void process_mouse_packet(void){ if (!isMousePacketReady) return; - bool xNegative, yNegative, xOverflow, yOverflow; - - xNegative = mouse_packet[0] & PS2_x; - yNegative = mouse_packet[0] & PS2_y; - xOverflow = mouse_packet[0] & PS2_x_overflow; - yOverflow = mouse_packet[0] & PS2_y_overflow; + bool xNegative = (mouse_packet[0] & (int64_t)PS2_x) != 0; + bool yNegative = (mouse_packet[0] & (int64_t)PS2_y) != 0; + bool xOverflow = (mouse_packet[0] & (int64_t)PS2_x_overflow) != 0; + bool yOverflow = (mouse_packet[0] & (int64_t)PS2_y_overflow) != 0; if (!xNegative){ - current_mouse_position.x += mouse_packet[1]; + current_mouse_position.x += (int64_t)mouse_packet[1]; if (xOverflow){ - current_mouse_position.x += (int64)255; + current_mouse_position.x += 255; } } else { - mouse_packet[1] = ((int64)256) - mouse_packet[1]; - current_mouse_position.x -= mouse_packet[1]; + mouse_packet[1] = (uint8_t)(256U - mouse_packet[1]); + current_mouse_position.x -= (int64_t)mouse_packet[1]; if (xOverflow){ - current_mouse_position.x -= (int64)255; + current_mouse_position.x -= 255; } } if (!yNegative) { - current_mouse_position.y -= mouse_packet[2]; + current_mouse_position.y -= (int64_t)mouse_packet[2]; if (yOverflow) - current_mouse_position.y -= (int64)255; + current_mouse_position.y -= 255; } else { - mouse_packet[2] = ((int64)256) - mouse_packet[2]; - current_mouse_position.y += mouse_packet[2]; + mouse_packet[2] = (uint8_t)(256U - mouse_packet[2]); + current_mouse_position.y += (int64_t)mouse_packet[2]; if (yOverflow) - current_mouse_position.y += (int64)255; + current_mouse_position.y += 255; } if (current_mouse_position.x < 0) current_mouse_position.x = 0; - if (current_mouse_position.x > fb_width) current_mouse_position.x = fb_width - 1; + if (fb_width > 0U && current_mouse_position.x >= (int64_t)fb_width) current_mouse_position.x = (int64_t)(fb_width - 1U); if (current_mouse_position.y < 0) current_mouse_position.y = 0; - if (current_mouse_position.y > fb_height) current_mouse_position.y = fb_height - 1; + if (fb_height > 0U && current_mouse_position.y >= (int64_t)fb_height) current_mouse_position.y = (int64_t)(fb_height - 1U); int64_t deltaX = current_mouse_position.x - previous_mouse_position.x; int64_t deltaY = current_mouse_position.y - previous_mouse_position.y; @@ -176,9 +179,9 @@ void process_mouse_packet(void){ mLastMouseButtonState = mMouseButtonState; mMouseButtonState = 0; - mMouseButtonState |= mouse_packet[0] & PS2_left_button; - mMouseButtonState |= mouse_packet[0] & PS2_middle_button; - mMouseButtonState |= mouse_packet[0] & PS2_right_button; + mMouseButtonState |= (uint8_t)(mouse_packet[0] & (int64_t)PS2_left_button); + mMouseButtonState |= (uint8_t)(mouse_packet[0] & (int64_t)PS2_middle_button); + mMouseButtonState |= (uint8_t)(mouse_packet[0] & (int64_t)PS2_right_button); if (mLastMouseButtonState != mMouseButtonState && mButtonHandler != NULL) { @@ -196,7 +199,8 @@ void process_mouse_packet(void){ previous_mouse_position = current_mouse_position; } -void handle_click(int64 type, ivec2 position){ +__attribute__((unused)) static void handle_click(uint8_t type, ivec2 position){ + (void)position; switch (type) { case PS2_left_button: @@ -220,15 +224,15 @@ void init_ps2_mouse(void){ outb(0x64, 0x20); //tells the keyboard controller that we want to send a command to the mouse ps2_mouse_wait_input(); int8 status = inb(0x60); - status |= 0b10; + status |= 0x02U; ps2_mouse_wait(); outb(0x64, 0x60); ps2_mouse_wait(); outb(0x60, status); // setting the correct bit is the "compaq" status byte ps2_mouse_write(0xF6); - ps2_mouse_read(); + (void)ps2_mouse_read(); ps2_mouse_write(0xF4); - ps2_mouse_read(); + (void)ps2_mouse_read(); } \ No newline at end of file diff --git a/source/kernel/C/user-input/tty.c b/source/kernel/C/user-input/tty.c index feb497f..9a381b4 100644 --- a/source/kernel/C/user-input/tty.c +++ b/source/kernel/C/user-input/tty.c @@ -12,6 +12,7 @@ #include #include #include +#include static ring_buffer_t cooked_rb; static char cooked_storage[TTY_COOKED_MAX]; @@ -67,7 +68,7 @@ void tty_input_char(char c) { putc(c); } -extern volatile int pit_ticks; +extern volatile uint64_t pit_ticks; int tty_read(char* buf, uint64_t count) { if (!buf || count == 0) return 0; diff --git a/source/kernel/C/userland.c b/source/kernel/C/userland.c index fb2f904..b45d13d 100644 --- a/source/kernel/C/userland.c +++ b/source/kernel/C/userland.c @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include static uint64_t user_heap_break = USER_HEAP_VADDR; static uint64_t user_heap_mapped_end = USER_HEAP_VADDR; @@ -102,7 +105,7 @@ static uint64_t align_up_u64(uint64_t value, uint64_t align) { return (value + align - 1) & ~(align - 1); } -static uint64_t max_u64(uint64_t a, uint64_t b) { +__attribute__((unused)) static uint64_t max_u64(uint64_t a, uint64_t b) { return a > b ? a : b; } @@ -113,7 +116,7 @@ static uint64_t push_bytes_to_stack(uint64_t* stack_ptr, const void* src, uint64 } static uint64_t push_cstr_to_stack(uint64_t* stack_ptr, const char* str) { - return push_bytes_to_stack(stack_ptr, str, strlen(str) + 1); + return push_bytes_to_stack(stack_ptr, str, (uint64_t)strlen(str) + 1U); } static int string_array_count(const char* const* arr) { @@ -346,13 +349,13 @@ void userland_heap_init(void) { } uint64_t userland_brk(uint64_t requested_break) { - uint64_t heap_end = USER_HEAP_VADDR + USER_HEAP_SIZE; + uint64_t user_heap_end = USER_HEAP_VADDR + USER_HEAP_SIZE; if (requested_break == 0) { return user_heap_break; } - if (requested_break < USER_HEAP_VADDR || requested_break > heap_end) { + if (requested_break < USER_HEAP_VADDR || requested_break > user_heap_end) { return user_heap_break; }