multiboot
E. Almqvist 3 years ago
parent 7427e69fb5
commit a67b6ad5cd
  1. 6
      drivers/vga.c
  2. 43
      kernel/kernel.c
  3. 10
      kernel/memory.c

@ -10,9 +10,6 @@ static uint cursor_row = 0;
static uint cursor_col = 0; static uint cursor_col = 0;
void vga_init() { void vga_init() {
// Allocate VGA memory range
pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range
// Disable cursor // Disable cursor
port_outb(0x3d4, 0x0a); port_outb(0x3d4, 0x0a);
port_outb(0x3d5, 0x20); port_outb(0x3d5, 0x20);
@ -68,11 +65,14 @@ void clear_screen() {
void print(char* str, int attribute_byte) { void print(char* str, int attribute_byte) {
for( char* c = str; *c != '\0'; c++ ) for( char* c = str; *c != '\0'; c++ )
writechar(*c, (uint)(c - str) + cursor_col, cursor_row, attribute_byte); writechar(*c, (uint)(c - str) + cursor_col, cursor_row, attribute_byte);
cursor_col += strlen(str);
} }
void println(char* str, int attribute_byte) { void println(char* str, int attribute_byte) {
print(str, attribute_byte); print(str, attribute_byte);
cursor_row++; // Increment to next y-pos (newline) cursor_row++; // Increment to next y-pos (newline)
cursor_col = 0;
} }
void printint(int i, int attribute_byte) { void printint(int i, int attribute_byte) {

@ -11,38 +11,38 @@ void init() {
println("Kernel loaded", SUCCESS_COLOR); println("Kernel loaded", SUCCESS_COLOR);
// enable_paging(); // Allocate VGA memory range
println("Allocating VGA memory...", DEFAULT_COLOR);
println(""); pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range
char* title = "eOS Version 0.4 2022";
println(title, DEFAULT_COLOR);
char* subtitle = "A x86 operating system, licenced under GPL-2.0";
println(subtitle, DEFAULT_COLOR);
/* // TODO: MAKE THESE DYNAMIC
print("Kernel offset: ", DEFAULT_COLOR); print("Kernel offset: ", DEFAULT_COLOR);
println("0x1000", DEFAULT_COLOR); println("0x1000", DEFAULT_COLOR);
*/
char* malloctest = pm_malloc(1); // allocate two blocks println("-VGA Stats-", DEFAULT_COLOR);
print("Start: ", DEFAULT_COLOR);
println("0xb7000", DEFAULT_COLOR);
print("End: ", DEFAULT_COLOR);
println("0xb8fa0", DEFAULT_COLOR);
// ENABLE PAGING
// TODO: make this work
// enable_paging();
char* intbuf = "xxxx"; println("");
int num = 1234; char* title = "eOS Version 0.4 2022";
intbuf = int_to_str(num, intbuf); println(title, DEFAULT_COLOR);
print("TEST NUM: ", DEFAULT_COLOR);
println(intbuf, DEFAULT_COLOR);
/* char* subtitle = "A x86 operating system, licenced under GPL-2.0";
println(subtitle, DEFAULT_COLOR);
// Memory allocation testing // Memory allocation testing
printalign("-- PMM Tests --", DEFAULT_COLOR, MIDDLE); printalign("-- PMM malloc Tests --", DEFAULT_COLOR, MIDDLE);
println("THESE ALLOC SHOULD WORK:", 0xa0); println("THESE MALLOC SHOULD WORK (no text => success):", 0xa0);
for(int i=0; i < 4; i++) { for(int i=0; i < 4; i++) {
block_alloc(i); pm_malloc(1);
} }
println("(2) THIS ALLOC SHOULD FAIL:", 0xc0); println("(2) THIS ALLOC SHOULD FAIL:", 0xc0);
@ -52,11 +52,10 @@ void init() {
block_free(2); // after this, allocation of 2nd block should work block_free(2); // after this, allocation of 2nd block should work
block_alloc(2); block_alloc(2);
printalign("-- End of PMM Tests --", DEFAULT_COLOR, MIDDLE); printalign("-- End of PMM malloc Tests --", DEFAULT_COLOR, MIDDLE);
char* strbuf = "Concat test: "; char* strbuf = "Concat test: ";
char* str2 = "Works!"; char* str2 = "Works!";
strbuf = strcat(strbuf, str2); strbuf = strcat(strbuf, str2);
println(strbuf, DEFAULT_COLOR); println(strbuf, DEFAULT_COLOR);
*/
} }

@ -37,8 +37,6 @@ pointer block_alloc(uint blockidx) {
block_bflag = CHECK_BITMAP(bitmap, blockidx); block_bflag = CHECK_BITMAP(bitmap, blockidx);
if( block_bflag == BM_FREE ) { // check if block is free if( block_bflag == BM_FREE ) { // check if block is free
println("Allocating block...", DEFAULT_COLOR);
mod_bitmap(blockidx, 1); mod_bitmap(blockidx, 1);
last_block = blockidx; last_block = blockidx;
@ -107,11 +105,15 @@ void pm_malloc_range(ulong start, ulong end, bool force) {
} }
pointer pm_malloc(uint block_count) { pointer pm_malloc(uint block_count) {
// failsafe if the dev is a moron
if( block_count < 1 ) {
println("[ERROR] Attempted to allocated zero blocks!", URGENT_COLOR);
return 0x0;
}
// find free block range and get lower offset // find free block range and get lower offset
int lower; int lower;
lower = find_free(block_count); lower = find_free(block_count);
println("lower: ", DEFAULT_COLOR);
println((lower+46), 0xfc);
if( lower < 0 ) { if( lower < 0 ) {
println("malloc: OUT OF MEMORY :(", URGENT_COLOR); println("malloc: OUT OF MEMORY :(", URGENT_COLOR);

Loading…
Cancel
Save