Skip to content

Commit

Permalink
Update tests and fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Aug 21, 2024
1 parent ba160b3 commit 50da1e8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 99 deletions.
10 changes: 6 additions & 4 deletions docs/kernel/Initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ The sequence of component that are intialized (refer to `src/main.c`):
* Load the PSF font from memory
* Basic System Initialization:
- Parse the multiboot information received from the bootloader.
- Parse the mmap and initialize
- Initia physical memory manager, marking the pmm areas as busy and setup the hhdm.
- Initialize the physical memory manager, marking the area in the mmap as already taken.
- Parse the mmap and compute physical memory available.
- Initialize physical memory manager in the following order:
* Prepare the higher half direct map, it will avail of anonymous memory not used after the end of the kernel.
* Initialize the physical memory bitmap
* Parse and mark as busy the memory map.
- Validate and parse the SDT tables
* Finish mapping the Framebuffer (there is a potential bug here, need to chek what i do while mapping it)
* Finish mapping the Framebuffer
* Initialize the kernel VMM
* Initialize the kernel heap
* Initialize the apic
Expand Down
6 changes: 5 additions & 1 deletion src/include/kernel/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ typedef struct framebuffer_info {
extern _fb_window_t framebuffer_main_window;
extern _fb_window_t framebuffer_logo_area;

extern size_t cur_fb_line;
extern framebuffer_info framebuffer_data;
extern uint32_t number_of_lines;
extern _fb_window_t *logo_area_ptr;

void _fb_putchar(char symbol, size_t cx, size_t cy, uint32_t fg, uint32_t bg);
void _fb_printStrAt(const char *string, size_t cx, size_t cy, uint32_t fg, uint32_t bg);
void _fb_printStr(const char *string, uint32_t fg, uint32_t bg);
Expand All @@ -46,5 +51,4 @@ void draw_logo(uint32_t start_x, uint32_t start_y);
void _fb_scrollLine(_fb_window_t *scrolling_window, uint32_t line_height, uint32_t number_of_lines_to_scroll, _fb_window_t *area_to_pin);
void _fb_scroll(_fb_window_t *scrolling_window, uint32_t line_height, uint32_t number_of_lines_to_scroll, _fb_window_t *area_to_pin, bool clear_last_line);

void map_framebuffer_2(framebuffer_info fbdata);
#endif
14 changes: 5 additions & 9 deletions src/kernel/arch/x86_64/framebuffer/framebuffer.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <framebuffer.h>
#include <stacktrace.h>
#include <bitmap.h>
#include <hh_direct_map.h>
#include <framebuffer.h>
Expand All @@ -17,14 +19,7 @@ extern uint64_t pt_tables[];
#endif

/*struct framebuffer_info framebuffer_data;*/
void map_framebuffer_2(framebuffer_info fbdata) {
}

/*void map_framebuffer_2(struct framebuffer_info fbdata) {
uint32_t fb_entries = fbdata.memory_size / PAGE_SIZE_IN_BYTES;
pretty_logf(Verbose, "Fbdata size: 0x%x", fbdata.memory_size);
}*/
/*
void map_framebuffer(framebuffer_info fbdata) {
uint32_t fb_entries = fbdata.memory_size / PAGE_SIZE_IN_BYTES;
pretty_logf(Verbose, "Fbdata size: 0x%x", fbdata.memory_size);

Expand Down Expand Up @@ -82,6 +77,7 @@ void map_framebuffer_2(framebuffer_info fbdata) {
#endif
}


void set_fb_data(struct multiboot_tag_framebuffer *fbtag){
//FRAMEBUFFER_MEM = (void*)(uint64_t)fbtag->common.framebuffer_addr;
#if USE_FRAMEBUFFER == 1
Expand All @@ -106,4 +102,4 @@ void set_fb_data(struct multiboot_tag_framebuffer *fbtag){

#endif
}
*/

84 changes: 0 additions & 84 deletions src/kernel/framebuffer/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,90 +37,6 @@ _fb_window_t framebuffer_main_window;
_fb_window_t framebuffer_logo_area;
_fb_window_t *logo_area_ptr;

void map_framebuffer(framebuffer_info fbdata) {
uint32_t fb_entries = fbdata.memory_size / PAGE_SIZE_IN_BYTES;
pretty_logf(Verbose, "Fbdata size: 0x%x", fbdata.memory_size);

uint64_t phys_address = (uint64_t) fbdata.phys_address;

uint32_t pd = PD_ENTRY(_FRAMEBUFFER_MEM_START);
uint32_t pdpr = PDPR_ENTRY(_FRAMEBUFFER_MEM_START);
uint32_t pml4 = PML4_ENTRY(_FRAMEBUFFER_MEM_START);
#if SMALL_PAGES == 1
uint32_t fb_pd_entries = fb_entries / VM_PAGES_PER_TABLE;
//uint32_t pt = PT_ENTRY(_FRAMEBUFFER_MEM_START);
#endif

if(p4_table[pml4] == 0x00l || p3_table_hh[pdpr] == 0x00l){
pretty_log(Verbose, "PANIC - PML4 or PDPR Empty - not supported for now\n");
asm("hlt");
}

#if SMALL_PAGES == 1
uint64_t *current_page_table = pt_tables;
for(uint32_t i = 0; i <= fb_pd_entries; i++){
bool newly_allocated = false;
// Probably should be safer to rely on the direct map if possible?
if(p2_table[pd] == 0x00){
uint64_t *new_table = pmm_prepare_new_pagetable();
p2_table[pd] = (uint64_t)new_table | (PRESENT_BIT | WRITE_BIT);
uint64_t *new_table_hhdm = hhdm_get_variable((uintptr_t)new_table);
current_page_table = new_table_hhdm;
clean_new_table((uint64_t *)new_table_hhdm);
newly_allocated = true;
}
for(int j=0; j < VM_PAGES_PER_TABLE && fb_entries > 0; j++){
if(newly_allocated == false){
} else {
current_page_table[j] = phys_address + (((VM_PAGES_PER_TABLE * i) + j) * PAGE_SIZE_IN_BYTES) | PAGE_ENTRY_FLAGS;
}
fb_entries--;
}
newly_allocated = false;
pd++;
}
#elif SMALL_PAGES == 0
uint32_t fb_entries_mod = fbdata.memory_size % PAGE_SIZE_IN_BYTES;
if(fb_entries_mod != 0){
fb_entries++;
}
for(int j=0; fb_entries > 0; j++){
fb_entries--;
if( (p2_table[pd+j] < phys_address
|| p2_table[pd+j] > (phys_address + fbdata.memory_size) )
|| p2_table[pd+j] == 0x00l ) {
p2_table[pd+j] = (phys_address + (j * PAGE_SIZE_IN_BYTES)) | PAGE_ENTRY_FLAGS;
}
}
#endif
}


void set_fb_data(struct multiboot_tag_framebuffer *fbtag){
//FRAMEBUFFER_MEM = (void*)(uint64_t)fbtag->common.framebuffer_addr;
#if USE_FRAMEBUFFER == 1
framebuffer_data.address = (void*)(uint64_t)_FRAMEBUFFER_MEM_START;
//framebuffer_data.address = hhdm_get_variable((uintptr_t) (fbtag->common.framebuffer_addr));
framebuffer_data.pitch = fbtag->common.framebuffer_pitch;
framebuffer_data.bpp = fbtag->common.framebuffer_bpp;
framebuffer_data.memory_size = fbtag->common.framebuffer_pitch * fbtag->common.framebuffer_height;
framebuffer_data.width = fbtag->common.framebuffer_width;
framebuffer_data.height = fbtag->common.framebuffer_height;
framebuffer_data.phys_address = fbtag->common.framebuffer_addr;

number_of_lines = 0;

map_framebuffer(framebuffer_data);
cur_fb_line = 0;
framebuffer_main_window.x_orig = 0;
framebuffer_main_window.y_orig = 0;
framebuffer_main_window.width = framebuffer_data.width;
framebuffer_main_window.height = framebuffer_data.height;
logo_area_ptr = NULL;

#endif
}

void _fb_putchar(char symbol, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
uint8_t *framebuffer = (uint8_t *) framebuffer_data.address;
uint32_t pitch = framebuffer_data.pitch;
Expand Down
3 changes: 3 additions & 0 deletions tests/include/test_mem.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef _TEST_MEM_H
#define _TEST_MEM_H

extern uint64_t multiboot_tag_end;
extern uint64_t multiboot_tag_start;

void test_pmm_initialize();
void test_pmm();
void test_mmap();
Expand Down
5 changes: 4 additions & 1 deletion tests/test_mem.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <bitmap.h>
#include <kernel.h>
#include <mmap.h>
#include <kernel.h>
#include <test_mem.h>
#include <test_common.h>
#include <pmm.h>
Expand All @@ -22,11 +22,14 @@ extern multiboot_memory_map_t *mmap_entries;

struct multiboot_tag_basic_meminfo *tagmem;
struct multiboot_tag_mmap *mmap_root;

//unsigned long _kernel_physical_end __attribute__((section(".mySection"))) = 0x9ABCDEF0;
uint64_t _kernel_end = 0x1190AC;
uint64_t _kernel_physical_end = 0x1190AC;

int main() {
multiboot_tag_start = 0x1ca000;
multiboot_tag_start = 0x9bf;
test_pmm_initialize();
test_pmm();
test_mmap();
Expand Down

0 comments on commit 50da1e8

Please sign in to comment.