multiboot
E. Almqvist 3 years ago
parent 15a9a8fb05
commit 909bb33666
  1. 2
      kernel/kernel.c
  2. 14
      kernel/memory.c
  3. 5
      lib/conv.c
  4. 2
      lib/types.h

@ -25,7 +25,7 @@ void init() {
println("0x1000", DEFAULT_COLOR);
*/
char* malloctest = pm_malloc(2); // allocate two blocks
char* malloctest = pm_malloc(1); // allocate two blocks

@ -1,5 +1,6 @@
#include "memory.h"
#include "../drivers/vga.h"
#include "../lib/conv.h"
// https://wiki.osdev.org/Page_Frame_Allocation
// page = block
@ -60,10 +61,11 @@ bool check_block_range(uint start, uint end) {
uint idx;
for(idx = start; idx <= end; idx++) {
if( CHECK_BITMAP(bitmap, idx) != BM_FREE )
if( CHECK_BITMAP(bitmap, idx) != BM_FREE ) {
allowed = false;
break;
}
}
return allowed;
}
@ -74,12 +76,13 @@ int find_free(uint block_count) {
// Loop through bitmap starting at last_block
for( uint lower = last_block; lower < MAX_BLOCK_COUNT - block_count; lower++ ) {
bool range_is_free = check_block_range(lower, lower + block_count - 1);
bool range_is_free = check_block_range(lower, lower + block_count);
if(range_is_free) // if range is free
if(range_is_free) { // if range is free
lowerb = (int)lower;
break; // then stop searching
}
}
return lowerb; // return the lower block index
}
@ -111,11 +114,14 @@ pointer pm_malloc(uint block_count) {
// find free block range and get lower offset
int lower;
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);
// do some out-of-memory interupt
return 0x0;
}
// allocate those blocks
uint i;

@ -8,10 +8,11 @@ char* int_to_str(int i, char* buf) {
*(buf+len) = '\0'; // add a "end-of-string" at the end
int j;
for(j = 0; j < len; j++) // iterate over each digit and assign it to the buffer
for(j = 0; j < len; j++) { // iterate over each digit and assign it to the buffer
// super dangerous memory write
println("char!", DEFAULT_COLOR);
*(buf+j) = (char)(ndigit(num, len-1-j) + ASCII_OFFSET); // apply the ascii offset so that i becomes a char
println(*(buf+j), 0xc0);
}
return buf;
}

@ -1,6 +1,6 @@
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long* pointer;
typedef char* pointer;
typedef int bool;
#define true 1
#define false 0

Loading…
Cancel
Save