kernel: use mpaland printf

This commit is contained in:
Matheus
2023-04-08 13:59:37 -03:00
parent ec9e498814
commit d8141261cb
8 changed files with 48 additions and 7 deletions
+2
View File
@@ -9,3 +9,5 @@ pkgs
sources
astral.iso
kernel-src/include/limine.h
kernel-src/include/printf.h
kernel-src/io/printf.c
+1 -1
View File
@@ -27,7 +27,7 @@ kernel:
./jinx build astral
clean-kernel:
find kernel-src -name *.o -delete
find builds/astral/ -name *.o -delete
clean:
make clean-kernel
+3 -1
View File
@@ -5,7 +5,9 @@ TARGET=x86-64
INCDIR=$(shell pwd)/include
ARCHDIR=$(shell pwd)/arch/$(TARGET)/
LDFLAGS=-ffreestanding -nostdlib -lgcc -Wl,-T,"$(ARCHDIR)/kernel.ld" -debug
CFLAGS=-ffreestanding -mcmodel=kernel -O2 -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -nostdlib -I "${INCDIR}"
# required for mpaland printf so it doesn't compile with floating point support, which results in build failures
PRINTFOPTS=-DPRINTF_DISABLE_SUPPORT_FLOAT
CFLAGS=-ffreestanding -mcmodel=kernel -O2 -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -nostdlib -Wall -I "${INCDIR}" $(PRINTFOPTS)
ASFLAGS=-felf64
astral: $(OBJS)
-2
View File
@@ -1,5 +1,3 @@
#include <arch/io.h>
// TODO compile time options for disabling output to port e9h
+3 -3
View File
@@ -1,7 +1,7 @@
#include <arch/e9.h>
#include <logging.h>
void kernel_entry() {
arch_e9_puts("Hello, world!\n");
asm("cli");
asm("hlt");
logging_sethook(arch_e9_putc);
__assert(!"kernel entry end");
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef _LOGGING_H
#define _LOGGING_H
#include <printf.h>
void _putchar(char c);
void logging_sethook(void (*fun)(char));
// TODO panic
#define __assert(x) \
if (!(x)){ \
printf("%s:%s:%d: %s failed\n", __FILE__, __func__, __LINE__, #x); \
for(;;); \
};
#endif
+14
View File
@@ -0,0 +1,14 @@
static void nohook(char c) {
}
static void (*hook)(char) = nohook;
// hook used by mpaland printf
void _putchar(char c) {
hook(c);
}
void logging_sethook(void (*fun)(char)) {
hook = fun;
}
+7
View File
@@ -2,7 +2,14 @@ name=astral
version=0
source_dir="kernel-src"
allow_network="yes"
imagedeps="wget"
regenerate() {
curl https://raw.githubusercontent.com/limine-bootloader/limine/trunk/limine.h > include/limine.h
pushd /tmp/
wget https://github.com/mpaland/printf/archive/refs/tags/v4.0.0.tar.gz
tar -xf v4.0.0.tar.gz
popd
cp /tmp/printf-4.0.0/printf.c io/printf.c
cp /tmp/printf-4.0.0/printf.h include/printf.h
}