85 lines
1.5 KiB
C
85 lines
1.5 KiB
C
#include <logger.h>
|
|
#include <timer.h>
|
|
#include <kmalloc.h>
|
|
#include <uart.h>
|
|
#include <dtb.h>
|
|
#include <initrd.h>
|
|
#include <mman.h>
|
|
#include <shell.h>
|
|
#include <vector.h>
|
|
#include <utils.h>
|
|
#include <thread.h>
|
|
#include <exception.h>
|
|
#include <interrupt.h>
|
|
|
|
static inline
|
|
void _init(void *dtb, file_node_t **initrd_root)
|
|
{
|
|
init_exception();
|
|
|
|
// UART
|
|
uart_init();
|
|
|
|
// Device tree
|
|
DEBUG_DTB(dtb);
|
|
dtb_start = dtb;
|
|
vector_t *dtb_struct_cbs = make_vector(0);
|
|
VEC_PUSH(dtb_struct_cbs, &initrd_dtb_cb);
|
|
VEC_PUSH(dtb_struct_cbs, &mman_dtb_memory_cb);
|
|
fdt_traverse(dtb_struct_cbs);
|
|
DEBUG_DTB("device tree parse done");
|
|
|
|
// Initramfs
|
|
DEBUG_INITRD(initrd_start);
|
|
*initrd_root = initrd_init();
|
|
|
|
// Memory (Buddy system)
|
|
mman_init();
|
|
|
|
// Threads
|
|
thread_init();
|
|
|
|
init_interrupt();
|
|
}
|
|
|
|
static inline
|
|
void _print_time(uint64_t)
|
|
{
|
|
uint64_t cntpct_el0, cntfrq_el0;
|
|
R_SYSREG(cntpct_el0, cntpct_el0);
|
|
R_SYSREG(cntfrq_el0, cntfrq_el0);
|
|
DEBUG_EXCEP(cntpct_el0 / cntfrq_el0);
|
|
|
|
task_t task = {
|
|
.firing_tick = cntpct_el0 + 2 * cntfrq_el0,
|
|
.interval = 2 * cntfrq_el0,
|
|
.repeat = 1,
|
|
|
|
.func = _print_time,
|
|
.param = 0x0,
|
|
};
|
|
|
|
add_timer_task(task);
|
|
}
|
|
|
|
static inline
|
|
int32_t _test(uint64_t)
|
|
{
|
|
for (int i = 0; i < 10; ++i) {
|
|
LOG(i); DEBUG_THREAD(get_current());
|
|
sleep(1000000);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void main(void *dtb)
|
|
{
|
|
file_node_t *initrd_root = 0x0;
|
|
_init(dtb, &initrd_root);
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
run_thread(_test, 0x0);
|
|
|
|
schedule();
|
|
}
|