From d25e5672015fd4d8cc41128db8279e2330db6771 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 7 Jan 2014 22:47:00 +0100 Subject: [PATCH] Testing --- bootloader/stage2.asm | 27 ++++++++++++++++++++++----- kernel/include/e820.hpp | 4 ++-- kernel/src/boot/boot_16.cpp | 13 ++++++++----- kernel/src/e820.cpp | 15 ++++++++++----- kernel/src/memory.cpp | 12 ++++++++++++ kernel/src/shell.cpp | 6 +++--- 6 files changed, 57 insertions(+), 20 deletions(-) diff --git a/bootloader/stage2.asm b/bootloader/stage2.asm index f97da415..4f7e0b2e 100644 --- a/bootloader/stage2.asm +++ b/bootloader/stage2.asm @@ -11,7 +11,9 @@ jmp second_step %include "intel_16.asm" +FREE_SEGMENT equ 0x5000 FREE_BASE equ 0x4500 + KERNEL_BASE equ 0x600 ; 0x600:0x0 (0x6000) DAP: @@ -42,7 +44,7 @@ second_step: mov ds, ax ; Used for disk access - xor ax, ax + mov ax, FREE_SEGMENT mov gs, ax mov si, load_kernel @@ -52,7 +54,7 @@ second_step: mov byte [DAP.count], 1 mov word [DAP.offset], FREE_BASE - mov word [DAP.segment], 0 + mov word [DAP.segment], FREE_SEGMENT mov dword [DAP.lba], 0 call extended_read @@ -64,7 +66,7 @@ second_step: mov byte [DAP.count], 1 mov word [DAP.offset], FREE_BASE - mov word [DAP.segment], 0 + mov word [DAP.segment], FREE_SEGMENT mov di, [partition_start] mov word [DAP.lba], di @@ -115,7 +117,7 @@ second_step: mov ah, [sectors_per_cluster] mov byte [DAP.count], ah mov word [DAP.offset], FREE_BASE - mov word [DAP.segment], 0 + mov word [DAP.segment], FREE_SEGMENT ; Compute LBA from root_dir_start mov ax, [root_dir_start] @@ -212,6 +214,12 @@ second_step: mov si, star call print_16 + mov di, [current_segment] + call print_int_16 + + mov si, star + call print_16 + movzx ax, [sectors_per_cluster] mov word [DAP.count], ax mov word [DAP.offset], 0x0 @@ -229,6 +237,15 @@ second_step: mov word [DAP.lba], ax + mov di, ax + call print_int_16 + + mov si, star + call print_16 + + mov di, [current_cluster] + call print_int_16 + call extended_read mov ax, [loaded_clusters] @@ -247,7 +264,7 @@ second_step: ; Read the FAT sector mov word [DAP.count], 1 mov word [DAP.offset], FREE_BASE - mov word [DAP.segment], 0x0 + mov word [DAP.segment], FREE_SEGMENT mov word [DAP.lba], ax call extended_read diff --git a/kernel/include/e820.hpp b/kernel/include/e820.hpp index 61694fdb..a54924c6 100644 --- a/kernel/include/e820.hpp +++ b/kernel/include/e820.hpp @@ -31,8 +31,8 @@ struct bios_e820_entry { uint16_t acpi; } __attribute__((packed)); -extern int16_t bios_e820_entry_count; -extern bios_e820_entry bios_e820_entries[MAX_E820_ENTRIES]; +//extern bios_e820_entry bios_e820_entries[MAX_E820_ENTRIES]; +//extern int16_t bios_e820_entry_count; struct mmapentry { uint64_t base; diff --git a/kernel/src/boot/boot_16.cpp b/kernel/src/boot/boot_16.cpp index 3e0bb614..f0d9f9a2 100644 --- a/kernel/src/boot/boot_16.cpp +++ b/kernel/src/boot/boot_16.cpp @@ -31,9 +31,8 @@ typedef uint64_t size_t; #define CODE_16 #include "e820.hpp" //Just for the address of the e820 map - -e820::bios_e820_entry e820::bios_e820_entries[e820::MAX_E820_ENTRIES]; -int16_t e820::bios_e820_entry_count = 0; +//e820::bios_e820_entry e820::bios_e820_entries[e820::MAX_E820_ENTRIES]; +//int16_t e820::bios_e820_entry_count = 0; namespace { @@ -66,7 +65,8 @@ void reset_segments(){ } int detect_memory_e820(){ - auto smap = &e820::bios_e820_entries[0]; + auto smap = reinterpret_cast(0x5008); + //auto smap = &e820::bios_e820_entries[0]; uint16_t entries = 0; @@ -99,7 +99,10 @@ int detect_memory_e820(){ void detect_memory(){ //TODO If e820 fails, try other solutions to get memory map - e820::bios_e820_entry_count = detect_memory_e820(); + auto t = detect_memory_e820(); + //asm volatile("xchg bx, bx"); + *reinterpret_cast(0x5000) = t; + //asm volatile("xchg bx, bx"); } void disable_interrupts(){ diff --git a/kernel/src/e820.cpp b/kernel/src/e820.cpp index b239be2b..f8722b3a 100644 --- a/kernel/src/e820.cpp +++ b/kernel/src/e820.cpp @@ -15,9 +15,11 @@ size_t _available_memory; } //end of namespace anonymous void e820::finalize_memory_detection(){ - if(bios_e820_entry_count > 0){ - for(int64_t i = 0; i < bios_e820_entry_count; ++i){ - auto& bios_entry = bios_e820_entries[i]; + auto t = *reinterpret_cast(0x5000); + auto smap = reinterpret_cast(0x5008); + if(t > 0){ + for(int64_t i = 0; i < t; ++i){ + auto& bios_entry = smap[i]; auto& os_entry = e820_mmap[i]; uint64_t base = bios_entry.base_low + (static_cast(bios_entry.base_high) << 32); @@ -39,11 +41,14 @@ void e820::finalize_memory_detection(){ } uint64_t e820::mmap_entry_count(){ - return bios_e820_entry_count; + auto t = *reinterpret_cast(0x5000); + return t; + //return bios_e820_entry_count; } bool e820::mmap_failed(){ - return bios_e820_entry_count <= 0; + auto t = *reinterpret_cast(0x5000); + return t <= 0; } const e820::mmapentry& e820::mmap_entry(uint64_t i){ diff --git a/kernel/src/memory.cpp b/kernel/src/memory.cpp index 5dd7f610..9397ae53 100644 --- a/kernel/src/memory.cpp +++ b/kernel/src/memory.cpp @@ -120,10 +120,16 @@ uint64_t* allocate_block(uint64_t blocks){ } } + asm volatile("xchg bx, bx"); + + if(!current_mmap_entry){ return nullptr; } + + + auto block = reinterpret_cast(current_mmap_entry_position); paging::identity_map(block, blocks); @@ -206,16 +212,22 @@ void init_head(){ } void expand_heap(malloc_header_chunk* current){ + asm volatile("xchg bx, bx"); + //Allocate a new block of memory uint64_t* block = allocate_block(MIN_BLOCKS); //Transform it into a malloc chunk auto header = reinterpret_cast(block); + asm volatile("xchg bx, bx"); + //Update the sizes header->size() = MIN_BLOCKS * BLOCK_SIZE - META_SIZE; header->footer()->size() = header->size(); + asm volatile("xchg bx, bx"); + //Insert the new block into the free list insert_after(current, header); } diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index dcb71742..faa4b8df 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -103,7 +103,7 @@ command_definition commands[26] = { std::string current_input(16); -void exec_command(); +void exec_shell_command(); template void history_key(char key){ @@ -166,7 +166,7 @@ void start_shell(){ k_print_line(); if(current_input.size() > 0){ - exec_command(); + exec_shell_command(); if(get_column() != 0){ k_print_line(); @@ -202,7 +202,7 @@ void start_shell(){ } } -void exec_command(){ +void exec_shell_command(){ history_save(); auto params = std::split(current_input);;