Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
init.c
Go to the documentation of this file.
1#include "init/init.h"
2#include "hal/apic/apic.h"
3#include "hal/cpu/interrupt.h"
4#include "init/loader.h"
5#include "libk/debug/debug.h"
6#include "libk/serial.h"
8#include "notify.h"
9#include "procc/process.h"
10#include "tty/tty.h"
11#include <console/console.h>
12#include <hal/acpi/hpet.h>
13#include <memory/kalloc.h>
14#include <net/netutils.h>
15#include <str.h>
16
17// prototypes
18__attribute__((noreturn)) void _start(struct stivale2_struct* stivale2_struct);
19
20KERNEL_API void _ZdlPv(void* ptr);
21KERNEL_API void _ZdlPvm(void* ptr, size_t size);
22int atexit(void (*function)(void));
23KERNEL_API void __cxa_finalize(void* dso_handle);
24
25static init_context_t ctx = {};
26
27// entry point of kernel
28__attribute__((unused, noreturn)) extern void
29_start(struct stivale2_struct* stivale2_struct) {
33
34 // for logger
35 auto irq = irq_alloc_entry(0);
36 irq_register(0, irq, (void*)serial2_flush, true, 0x28, 0,
39
40 wait_until_receive_notify("/vfs/root", 5000);
41
42 void* test_ptr = kalloc(256);
43 if (test_ptr) {
44 kalloc_metadata_t* meta =
45 (kalloc_metadata_t*)((uintptr_t)test_ptr -
46 sizeof(kalloc_metadata_t) - 16);
47 LOG2_INFO("KALLOC_TEST",
48 "Allocated 256 bytes at %x, sizeof(meta)=%d",
49 test_ptr, sizeof(kalloc_metadata_t));
50 LOG2_INFO("KALLOC_TEST",
51 "metadata: size=%d, magic=0x%x, pad=0x%x", meta->size,
52 meta->magic, meta->_pad);
53 kfree2(test_ptr);
54 LOG2_INFO("KALLOC_TEST", "Freed successfully");
55 }
56
57 /* Large allocation test */
58 void* large_ptr = kalloc(4096);
59 if (large_ptr) {
60 kalloc_metadata_t* meta =
61 (kalloc_metadata_t*)((uintptr_t)large_ptr -
62 sizeof(kalloc_metadata_t) - 16);
63 LOG2_INFO("KALLOC_TEST",
64 "Allocated 4096 bytes at %x, sizeof(meta)=%d",
65 large_ptr, sizeof(kalloc_metadata_t));
66 LOG2_INFO("KALLOC_TEST",
67 "metadata: size=%d, magic=0x%x, pad=0x%x", meta->size,
68 meta->magic, meta->_pad);
69 kfree2(large_ptr);
70 LOG2_INFO("KALLOC_TEST", "Large alloc freed successfully");
71 }
72
74 start_tty();
75
76 execve("/sbin/hello.elf", 0, 0);
77 // execve("/sbin/term.elf", 0, 0);
78 // execve("/sysroot/usr/bin/vim.", 0, 0);
79
80 // KDEBUG(DEBUG_LEVEL_INFO, "Boot complete, entering idle loop...\n");
81
82
83 // print_dentry_tree(get_root_dentry(), 0);
84
85 INFLOOP;
86}
87
88// cpp runtime stub
89KERNEL_API void _ZdlPv(void* ptr) {
90 kfree(ptr, sizeof(ptr));
91}
92
93KERNEL_API void _ZdlPvm(void* ptr, size_t size) {
94 kfree(ptr, size);
95}
96
98int atexit(__attribute__((unused)) void (*function)(void)) {
99 LOG_DEBUG("LIBC", "atexit called, but not implemented");
100 return 0;
101}
102
103KERNEL_API void __cxa_finalize(__attribute__((unused)) void* dso_handle) {
104 LOG_DEBUG("LIBC", "__cxa_finalize called, but not implemented");
105}
#define APIC_TIMER_PERIOD
Definition apic.h:21
void vxAPICCreateTimer(uint32_t type, uint64_t freq_us, uint16_t vector)
Definition apic_timer.c:162
typedef __attribute__
Definition msi.c:47
#define INFLOOP
Definition init.h:32
uint16_t irq_alloc_entry(uint8_t core)
Definition interrupt.c:109
void irq_register(uint8_t core, int n, void *handler, boolean_t use_default_isr, uint16_t selector, uint8_t ist, uint8_t type_attr)
Definition interrupt.c:70
#define INTERRUPT_ATTR_KERNEL
Definition interrupt.h:28
void kfree(void *ptr, size_t size)
void * kalloc(size_t size)
void kfree2(void *ptr)
void run_all_init_calls(init_context_t *ctx)
Definition loader.c:215
void build_context_from_stivale2(struct stivale2_struct *stivale2_struct, init_context_t *ctx)
Definition loader.c:81
int wait_until_receive_notify(const char *name, uint64_t timeout)
Definition notify.c:140
void pmm_log_usage()
int execve(const char *path, char *const *argv, char *const *envp)
Definition process.c:173
void serial2_flush(void)
Definition serial.c:359
void serial_setup(void)
Definition serial.c:46
#define LOG2_INFO(mod, fmt,...)
Definition serial.h:33
#define LOG_DEBUG(mod, fmt,...)
Definition serial.h:22
uint32_t _pad
Definition kalloc.h:21
uint32_t magic
Definition kalloc.h:20
void start_tty()
Definition tty.c:246
#define KERNEL_API
Definition type.h:93
unsigned long uintptr_t
Definition type.h:73
size_t size
Definition vnode.h:3
uint64_t ptr
Definition xhci.hpp:0