Merge into main the new state of the operating system/kernel #1

Open
Nigel wants to merge 120 commits from dev into main
2 changed files with 4 additions and 102 deletions
Showing only changes of commit f71a3a8ed6 - Show all commits

View File

@ -1,102 +1,5 @@
#include "idt.h" #include "idt.h"
static void itoa (char *buf, int base, int d) {
char *p = buf;
char *p1, *p2;
unsigned long ud = d;
int divisor = 10;
if ( base == 'd' && d < 0){
*p++ = '-';
buf++;
ud = -d;
} else if (base == 'x'){
divisor = 16;
}
do {
int remainder = ud % divisor;
*p++ = (remainder < 10 ) ? remainder + '0' : remainder + 'a' -10;
} while(ud /= divisor);
/*terminate buf*/
*p =0;
p1 = buf;
p2 = p -1;
while (p1 < p2)
{
char tmp = *p1;
*p1 = *p2;
*p2 = tmp;
p1++;
p2--;
}
}
void printf ( const char *format, ...) {
AS_KERNEL();
char **arg = (char **)&format;
int c;
char buf[20];
arg++;
while ((c = *format++) != 0){
if( c != '%')
kterm_put(c);
else{
char *p, *p2;
int pad0 = 0, pad = 0;
c = *format++;
if(c =='0'){
pad0 = 1;
c = *format++;
}
if ( c >= '0' && c <= '9'){
pad = c - '0';
c = *format++;
}
switch (c)
{
case 'd':
case 'u':
case 'x':
itoa(buf, c, *((int *) arg++));
p = buf;
goto string;
break;
case 's':
p = *arg++;
if(!p)
p = "(null)";
string:
for (p2 = p; *p2; p2++);
for (; p2 < p + pad; p2++)
kterm_put(pad0 ? '0': ' ');
while (*p)
kterm_put(*p++);
break;
default:
kterm_put(*((int *)arg++));
break;
}
}
}
}
IDT_entry idt_table[256]; IDT_entry idt_table[256];
IDT_ptr idt_ptr; IDT_ptr idt_ptr;

View File

@ -3,14 +3,13 @@
#include "stdint.h" #include "stdint.h"
#include "stddef.h" #include "stddef.h"
#include "../vga/colors.h" #include "../vga/colors.h"
#include "../pic/pic.h"; #include "../pic/pic.h"
extern "C"{
#include "../tty/kterm.h"
}
#define AS_KERNEL() ( kterm_writestring("[KERNEL]:")) #define AS_KERNEL() ( kterm_writestring("[KERNEL]:"))
extern "C" void kterm_writestring(const char* data );
extern "C" void kterm_putat(char, uint8_t, size_t, size_t);
extern "C" void kterm_put(char);
extern "C" { extern "C" {
struct __attribute__((__packed__)) IDT_entry { struct __attribute__((__packed__)) IDT_entry {