Browse Source

fixed bug on real hardware

master
Mathieu Serandour 1 year ago
parent
commit
94891b5a06
  1. 36
      kernel/drivers/terminal/terminal.c
  2. 14
      kernel/entry.c
  3. 3
      kernel/memory/heap.c

36
kernel/drivers/terminal/terminal.c

@ -35,7 +35,7 @@ static terminal_handler_t terminal_handler = NULL;
static bool need_refresh = false;
void empty_terminal_handler(const char* s, size_t l) {
static void empty_terminal_handler(const char* s, size_t l) {
(void) (s + l);
// empty handler by default,
// make sure not to execute the address 0 :)
@ -73,7 +73,7 @@ static unsigned timerID = INVALID_TIMER_ID;
//static char* stream_buffer = NULL;
static char* stream_buffer = NULL;
//static unsigned stream_buffer_size = 0;
//static volatile unsigned stream_buffer_content_size = 0;
@ -102,10 +102,12 @@ void terminal_remove(void) {
}
void terminal_install_early(void) {
log_debug("install the terminal...");
set_terminal_handler(empty_terminal_handler);
assert(charmap == NULL);
assert(char_buffer == NULL);
// log_debug("install the terminal...");
//
// assert(charmap == NULL);
// assert(char_buffer == NULL);
@ -125,8 +127,6 @@ void terminal_install_early(void) {
nlines = TERMINAL_N_PAGES * term_nlines;
// allocate the terminal buffer
char_buffer = malloc(ncols * nlines * sizeof(struct Char));
// calculate the margins
#ifdef BIGGER_FONT
@ -137,9 +137,12 @@ void terminal_install_early(void) {
margin_top = (screenImage->h - term_nlines * TERMINAL_FONTHEIGHT) / 2;
#endif
// stream_buffer = NULL;//malloc(ncols * term_nlines);
set_terminal_handler(empty_terminal_handler);
// allocate the terminal buffer
char_buffer = malloc(ncols * nlines * sizeof(struct Char) * 10);
stream_buffer = malloc(ncols * term_nlines);
}
// finish intallation when memory
@ -147,6 +150,8 @@ void terminal_install_early(void) {
void terminal_install_late(void) {
//timerID = apic_create_timer(terminal_update, UPDATE_PERIOD_MS);
charmap = loadBMP_24b_1b(&_binary_charmap_bmp);
@ -210,7 +215,7 @@ static void next_line(void) {
cur_line = nlines-4;
move_buffer(4);
}
}
else if(cur_line >= first_line + term_nlines) {
first_line++;
need_refresh = true;
@ -228,19 +233,18 @@ static struct Char make_Char(char c) {
static void emplace_normal_char(char c) {
if(cur_col >= ncols) {
next_line();
}
char_buffer[ncols * cur_line + cur_col] = make_Char(c);
struct Char* ch = &char_buffer[ncols * cur_line + cur_col];
cur_col += 1;
if(cur_col >= ncols)
next_line();
if(!need_refresh)
print_char(ch, cur_line - first_line, cur_col);
cur_col += 1;
}

14
kernel/entry.c

@ -133,8 +133,6 @@ static void init_memory(const struct stivale2_struct_tag_memmap* memmap_tag,
// map lapic & hpet registers
map_acpi_mmios();
// init kernel heap
heap_init();
}
@ -184,11 +182,21 @@ void _start(struct stivale2_struct *stivale2_struct) {
// after loading our gdt
// so we need to load our gdt after our
// terminal is successfully installed
append_paging_initialization();
void empty_terminal_handler(const char* s, size_t l) {
(void) (s + l);
// empty handler by default,
// make sure not to execute the address 0 :)
}
set_terminal_handler(empty_terminal_handler);
// init kernel heap
heap_init();
terminal_install_early();
terminal_set_colors(0xfff0a0, 0x212121);
append_paging_initialization();
terminal_install_late();

3
kernel/memory/heap.c

@ -260,6 +260,9 @@ void heap_init(void) {
void* __attribute__((noinline)) malloc(size_t size) {
// align the size to assure that
// the whole structure is alligned
printf("malloc(%x)", size);
size = ((size + 7 ) / 8) * 8;
if(size < MIN_SEGMENT_SIZE)
size = MIN_SEGMENT_SIZE;

Loading…
Cancel
Save