Add support for limine RSDP request
This commit is contained in:
parent
4410dde3f2
commit
0cc86fc37d
8 changed files with 83 additions and 0 deletions
83
lib/printf.c
Normal file
83
lib/printf.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <dev/serial.h>
|
||||
|
||||
static inline void printf_out(char c)
|
||||
{
|
||||
serial_write(c);
|
||||
}
|
||||
|
||||
static int printf_write(const char *restrict s)
|
||||
{
|
||||
char c;
|
||||
int ret = 0;
|
||||
while ((c = *s++)) {
|
||||
printf_out(c);
|
||||
ret++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int printf(const char *restrict fmt, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
char c;
|
||||
char *s;
|
||||
int i;
|
||||
|
||||
int n;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
const char *convert = "0123456789ABCDEF";
|
||||
|
||||
while ((c = *fmt++)) {
|
||||
if (c == '%') {
|
||||
c = *fmt++;
|
||||
switch (c) {
|
||||
case '\0':
|
||||
printf_out('%');
|
||||
ret++;
|
||||
goto out;
|
||||
case 'd':
|
||||
i = va_arg(args, int);
|
||||
|
||||
if (i < 0) {
|
||||
printf_out('-');
|
||||
ret++;
|
||||
i = -i;
|
||||
}
|
||||
|
||||
char buf[11];
|
||||
n = 0;
|
||||
|
||||
do {
|
||||
buf[n] = convert[i % 10];
|
||||
n++;
|
||||
} while ((i /= 10));
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
printf_out(buf[(n - 1) - j]);
|
||||
ret++;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
s = va_arg(args, char *);
|
||||
ret += printf_write(s);
|
||||
break;
|
||||
case 'c':
|
||||
i = va_arg(args, int);
|
||||
ret++;
|
||||
printf_out(i);
|
||||
}
|
||||
} else {
|
||||
printf_out(c);
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
out:
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
Loading…
Reference in a new issue