Minor refactor

pull/38/head
E. Almqvist 3 years ago
parent 45ff8a854f
commit fd7e32e141
  1. 5
      drivers/vga.c
  2. 3
      drivers/vga.h
  3. 11
      kernel/kernel.c
  4. 2
      kernel/memory.c
  5. 5
      lib/conv.c
  6. 2
      lib/conv.h
  7. 2
      lib/math.c
  8. 1
      lib/util.c

@ -10,6 +10,9 @@ 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_alloc_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);
@ -19,8 +22,6 @@ void vga_init() {
clear_screen(); clear_screen();
set_cursor_pos(0, 0); set_cursor_pos(0, 0);
pm_alloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range
} }
/* /*

@ -2,6 +2,9 @@
#define VGA_ADDRESS_MAX 0xb8fa0 #define VGA_ADDRESS_MAX 0xb8fa0
#define DEFAULT_COLOR 0x07 #define DEFAULT_COLOR 0x07
#define URGET_COLOR 0x0c
#define SUCCESS_COLOR 0x0a
#define MAX_ROWS 25 #define MAX_ROWS 25
#define MAX_COLS 80 #define MAX_COLS 80

@ -9,7 +9,7 @@ void init() {
vga_init(); // Initialize the screen first vga_init(); // Initialize the screen first
// i.e. clear the screen et cetera. // i.e. clear the screen et cetera.
println("Kernel loaded", DEFAULT_COLOR); println("Kernel loaded", SUCCESS_COLOR);
// enable_paging(); // enable_paging();
@ -26,6 +26,14 @@ void init() {
*/ */
char* intbuf = "xxxx";
int num = 1234;
intbuf = int_to_str(num, intbuf);
print("TEST NUM: ", DEFAULT_COLOR);
println(intbuf, DEFAULT_COLOR);
/*
// Memory allocation testing // Memory allocation testing
printalign("-- PMM Tests --", DEFAULT_COLOR, MIDDLE); printalign("-- PMM Tests --", DEFAULT_COLOR, MIDDLE);
@ -47,4 +55,5 @@ void init() {
char* str2 = "Works!"; char* str2 = "Works!";
strbuf = strcat(strbuf, str2); strbuf = strcat(strbuf, str2);
println(strbuf, DEFAULT_COLOR); println(strbuf, DEFAULT_COLOR);
*/
} }

@ -36,7 +36,7 @@ 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("Alloc!", DEFAULT_COLOR); println("Allocating block...", DEFAULT_COLOR);
mod_bitmap(blockidx, 1); mod_bitmap(blockidx, 1);
last_block = blockidx; last_block = blockidx;

@ -1,6 +1,7 @@
#include "conv.h" #include "conv.h"
#include "../drivers/vga.h"
void int_to_str(int i, char* buf) { char* int_to_str(int i, char* buf) {
ulong num = (ulong)i; // convert to ulong ulong num = (ulong)i; // convert to ulong
uint len = ulong_len(num); // number of digits uint len = ulong_len(num); // number of digits
@ -9,6 +10,8 @@ void int_to_str(int i, char* buf) {
int j; 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 // 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 *(buf+j) = (char)(ndigit(num, len-1-j) + ASCII_OFFSET); // apply the ascii offset so that i becomes a char
return buf;
} }

@ -3,4 +3,4 @@
#define ASCII_OFFSET 0x30 #define ASCII_OFFSET 0x30
void int_to_str(int i, char* buf); char* int_to_str(int i, char* buf);

@ -4,7 +4,7 @@ long pow(int num, uint expon) {
long prod = 1; long prod = 1;
while(expon > 0) while(expon > 0)
prod *= num; prod *= num;
--expon; expon--;
return prod; return prod;
} }

@ -1,4 +1,5 @@
#include "util.h" #include "util.h"
#include "math.h"
uint ulong_len(ulong n) { // get the digit length of a number uint ulong_len(ulong n) { // get the digit length of a number
int len = 0; int len = 0;

Loading…
Cancel
Save