This commit is contained in:
Baptiste Wicht 2014-01-07 22:47:00 +01:00
parent e319431a20
commit d25e567201
6 changed files with 57 additions and 20 deletions

View File

@ -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

View File

@ -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;

View File

@ -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<e820::bios_e820_entry*>(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<int16_t*>(0x5000) = t;
//asm volatile("xchg bx, bx");
}
void disable_interrupts(){

View File

@ -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<int16_t*>(0x5000);
auto smap = reinterpret_cast<e820::bios_e820_entry*>(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<uint64_t>(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<int16_t*>(0x5000);
return t;
//return bios_e820_entry_count;
}
bool e820::mmap_failed(){
return bios_e820_entry_count <= 0;
auto t = *reinterpret_cast<int16_t*>(0x5000);
return t <= 0;
}
const e820::mmapentry& e820::mmap_entry(uint64_t i){

View File

@ -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<uint64_t*>(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<malloc_header_chunk*>(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);
}

View File

@ -103,7 +103,7 @@ command_definition commands[26] = {
std::string current_input(16);
void exec_command();
void exec_shell_command();
template<bool Enable = History>
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);;