Refactor stuff

rust
E. Almqvist 3 years ago
parent a8231cfb34
commit efb0524e35
  1. 16
      bootloader/bios/memory.asm
  2. 52
      kernel/kernel.c
  3. 4
      kernel/memory.c
  4. 1
      kernel/memory.h
  5. 19
      lib/conv.c

@ -26,13 +26,13 @@ e820:
int 0x15 ; Do the interupt
; carry flag = (un)supported function
jc e820_fail ; TODO: Try probing instead
jc e820_fail_unsup ; TODO: Try probing instead
cmp eax, edx ; eax should be = 'SMAP'
jne e820_fail ; if not then fail
jne e820_fail_smap ; if not then fail
test ebx, ebx ; no entries
je e820_fail
je e820_fail_noent
e820_lp:
mov eax, 0xe820
@ -73,6 +73,16 @@ e820_write:
clc
ret
e820_fail_unsup:
mov [e820_stats_addr], byte -1
jmp e820_fail
e820_fail_smap:
mov [e820_stats_addr], byte -2
jmp e820_fail
e820_fail_noent:
mov [e820_stats_addr], byte -3
jmp e820_fail
e820_fail:
stc
ret

@ -1,6 +1,6 @@
#include "kernel.h"
void kernel_motd() {
void print_kernel_motd() {
printalign(" ___ ____ ", BANNER_COLOR, MIDDLE);
printalign(" ___ / _ \\/ ___| ", BANNER_COLOR, MIDDLE);
printalign(" / _ \\ | | \\___ \\ ", BANNER_COLOR, MIDDLE);
@ -8,15 +8,54 @@ void kernel_motd() {
printalign(" \\___|\\___/|____/ licenced under GPL-2.0", BANNER_COLOR, MIDDLE);
println("");
printalign("Fun fact: e = lim[h->0] (1+h)^(1/h)", DEFAULT_COLOR, MIDDLE);
printalign("Created by Elias Almqvist", DEFAULT_COLOR, MIDDLE);
println("");
}
void print_kernel_stats() {
char* buf;
// Memory stats
print("MEMORY BITMAP: ", 0x0f);
buf = itoa(get_bitmap(), buf, 2);
println(buf, DEFAULT_COLOR);
println("");
println("Memory", 0x0f);
print("Loaded Entries: ", DEFAULT_COLOR);
uint entries = get_phys_mem_size();
buf = itoa(entries, buf, 10);
println(buf, DEFAULT_COLOR);
print("Physical Memory Size: ");
println("?", DEFAULT_COLOR);
println("");
// VGA stats
println("Display (VGA)", 0x0f);
print("Memory Range: ", DEFAULT_COLOR);
buf = itoa(VGA_ADDRESS, buf, 16);
print(buf, DEFAULT_COLOR);
print(" - ");
buf = itoa(VGA_ADDRESS_MAX, buf, 16);
println(buf, DEFAULT_COLOR);
print("Screen Dimensions: ", DEFAULT_COLOR);
buf = itoa(MAX_COLS, buf, 10);
print(buf, DEFAULT_COLOR);
print("x");
buf = itoa(MAX_ROWS, buf, 10);
println(buf, DEFAULT_COLOR);
}
void kernel_init() {
// Display a nice MOTD
clear_screen();
kernel_motd();
print_kernel_motd();
vga_init(); // Initialize the screen first
// i.e. clear the screen et cetera.
@ -27,9 +66,6 @@ void kernel_init() {
// TODO: make this work
// enable_paging();
print("E820 loaded entries: ", DEFAULT_COLOR);
uint entries = get_phys_mem_size();
char* buf;
buf = itoa(entries, buf, 10);
println(buf, DEFAULT_COLOR);
print_kernel_stats();
}

@ -29,6 +29,10 @@ uint get_phys_mem_size() {
return entry_count;
}
int get_bitmap() {
return bitmap;
}
void mod_bitmap(uint bit, uint bflag) {
// create a bitmask that will be applied to the bitmap
int bitmask = 1 << bit;

@ -13,6 +13,7 @@
// void init_pmm(uint map_addr, uint bsize); // Initialize physical memory manager
int get_bitmap();
void mod_bitmap(uint bit, uint flag);
pointer block_alloc(uint blockidx); // allocate a block

@ -7,14 +7,23 @@ char* itoa( int value, char * str, int base ) {
char* low;
// Check for supported base.
if ( base < 2 || base > 36 ) {
if( base < 2 || base > 36 ) {
*str = '\0';
return str;
}
rc = ptr = str;
if ( value < 0 && base == 10 ) // sign
*ptr++ = '-';
switch(base) {
case 16:
*ptr++ = '0';
*ptr++ = 'x';
case 10:
if(value < 0)
*ptr++ = '-';
}
// if(value < 0 && base == 10 ) // sign
// *ptr++ = '-';
// Remember where the numbers start.
low = ptr;
@ -24,9 +33,11 @@ char* itoa( int value, char * str, int base ) {
// Modulo is negative for negative value. This trick makes abs() unnecessary.
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + value % base];
value /= base;
} while ( value );
} while(value);
// Terminating the string.
*ptr-- = '\0';
// Invert the numbers.
while ( low < ptr ) {
char tmp = *low;

Loading…
Cancel
Save