Files
mango/init/main.c

76 lines
1.5 KiB
C
Raw Normal View History

2024-11-02 11:31:51 +00:00
#include <mango/arg.h>
#include <mango/clock.h>
#include <mango/cpu.h>
#include <mango/init.h>
#include <mango/input.h>
#include <mango/libc/stdio.h>
#include <mango/machine/init.h>
#include <mango/object.h>
#include <mango/panic.h>
#include <mango/printk.h>
#include <mango/sched.h>
#include <mango/test.h>
#include <stdint.h>
extern unsigned long get_rflags(void);
2023-02-05 10:50:13 +00:00
extern char __pstart[], __pend[];
2023-02-04 19:19:48 +00:00
void print_kernel_banner(void)
{
2024-11-02 11:31:51 +00:00
printk("Mango kernel version " BUILD_ID);
2023-02-04 19:19:48 +00:00
}
static void hang(void)
{
struct task *self = current_task();
struct thread *thread = current_thread();
while (1) {
printk("[cpu %u, task %u, thread %u]: tick",
this_cpu(),
self->t_id,
thread->tr_id);
milli_sleep(2000);
}
}
void background_thread(void)
{
struct task *self = current_task();
struct thread *thread = current_thread();
printk("background_thread() running on processor %u", this_cpu());
milli_sleep(1000);
while (1) {
printk("[cpu %u, task %u, thread %u]: tock",
this_cpu(),
self->t_id,
thread->tr_id);
milli_sleep(2000);
}
}
static void putchar(char c)
{
unsigned long flags;
struct queue *consoles = get_consoles(&flags);
queue_foreach(struct console, con, consoles, c_list)
{
console_write(con, &c, 1);
}
put_consoles(consoles, flags);
}
void kernel_init(uintptr_t arg)
{
ml_init(arg);
printk("kernel_init() running on processor %u", this_cpu());
create_kernel_thread(background_thread);
hang();
}