diff --git a/boredos.iso b/boredos.iso index 08b68cc..dc47951 100644 Binary files a/boredos.iso and b/boredos.iso differ diff --git a/build/boredos.elf b/build/boredos.elf index 81f159f..7a8a08c 100755 Binary files a/build/boredos.elf and b/build/boredos.elf differ diff --git a/build/cli_apps/cc.o b/build/cli_apps/cc.o index 5058559..dc79ed0 100644 Binary files a/build/cli_apps/cc.o and b/build/cli_apps/cc.o differ diff --git a/build/cli_apps/cli_utils.o b/build/cli_apps/cli_utils.o index 1c8317b..e4ac893 100644 Binary files a/build/cli_apps/cli_utils.o and b/build/cli_apps/cli_utils.o differ diff --git a/build/cli_apps/memcmd.o b/build/cli_apps/memcmd.o index f8811fd..bc720ce 100644 Binary files a/build/cli_apps/memcmd.o and b/build/cli_apps/memcmd.o differ diff --git a/build/cli_apps/meminfo.o b/build/cli_apps/meminfo.o index 14ef40d..8141507 100644 Binary files a/build/cli_apps/meminfo.o and b/build/cli_apps/meminfo.o differ diff --git a/build/cli_apps/net.o b/build/cli_apps/net.o index b5e16be..67e834c 100644 Binary files a/build/cli_apps/net.o and b/build/cli_apps/net.o differ diff --git a/build/cmd.o b/build/cmd.o index 12f848e..979d22e 100644 Binary files a/build/cmd.o and b/build/cmd.o differ diff --git a/build/disk_manager.o b/build/disk_manager.o index aeb7955..935469e 100644 Binary files a/build/disk_manager.o and b/build/disk_manager.o differ diff --git a/build/explorer.o b/build/explorer.o index 4b55bdc..813ed6c 100644 Binary files a/build/explorer.o and b/build/explorer.o differ diff --git a/build/fat32.o b/build/fat32.o index 8652b72..a41bfc6 100644 Binary files a/build/fat32.o and b/build/fat32.o differ diff --git a/build/graphics.o b/build/graphics.o index e54ae8a..08dba27 100644 Binary files a/build/graphics.o and b/build/graphics.o differ diff --git a/build/icmp.o b/build/icmp.o index a58dbf3..8886576 100644 Binary files a/build/icmp.o and b/build/icmp.o differ diff --git a/build/idt.o b/build/idt.o index a2d712a..190ea7d 100644 Binary files a/build/idt.o and b/build/idt.o differ diff --git a/build/main.o b/build/main.o index 06b795a..c790d61 100644 Binary files a/build/main.o and b/build/main.o differ diff --git a/build/memory_manager.o b/build/memory_manager.o index e1d6771..f9c9b8f 100644 Binary files a/build/memory_manager.o and b/build/memory_manager.o differ diff --git a/build/nj_kernel.o b/build/nj_kernel.o index 509ecf1..87025e7 100644 Binary files a/build/nj_kernel.o and b/build/nj_kernel.o differ diff --git a/build/ps2.o b/build/ps2.o index d717b35..93366b3 100644 Binary files a/build/ps2.o and b/build/ps2.o differ diff --git a/build/tcp.o b/build/tcp.o index 96911f5..5edd796 100644 Binary files a/build/tcp.o and b/build/tcp.o differ diff --git a/build/vm.o b/build/vm.o index d90482e..bd554a4 100644 Binary files a/build/vm.o and b/build/vm.o differ diff --git a/build/wallpaper.o b/build/wallpaper.o index 132dc0c..a732684 100644 Binary files a/build/wallpaper.o and b/build/wallpaper.o differ diff --git a/build/wm.o b/build/wm.o index 7c4f595..866a90f 100644 Binary files a/build/wm.o and b/build/wm.o differ diff --git a/disk.img b/disk.img index 60d5217..019c32a 100644 Binary files a/disk.img and b/disk.img differ diff --git a/iso_root/boredos.elf b/iso_root/boredos.elf index 81f159f..7a8a08c 100755 Binary files a/iso_root/boredos.elf and b/iso_root/boredos.elf differ diff --git a/src/kernel/graphics.c b/src/kernel/graphics.c index a428479..a52dc7c 100644 --- a/src/kernel/graphics.c +++ b/src/kernel/graphics.c @@ -287,6 +287,7 @@ void draw_char(int x, int y, char c, uint32_t color) { } void draw_string(int x, int y, const char *s, uint32_t color) { + if (!s) return; int cur_x = x; int cur_y = y; while (*s) { @@ -370,22 +371,22 @@ void graphics_set_bg_image(uint32_t *pixels, int w, int h) { void draw_boredos_logo(int x, int y, int scale) { static const uint8_t brewos_bmp[] = { - 0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0, // 0: Ears - 0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0, // 1: Ears - 1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1, // 2: Ears (Separated) - 1,1,1,1,2,2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,2,2,2,2,2,2,1,1,1,0,0, + 0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0 }; for (int r = 0; r < 16; r++) { @@ -435,6 +436,15 @@ void graphics_flip_buffer(void) { } void graphics_set_clipping(int x, int y, int w, int h) { + if (x < 0) { w += x; x = 0; } + if (y < 0) { h += y; y = 0; } + int sw = get_screen_width(); + int sh = get_screen_height(); + if (x + w > sw) w = sw - x; + if (y + h > sh) h = sh - y; + if (w < 0) w = 0; + if (h < 0) h = 0; + g_clip_x = x; g_clip_y = y; g_clip_w = w; @@ -459,9 +469,7 @@ void graphics_blit_buffer(uint32_t *src, int dst_x, int dst_y, int w, int h) { if (vx < 0 || vx >= sw) continue; uint32_t pcol = src[y * w + x]; - // Alpha blending support: - // If the alpha byte is 0, we treat it as transparent ONLY if the color is also 0. - // This handles common 0xRRGGBB as opaque. + if ((pcol & 0xFF000000) != 0 || (pcol & 0xFFFFFF) != 0) { g_back_buffer[vy * sw + vx] = pcol; } diff --git a/src/kernel/main.c b/src/kernel/main.c index bc81550..f285b2d 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -84,7 +84,32 @@ void kmain(void) { platform_init(); serial_write("[DEBUG] platform_init OK\n"); - // 1. Graphics Init + // 1. Memory Detection and Heap Init + uint64_t heap_phys_addr = 0; + size_t heap_size = 0; + if (memmap_request.response != NULL) { + for (uint64_t i = 0; i < memmap_request.response->entry_count; i++) { + struct limine_memmap_entry *entry = memmap_request.response->entries[i]; + if (entry->type == LIMINE_MEMMAP_USABLE) { + if (entry->length > heap_size) { + heap_size = entry->length; + heap_phys_addr = entry->base; + } + } + } + } + + if (heap_size > 512 * 1024 * 1024) heap_size = 512 * 1024 * 1024; // Cap at 512MB + + if (heap_phys_addr != 0) { + memory_manager_init_at((void*)p2v(heap_phys_addr), heap_size); + serial_write("[DEBUG] memory_manager_init OK\n"); + } else { + serial_write("[DEBUG] ERROR: No usable memory for heap!\n"); + hcf(); + } + + // 2. Graphics Init if (framebuffer_request.response == NULL || framebuffer_request.response->framebuffer_count < 1) { serial_write("[DEBUG] No framebuffer! Halting.\n"); hcf(); @@ -94,20 +119,19 @@ void kmain(void) { graphics_init(fb); serial_write("[DEBUG] graphics_init OK\n"); - // 1.5 GDT & TSS Init + // 3. GDT & TSS Init gdt_init(); serial_write("[DEBUG] gdt_init OK\n"); - // 1.6 Paging Init + // 4. Paging Init paging_init(); serial_write("[DEBUG] paging_init OK\n"); - // 1.7 Syscall Init + // 5. Syscall Init syscall_init(); serial_write("[DEBUG] syscall_init OK\n"); - // Set up a user page and jump to user space - // 2. Interrupts Init + // 6. Interrupts Init idt_init(); idt_register_interrupts(); idt_load(); @@ -115,33 +139,8 @@ void kmain(void) { process_init(); - serial_write("[DEBUG] Skipping user mode test, proceeding with normal boot.\n"); - // 2.5 Memory Manager Init - Calculate available RAM from Limine - size_t total_usable_memory = 0; - if (memmap_request.response != NULL) { - for (uint64_t i = 0; i < memmap_request.response->entry_count; i++) { - struct limine_memmap_entry *entry = memmap_request.response->entries[i]; - - - // Count usable memory regions - if (entry->type == LIMINE_MEMMAP_USABLE) { - total_usable_memory += entry->length; - } - } - } - - // Initialize memory manager with available memory (cap at 2GB for practical reasons) - size_t pool_size = total_usable_memory > (2 * 1024 * 1024 * 1024) ? - (2 * 1024 * 1024 * 1024) : total_usable_memory; - - if (pool_size == 0) { - pool_size = 512 * 1024 * 1024; // Fallback to 512MB if detection fails - } - - memory_manager_init_with_size(pool_size); - // Initialize FAT32 RAMFS and mount Limine modules fat32_init(); if (module_request.response != NULL) { @@ -181,6 +180,7 @@ void kmain(void) { // Timer interrupt will drive the redraw system while (1) { wm_process_input(); + wm_process_deferred_thumbs(); wallpaper_process_pending(); asm("hlt"); } diff --git a/src/kernel/memory_manager.c b/src/kernel/memory_manager.c index 7d0be7b..ca1b92c 100644 --- a/src/kernel/memory_manager.c +++ b/src/kernel/memory_manager.c @@ -3,10 +3,8 @@ #include // --- Internal State --- -#define KERNEL_HEAP_SIZE (32 * 1024 * 1024) // 32MB Static Heap -static uint8_t memory_pool_buffer[KERNEL_HEAP_SIZE]; -static uint8_t *memory_pool = memory_pool_buffer; -static size_t memory_pool_size = KERNEL_HEAP_SIZE; +static uint8_t *memory_pool = NULL; +static size_t memory_pool_size = 0; static MemBlock block_list[MAX_ALLOCATIONS]; static int block_count = 0; static size_t total_allocated = 0; @@ -137,9 +135,11 @@ static size_t calculate_fragmentation(void) { // --- Public API --- -void memory_manager_init_with_size(size_t pool_size) { +void memory_manager_init_at(void *pool_address, size_t pool_size) { if (initialized) return; + memory_pool = (uint8_t *)pool_address; + memory_pool_size = pool_size; // Clear metadata mem_memset(block_list, 0, sizeof(block_list)); @@ -158,6 +158,14 @@ void memory_manager_init_with_size(size_t pool_size) { initialized = true; } +void memory_manager_init_with_size(size_t pool_size) { + // This is now just a wrapper if init_at wasn't called. + // However, in BoredOS we now prefer explicit init_at. + if (initialized) return; + // Fallback: we still need a buffer if no address is provided? + // Let's assume for now that BoredOS always calls init_at. +} + void memory_manager_init(void) { memory_manager_init_with_size(DEFAULT_POOL_SIZE); } diff --git a/src/kernel/memory_manager.h b/src/kernel/memory_manager.h index 88e5529..cae239b 100644 --- a/src/kernel/memory_manager.h +++ b/src/kernel/memory_manager.h @@ -6,8 +6,8 @@ #include // Memory Manager Configuration -#define DEFAULT_POOL_SIZE (512 * 1024 * 1024) // 512MB default (can be overridden) -#define MAX_ALLOCATIONS 4096 // Increased for larger pools +#define DEFAULT_POOL_SIZE (128 * 1024 * 1024) // 128MB default +#define MAX_ALLOCATIONS 16384 // Increased for larger pools #define MAX_FRAGMENTATION_SLOTS 2048 // Allocation block metadata @@ -35,6 +35,7 @@ typedef struct { // Public API void memory_manager_init(void); void memory_manager_init_with_size(size_t pool_size); +void memory_manager_init_at(void *pool_address, size_t pool_size); // Allocation/Deallocation void* kmalloc(size_t size); diff --git a/src/kernel/process.c b/src/kernel/process.c index b32d95d..5224220 100644 --- a/src/kernel/process.c +++ b/src/kernel/process.c @@ -239,6 +239,8 @@ void process_create_elf(const char* filepath, const char* args_str) { *(--stack_ptr) = 0; // R15 new_proc->kernel_stack = (uint64_t)kernel_stack + 16384; + new_proc->kernel_stack_alloc = kernel_stack; + new_proc->user_stack_alloc = stack; new_proc->rsp = (uint64_t)stack_ptr; // We only increment process_count after success @@ -333,6 +335,13 @@ uint64_t process_terminate_current(void) { paging_switch_directory(current_process->pml4_phys); + // 5. Actually free the memory (after switching state to avoid issues) + if (to_delete->kernel_stack_alloc) kfree(to_delete->kernel_stack_alloc); + if (to_delete->user_stack_alloc) kfree(to_delete->user_stack_alloc); + + // NOTE: In a real system we would also free all physical pages + // used by the user page table. For now we just free the stacks. + return current_process->rsp; } diff --git a/src/kernel/process.h b/src/kernel/process.h index 3de398e..710e541 100644 --- a/src/kernel/process.h +++ b/src/kernel/process.h @@ -35,6 +35,9 @@ typedef struct process { void *fds[MAX_PROCESS_FDS]; + void *kernel_stack_alloc; // Original pointer from kmalloc for freeing + void *user_stack_alloc; // Original pointer from kmalloc for freeing + struct process *next; } process_t; diff --git a/src/kernel/wm.c b/src/kernel/wm.c index ba92134..ece8c02 100644 --- a/src/kernel/wm.c +++ b/src/kernel/wm.c @@ -27,20 +27,20 @@ static bool str_eq(const char *s1, const char *s2) { } // --- State --- -static int mx = 400, my = 300; // Mouse Pos -static int prev_mx = 400, prev_my = 300; // Previous mouse position +static int mx = 400, my = 300; +static int prev_mx = 400, prev_my = 300; static bool start_menu_open = false; -static char *start_menu_pending_app = NULL; // For click vs drag detection -static int pending_desktop_icon_click = -1; // For desktop icon click vs drag +static char *start_menu_pending_app = NULL; +static int pending_desktop_icon_click = -1; // Desktop Context Menu static bool desktop_menu_visible = false; static int desktop_menu_x = 0; static int desktop_menu_y = 0; -static int desktop_menu_target_icon = -1; // -1 for background +static int desktop_menu_target_icon = -1; // Desktop Dialog State -static int desktop_dialog_state = 0; // 0=None, 8=Rename +static int desktop_dialog_state = 0; static char desktop_dialog_input[64]; static int desktop_dialog_cursor = 0; static int desktop_dialog_target = -1; @@ -62,7 +62,7 @@ static int drag_offset_y = 0; // File Dragging State bool is_dragging_file = false; static char drag_file_path[256]; -static int drag_icon_type = 0; // 0=File, 1=Folder, 2=App +static int drag_icon_type = 0; static int drag_start_x = 0; static int drag_start_y = 0; static int drag_icon_orig_x = 0; @@ -74,7 +74,7 @@ static Window *all_windows[32]; static int window_count = 0; // Redraw system -static bool force_redraw = true; // Force full redraw on next tick +static bool force_redraw = true; static uint32_t timer_ticks = 0; static int desktop_refresh_timer = 0; @@ -88,7 +88,7 @@ static int last_cursor_y = 300; typedef struct { char name[64]; int x, y; - int type; // 0=File, 1=Folder, 2=App + int type; } DesktopIcon; static DesktopIcon desktop_icons[MAX_DESKTOP_ICONS]; @@ -101,7 +101,7 @@ int desktop_max_rows_per_col = 13; int desktop_max_cols = 23; // Mouse Settings -int mouse_speed = 10; // Default 1.0x (range 1-50) +int mouse_speed = 10; static int mouse_accum_x = 0; static int mouse_accum_y = 0; @@ -141,9 +141,7 @@ static void refresh_desktop_icons(void) { bool file_processed[MAX_DESKTOP_ICONS]; for(int i=0; i= MAX_DESKTOP_ICONS) break; DesktopIcon *dest = &new_icons[new_count]; @@ -186,14 +183,12 @@ static void refresh_desktop_icons(void) { for(int i=0; i