summaryrefslogtreecommitdiff
path: root/kc/core
diff options
context:
space:
mode:
Diffstat (limited to 'kc/core')
-rw-r--r--kc/core/Makefile6
-rw-r--r--kc/core/arch_thread.c4
-rw-r--r--kc/core/cpu/cpu.c4
-rw-r--r--kc/core/cpu/exceptions.h4
-rw-r--r--kc/core/i8042.c18
-rw-r--r--kc/core/kc_main.c4
-rw-r--r--kc/core/memory.h2
-rw-r--r--kc/core/memory/memory.c24
-rw-r--r--kc/core/memory/page_early.c12
-rw-r--r--kc/core/panic.c6
-rw-r--r--kc/core/pic8259.c12
-rw-r--r--kc/core/pit8253.c6
-rw-r--r--kc/core/stdio.c (renamed from kc/core/kstdio.c)8
-rw-r--r--kc/core/task.c16
-rw-r--r--kc/core/video.c6
-rw-r--r--kc/core/vm_tree.c6
16 files changed, 70 insertions, 68 deletions
diff --git a/kc/core/Makefile b/kc/core/Makefile
index 56ddf55..9791762 100644
--- a/kc/core/Makefile
+++ b/kc/core/Makefile
@@ -1,12 +1,12 @@
include ../../defaults.mk
include ../defaults.mk
-VPATH := ../../lib ../ cpu/ memory/
+VPATH := ../../lib ../../lib/libc ../ cpu/ memory/
TARGET := kernel.os
.DEFAULT: $(TARGET)
-CPPFLAGS += -I../../api -I../api -I../../lib -I.
+CPPFLAGS += -I../../api -I../api -I../../lib/api -I.
CFLAGS += -mcmodel=small -Wno-unused-const-variable -Wno-unused-function -fvisibility=hidden -g
AOBJS := entry_x86_64.o reloc_x86_64.o dynamic_x86_64.o
@@ -14,7 +14,7 @@ COBJS := mmu.o cpu_thread.o irq.o exceptions.o cpu.o msr.o mmu.o port.o arch_thr
POBJS := pic8259.o pic8259_isr.o pit8253.o i8042.o
GOBJS := serial.o kc_main.o memory.o vm_tree.o panic.o task.o \
kcc_memory.o page_early.o page_stack.o video.o
-LOBJS := kprintf.o memset.o memcpy.o memmove.o memcmp.o kstdio.o string.o
+LOBJS := printf.o memset.o memcpy.o memmove.o memcmp.o stdio.o string.o
OBJS := $(AOBJS) $(COBJS) $(POBJS) $(GOBJS) $(LOBJS)
DEPS := $(patsubst %.o,%.d,$(OBJS))
diff --git a/kc/core/arch_thread.c b/kc/core/arch_thread.c
index 180923d..c0d707a 100644
--- a/kc/core/arch_thread.c
+++ b/kc/core/arch_thread.c
@@ -1,8 +1,10 @@
#include <stdint.h>
#include <stddef.h>
#include <stdnoreturn.h>
+
+#include <libc/stdio.h>
+
#include "task.h"
-#include <lib/kstdio.h>
struct arch_register_context
{
diff --git a/kc/core/cpu/cpu.c b/kc/core/cpu/cpu.c
index f61ed00..0eaccb7 100644
--- a/kc/core/cpu/cpu.c
+++ b/kc/core/cpu/cpu.c
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
#define GDT_ENTRIES 16
#define IDT_ENTRIES 256
@@ -53,7 +53,7 @@ uint64_t *get_tss_rsp0(void)
static void syscall_entry(void)
{
- kprintf("system call\n");
+ printf("system call\n");
halt();
}
diff --git a/kc/core/cpu/exceptions.h b/kc/core/cpu/exceptions.h
index 7babb65..14a2088 100644
--- a/kc/core/cpu/exceptions.h
+++ b/kc/core/cpu/exceptions.h
@@ -21,7 +21,7 @@
#ifndef __ASSEMBLER__
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
struct isr_context_param_regs
{
@@ -53,7 +53,7 @@ struct isr_context
static inline void print_exception_context(struct isr_context *context)
{
- kprintf(
+ printf(
"exception %#hhx:%x context:\n"
"interrupt entry state:\n"
"rip: %#hx:%p rflags: %#0.16lx\n"
diff --git a/kc/core/i8042.c b/kc/core/i8042.c
index 0ba12dc..f6b63b0 100644
--- a/kc/core/i8042.c
+++ b/kc/core/i8042.c
@@ -2,7 +2,7 @@
#include "port.h"
#include "i8042.h"
#include "pic8259.h"
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
static void i8042_init(void);
static void i8042_enable(void) {}
@@ -99,21 +99,21 @@ static void i8042_set_config(void)
i8042_command(0x20);
uint8_t config_byte;
i8042_read(&config_byte);
- kprintf("i8042: current config: %#0.2x\n", config_byte);
+ printf("i8042: current config: %#0.2x\n", config_byte);
config_byte &= 0xfc;
if (config_byte & (0x1 << 5))
{
maybe_dual_channel = true;
}
config_byte |= 0x01;
- kprintf("i8042: new config: %#0.2x\n", config_byte);
+ printf("i8042: new config: %#0.2x\n", config_byte);
i8042_command(0x60);
i8042_write(config_byte);
i8042_command(0xaa);
uint8_t bist_result;
if (i8042_read(&bist_result) && bist_result != 0x55)
{
- kprintf("i8042: warning: error self-testing device. aborting.\n");
+ printf("i8042: warning: error self-testing device. aborting.\n");
return;
}
@@ -124,11 +124,11 @@ static void i8042_set_config(void)
uint8_t config_byte;
if (i8042_read(&config_byte) && config_byte & (0x1 << 5))
{
- kprintf("i8042: single-channel controller detected\n");
+ printf("i8042: single-channel controller detected\n");
}
else
{
- kprintf("i8042: dual-channel controller detected\n");
+ printf("i8042: dual-channel controller detected\n");
is_dual_channel = true;
}
}
@@ -136,7 +136,7 @@ static void i8042_set_config(void)
outb(PS2_COMMAND, 0xab);
if (inb(PS2_DATA) != 0x00)
{
- kprintf("i8042: failed testing port a\n");
+ printf("i8042: failed testing port a\n");
}
else
{
@@ -147,7 +147,7 @@ static void i8042_set_config(void)
outb(PS2_COMMAND, 0xa9);
if (inb(PS2_DATA) != 0x00)
{
- kprintf("i8042: failed testing port b\n");
+ printf("i8042: failed testing port b\n");
}
else
{
@@ -162,7 +162,7 @@ static void i8042_set_config(void)
i8042_write(0xff);
if(inb(PS2_DATA) == 0xfa && inb(PS2_DATA) == 0xaa)
{
- kprintf("i8042: detected device on channel, type %#0.2x\n", inb(PS2_DATA));
+ printf("i8042: detected device on channel, type %#0.2x\n", inb(PS2_DATA));
}
}
diff --git a/kc/core/kc_main.c b/kc/core/kc_main.c
index 9a84727..4f70d00 100644
--- a/kc/core/kc_main.c
+++ b/kc/core/kc_main.c
@@ -10,7 +10,7 @@
#include "i8042.h"
#include <kernel/entry.h>
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
#include <stdbool.h>
#include <stddef.h>
@@ -27,7 +27,7 @@ unsigned long kc_main(struct kc_boot_data *data)
cpu_init();
serial_init();
video_init();
- kprintf("sophia starting, boot data %#lx\n", boot_data);
+ printf("sophia starting, boot data %#lx\n", boot_data);
memory_init();
pic8259_init();
pit8253_timer_source.init();
diff --git a/kc/core/memory.h b/kc/core/memory.h
index 6f70e57..425c2cd 100644
--- a/kc/core/memory.h
+++ b/kc/core/memory.h
@@ -4,7 +4,7 @@
#include <kernel/memory/paging.h>
#include <kernel/memory/range.h>
-#include <lib/kstring.h>
+#include <libc/string.h>
#include <core/memory.h>
diff --git a/kc/core/memory/memory.c b/kc/core/memory/memory.c
index 1c6fabb..82fba3f 100644
--- a/kc/core/memory/memory.c
+++ b/kc/core/memory/memory.c
@@ -20,7 +20,7 @@
#include <kc.h>
#include <core/memory.h>
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
#define align_next(x, a) (x + a - 1) & ~(a - 1)
@@ -89,7 +89,7 @@ struct vm_tree *vm_get_tree(void)
void page_init(void)
{
- kprintf("initializing page frame allocator\n");
+ printf("initializing page frame allocator\n");
page_early_init();
page_stack_init();
}
@@ -98,7 +98,7 @@ void page_init_final(void)
{
if (current_alloc_func == boot_page_alloc)
{
- kprintf("finishing page frame allocator initialization\n");
+ printf("finishing page frame allocator initialization\n");
page_early_final();
current_alloc_func = page_stack_alloc;
}
@@ -176,7 +176,7 @@ static void *map_tableset(void *vaddr, uint64_t *tables[TABLESET_COUNT])
}
else
{
- kprintf("error: failed allocating memory for page table\n");
+ printf("error: failed allocating memory for page table\n");
PANIC(OUT_OF_MEMORY);
}
}
@@ -380,7 +380,7 @@ static void temp_page_unmap(void *vaddr)
static void vm_init(void)
{
- kprintf("initializing vm state\n");
+ printf("initializing vm state\n");
struct kc_boot_data *boot_data = get_boot_data();
struct vm_core_static_state *states = &vm_state.statics[0];
@@ -433,7 +433,7 @@ static void vm_init(void)
vm_state.zero_page = page_alloc(PAGE_ALLOC_CONV);
if (!vm_state.zero_page)
{
- kprintf("failed allocating for zero page\n");
+ printf("failed allocating for zero page\n");
PANIC(GENERAL_PANIC);
}
@@ -441,7 +441,7 @@ static void vm_init(void)
if (!zero_temp)
{
- kprintf("failed mapping zero page for initialization\n");
+ printf("failed mapping zero page for initialization\n");
PANIC(GENERAL_PANIC);
}
@@ -492,7 +492,7 @@ void *heap_alloc(size_t size)
if ((void *)-1ULL == heap_root)
{
struct vm_tree_node *heap_node = &vm_state.statics[HEAP_VM_STATE].node;
- kprintf("initializing heap at %#lx of %zu bytes\n",
+ printf("initializing heap at %#lx of %zu bytes\n",
heap_node->key.address, heap_node->key.size);
heap_root = NULL;
header = (struct heap_header *)heap_node->key.address;
@@ -631,7 +631,7 @@ int anonymous_page_handler(
if (!paddr)
{
- kprintf("got zero from page_alloc :|\n");
+ printf("got zero from page_alloc :|\n");
PANIC(OUT_OF_MEMORY);
}
page_map_at(
@@ -657,14 +657,14 @@ void page_fault_handler(struct isr_context *context)
if (!node)
{
print_exception_context(context);
- kprintf("error: page fault in unmanaged address %#lx\n", address);
+ printf("error: page fault in unmanaged address %#lx\n", address);
PANIC(UNHANDLED_FAULT);
}
if (!node->object->handler)
{
print_exception_context(context);
- kprintf("error: vm object at %p has no fault handler\n");
+ printf("error: vm object at %p has no fault handler\n");
PANIC(UNHANDLED_FAULT);
}
@@ -674,7 +674,7 @@ void page_fault_handler(struct isr_context *context)
void general_protection_handler(struct isr_context *context)
{
//TODO: implement #gp handler
- kprintf("general protection violation\n");
+ printf("general protection violation\n");
print_exception_context(context);
PANIC(UNHANDLED_FAULT);
}
diff --git a/kc/core/memory/page_early.c b/kc/core/memory/page_early.c
index 9ac90d2..989f82a 100644
--- a/kc/core/memory/page_early.c
+++ b/kc/core/memory/page_early.c
@@ -1,7 +1,7 @@
#include "page_early.h"
#include "panic.h"
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
static struct page_early_state
{
@@ -13,20 +13,20 @@ early_state;
void page_early_init(void)
{
- kprintf("initializing early page frame allocator\n");
+ printf("initializing early page frame allocator\n");
struct kc_boot_data *boot_data = get_boot_data();
early_state.first = &boot_data->memory.entries[0];
early_state.last = &boot_data->memory.entries[boot_data->memory.count];
early_state.current = early_state.first;
- /*kprintf("memory ranges\n");
+ /*printf("memory ranges\n");
struct memory_range *current = early_state.first;
do
{
- kprintf("base %#0.16lx size %#0.16lx type %d\n", current->base, current->size, current->type);
+ printf("base %#0.16lx size %#0.16lx type %d\n", current->base, current->size, current->type);
current++;
}
while (current != early_state.last);
@@ -37,7 +37,7 @@ void page_early_final(void)
{
if (early_state.first)
{
- kprintf("finalizing early page allocator\n");
+ printf("finalizing early page allocator\n");
for (struct memory_range *current = early_state.first;
current < early_state.last;
current++)
@@ -101,7 +101,7 @@ kc_phys_addr page_early_alloc(enum page_alloc_flags type)
early_state.current++;
}
- kprintf("error: early allocator has run out of memory\n");
+ printf("error: early allocator has run out of memory\n");
PANIC(OUT_OF_MEMORY);
}
diff --git a/kc/core/panic.c b/kc/core/panic.c
index 7844487..02c58c7 100644
--- a/kc/core/panic.c
+++ b/kc/core/panic.c
@@ -1,6 +1,6 @@
#include "panic.h"
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
#include <stdbool.h>
@@ -13,12 +13,12 @@ static char const *reason_strings[] = {
noreturn void panic(const char *file, int line, enum panic_reason reason)
{
- // TODO: kprintf() and friends
+ // TODO: printf() and friends
if (reason > sizeof(reason_strings) / sizeof(*reason_strings))
{
reason = 0;
}
- kprintf(
+ printf(
"kernel panic:%s:%u %s\n",
file,
line,
diff --git a/kc/core/pic8259.c b/kc/core/pic8259.c
index 4ddd2e1..792d0bd 100644
--- a/kc/core/pic8259.c
+++ b/kc/core/pic8259.c
@@ -4,7 +4,7 @@
#include <stdbool.h>
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
#define ICW1_ICW4 0x1
#define ICW1_SINGLE 0x2
@@ -28,7 +28,7 @@ void pic8259_irq_install(uint8_t irq, pic8259_handler_func h)
{
if (irq_handlers[irq])
{
- kprintf("attempt to overwrite irq handler for %u\n", irq);
+ printf("attempt to overwrite irq handler for %u\n", irq);
return;
}
irq_handlers[irq] = h;
@@ -43,7 +43,7 @@ static void wait(void)
void pic8259_init(void)
{
- kprintf("initializing legacy pic\n");
+ printf("initializing legacy pic\n");
// basic init. not gonna fret with this too much
outb(PIC_PRI_CMD, ICW1_INIT|ICW1_ICW4);
wait();
@@ -171,7 +171,7 @@ void pic8259_irq_begin(uint8_t irq)
// check for spurious activations
if (irq_is_spurious(irq))
{
- kprintf("spurious activation of irq%hhu\n", irq);
+ printf("spurious activation of irq%hhu\n", irq);
return;
}
@@ -181,12 +181,12 @@ void pic8259_irq_begin(uint8_t irq)
if (result)
{
- kprintf("error handling irq%hhu: % d\n", irq, result);
+ printf("error handling irq%hhu: % d\n", irq, result);
}
}
else
{
- kprintf("unhandled irq%hhu\n", irq);
+ printf("unhandled irq%hhu\n", irq);
}
pic8259_irq_end(irq);
diff --git a/kc/core/pit8253.c b/kc/core/pit8253.c
index 360808f..31cf349 100644
--- a/kc/core/pit8253.c
+++ b/kc/core/pit8253.c
@@ -5,7 +5,7 @@
#include <stdatomic.h>
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
#define PIT8253_DATA0 0x40
#define PIT8253_CMD 0x43
@@ -82,9 +82,9 @@ void pit8253_set_frequency(uint32_t frequency)
if (d > UINT16_MAX)
{
- kprintf("warning: %uHz is too slow for 8253 pit\n", PIT_HZ/d);
+ printf("warning: %uHz is too slow for 8253 pit\n", PIT_HZ/d);
d = UINT16_MAX;
- kprintf("warning: set timer to minimum frequency\n");
+ printf("warning: set timer to minimum frequency\n");
}
set_divisor(d);
diff --git a/kc/core/kstdio.c b/kc/core/stdio.c
index 680eb07..66c539f 100644
--- a/kc/core/kstdio.c
+++ b/kc/core/stdio.c
@@ -4,12 +4,12 @@
#include <stdint.h>
#include <stdbool.h>
-#include <lib/kstdio.h>
-#include <lib/kstring.h>
+#include <libc/stdio.h>
+#include <libc/string.h>
-FILE *kstdout;
+FILE *stdout;
-int kfputc(int c, FILE *f)
+int fputc(int c, FILE *f)
{
(void)f;
video_putchar(c);
diff --git a/kc/core/task.c b/kc/core/task.c
index 5eaa3fb..a298a05 100644
--- a/kc/core/task.c
+++ b/kc/core/task.c
@@ -12,7 +12,7 @@
#include <stdbool.h>
#include <lib/elf.h>
-#include <lib/kstdio.h>
+#include <libc/stdio.h>
#include "arch_thread.h"
@@ -110,7 +110,7 @@ static volatile atomic_bool preempt_switch_flag = false;
static void *idle_thread_entry(void *)
{
- kprintf("idle thread started\n");
+ printf("idle thread started\n");
__asm__ ("sti");
@@ -132,7 +132,7 @@ static void *sleepy_thread_entry(void *p)
{
sleep_thread(sleep_nanoseconds);
thread_slept_count++;
- kprintf("thread slept %d times\n", thread_slept_count);
+ printf("thread slept %d times\n", thread_slept_count);
}
(void)thread_slept_count;
@@ -414,19 +414,19 @@ union kc_thread_result kct_wait(struct kc_thread *target)
static void *waited_thread_test(void *)
{
- kprintf("worker thread, sleeping for some time...\n");
+ printf("worker thread, sleeping for some time...\n");
sleep_thread(30000000000);
return (void *)1;
}
static void *waiting_thread_test(void *)
{
- kprintf("waiting thread\n");
+ printf("waiting thread\n");
struct kc_thread *t = create_thread(waited_thread_test, nullptr);
t->status = READY;
thread_queue_push_back(&ready_queue, t);
union kc_thread_result r = kct_wait(t);
- kprintf("waited thread terminated result: %d\n", r);
+ printf("waited thread terminated result: %d\n", r);
return nullptr;
}
@@ -439,7 +439,7 @@ noreturn void task_init(void)
timesource = &pit8253_timer_source;
timesource->append_callback(sleeping_thread_callback);
timesource->start();
- kprintf(
+ printf(
"starting task management, timesource delta %luns\n",
timesource->nanoseconds_delta());
@@ -454,7 +454,7 @@ noreturn void task_init(void)
thread_queue_push(&ready_queue, idle_thread);
block_thread(BLOCKED);
// shouldn't ever get here
- kprintf("the idle thread exited somehow. we're back in the boot thread. this is not good.\n");
+ printf("the idle thread exited somehow. we're back in the boot thread. this is not good.\n");
PANIC(DEAD_END);
}
diff --git a/kc/core/video.c b/kc/core/video.c
index 6d89c08..a3bdce2 100644
--- a/kc/core/video.c
+++ b/kc/core/video.c
@@ -46,8 +46,8 @@
#include <stdbool.h>
-#include <lib/kstring.h>
-#include <lib/kstdio.h>
+#include <libc/string.h>
+#include <libc/stdio.h>
#include <lib/numeric.h>
#include <kernel/entry.h>
@@ -227,7 +227,7 @@ int video_init(void)
}
}
- kprintf("video output %ix%i pixels, %i bytes per line, %s 32 bytes per pixel\n",
+ printf("video output %ix%i pixels, %i bytes per line, %s 32 bytes per pixel\n",
boot_data->width, boot_data->height, boot_data->pitch, video_format_name);
diff --git a/kc/core/vm_tree.c b/kc/core/vm_tree.c
index 9bab154..72affe8 100644
--- a/kc/core/vm_tree.c
+++ b/kc/core/vm_tree.c
@@ -31,8 +31,8 @@
#include "vm_tree.h"
#include "panic.h"
-#include <lib/kstdio.h>
-#include <lib/kstring.h>
+#include <libc/stdio.h>
+#include <libc/string.h>
#define assert(expr)
@@ -102,7 +102,7 @@ void vmt_init_node(
}
else
{
- kprintf("fatal: attempt to insert overlapping vm node\n"
+ printf("fatal: attempt to insert overlapping vm node\n"
"node 1: %p: %p @ %zu bytes\n"
"node 2: %p: %p @ %zu bytes\n",
node->key.address, node->key.size,