rust
E. Almqvist 3 years ago
parent 128ead244a
commit 152bb910f3
  1. 3
      kernel/kernel.c
  2. 50
      lib/conv.c
  3. 4
      lib/conv.h
  4. 3
      lib/math.c
  5. 2
      lib/math.h

@ -27,10 +27,9 @@ void kernel_init() {
// TODO: make this work
// enable_paging();
set_cursor_pos(0, 8);
print("E820 loaded entries: ", DEFAULT_COLOR);
uint entries = get_phys_mem_size();
char* buf;
buf = int_to_str(entries, buf);
buf = itoa(entries, buf, 10);
println(buf, DEFAULT_COLOR);
}

@ -1,23 +1,37 @@
#include "conv.h"
#include "../drivers/vga.h"
// char* int_to_str(int i, char* buf) {
// ulong num = (ulong)i; // convert to ulong
// uint len = ulong_len(num); // number of digits
//
// *(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
// // super dangerous memory write
// *(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;
// }
char* itoa( int value, char * str, int base ) {
char* rc;
char* ptr;
char* low;
char* int_to_str(int i, char* buf) {
char* sign = (i < 0) ? "-" : "+";
return (char*) sign;
// Check for supported base.
if ( base < 2 || base > 36 ) {
*str = '\0';
return str;
}
rc = ptr = str;
if ( value < 0 && base == 10 ) // sign
*ptr++ = '-';
// Remember where the numbers start.
low = ptr;
// The actual conversion.
do {
// Modulo is negative for negative value. This trick makes abs() unnecessary.
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + value % base];
value /= base;
} while ( value );
// Terminating the string.
*ptr-- = '\0';
// Invert the numbers.
while ( low < ptr ) {
char tmp = *low;
*low++ = *ptr;
*ptr-- = tmp;
}
return rc;
}

@ -1,6 +1,4 @@
#include "types.h"
#include "util.h"
#define ASCII_OFFSET 0x30
char* int_to_str(int i, char* buf);
char* itoa(int, char*, int);

@ -17,6 +17,3 @@ long square(uint num) {
}
return sum + 1;
}
float powf(float n) {}

@ -2,5 +2,3 @@
long pow(int, uint);
long square(uint);
float powf(float);

Loading…
Cancel
Save