2017-11-04 07:45:48 -04:00
|
|
|
#include "console.h"
|
2017-11-03 22:32:23 -04:00
|
|
|
#include "logger.h"
|
2017-11-05 02:13:54 -05:00
|
|
|
#include "memory.h"
|
2017-11-03 22:32:23 -04:00
|
|
|
#include "protected.h"
|
2017-11-04 11:08:59 -04:00
|
|
|
#include "paging.h"
|
2017-11-03 22:32:23 -04:00
|
|
|
#include "timer.h"
|
2017-11-05 12:03:00 -05:00
|
|
|
#include "tasks.h"
|
2017-11-03 22:32:23 -04:00
|
|
|
|
2017-11-04 06:38:28 -04:00
|
|
|
#include <kernelmq/info.h>
|
|
|
|
#include <kernelmq/stdlib.h>
|
2017-11-05 05:57:23 -05:00
|
|
|
#include <kernelmq/module.h>
|
2017-11-04 06:38:28 -04:00
|
|
|
|
|
|
|
static struct KernelMQ_Info kinfo;
|
|
|
|
|
2017-11-06 07:00:13 -05:00
|
|
|
#define TIMER_FREQ 50
|
|
|
|
|
|
|
|
static unsigned long ticks = 0;
|
|
|
|
|
2017-11-03 22:32:23 -04:00
|
|
|
static void on_timer();
|
|
|
|
|
2017-11-04 06:38:28 -04:00
|
|
|
void main(const struct KernelMQ_Info *const kinfo_ptr)
|
2017-11-03 22:32:23 -04:00
|
|
|
{
|
2017-11-04 07:45:48 -04:00
|
|
|
console_initialize();
|
|
|
|
|
2017-11-04 06:38:28 -04:00
|
|
|
kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info));
|
|
|
|
|
2017-11-04 08:01:10 -04:00
|
|
|
if (!kernelmq_info_validate_and_copy(&kinfo, kinfo_ptr)) {
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_fail_from("main", "Invalid kernel information. Halt.");
|
2017-11-04 06:38:28 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_info_from("main", "Kernel command line: %s", kinfo.cmdline);
|
2017-11-04 08:01:10 -04:00
|
|
|
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_info_from(
|
|
|
|
"main",
|
2017-11-05 22:48:16 -05:00
|
|
|
"Kernel phys base 0x%x, limit 0x%x",
|
2017-11-04 08:12:20 -04:00
|
|
|
kinfo.kernel_phys_base,
|
|
|
|
kinfo.kernel_phys_limit
|
|
|
|
);
|
|
|
|
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_info_from(
|
|
|
|
"main",
|
2017-11-05 22:48:16 -05:00
|
|
|
"Kernel virt base 0x%x, limit 0x%x",
|
2017-11-04 08:12:20 -04:00
|
|
|
kinfo.kernel_virt_base,
|
|
|
|
kinfo.kernel_virt_limit
|
|
|
|
);
|
|
|
|
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_info_from(
|
|
|
|
"main",
|
2017-11-05 22:48:16 -05:00
|
|
|
"Kernel size 0x%x, offset 0x%x",
|
2017-11-04 08:12:20 -04:00
|
|
|
kinfo.kernel_size,
|
|
|
|
kinfo.kernel_offset
|
|
|
|
);
|
|
|
|
|
2017-11-04 08:01:10 -04:00
|
|
|
for (unsigned int i = 0; i < kinfo.modules_count; ++i) {
|
|
|
|
struct KernelMQ_Info_Module *module = &kinfo.modules[i];
|
|
|
|
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_info_from(
|
|
|
|
"main",
|
2017-11-05 22:48:16 -05:00
|
|
|
"Module at 0x%x, size 0x%x, command line: %s",
|
2017-11-04 08:01:10 -04:00
|
|
|
module->base,
|
|
|
|
module->size,
|
|
|
|
module->cmdline
|
|
|
|
);
|
|
|
|
}
|
2017-11-04 06:38:28 -04:00
|
|
|
|
2017-11-05 02:13:54 -05:00
|
|
|
memory_initialize(&kinfo);
|
|
|
|
|
2017-11-05 10:26:30 -05:00
|
|
|
protected_initialize(&kinfo);
|
2017-11-03 22:32:23 -04:00
|
|
|
|
2017-11-04 11:08:59 -04:00
|
|
|
// Set up a new post-relocate bootstrap pagetable so that
|
|
|
|
// we can map in VM, and we no longer rely on pre-relocated
|
|
|
|
// data.
|
|
|
|
paging_clear();
|
2017-11-05 01:56:53 -04:00
|
|
|
paging_identity(); // Still need 1:1 for lapic and video mem and such.
|
2017-11-04 11:08:59 -04:00
|
|
|
paging_mapkernel(&kinfo);
|
|
|
|
paging_load();
|
|
|
|
|
2017-11-06 07:00:13 -05:00
|
|
|
timer_initialize(TIMER_FREQ);
|
|
|
|
timer_register_handler(on_timer);
|
|
|
|
|
|
|
|
while (ticks < TIMER_FREQ * 3) {}
|
|
|
|
|
2017-11-05 05:57:23 -05:00
|
|
|
for (unsigned int i = 0; i < kinfo.modules_count; ++i) {
|
2017-11-05 12:03:00 -05:00
|
|
|
tasks_switch_to_user(kinfo.modules[i].base);
|
2017-11-05 05:57:23 -05:00
|
|
|
}
|
|
|
|
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_warn_from("main", "Nothing to do.");
|
|
|
|
logger_fail_from("main", "Halt.");
|
2017-11-03 22:32:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_timer()
|
|
|
|
{
|
2017-11-06 07:00:13 -05:00
|
|
|
if (ticks % TIMER_FREQ == 0) {
|
|
|
|
logger_info_from("main", "Timer tick %u.", ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
++ticks;
|
2017-11-03 22:32:23 -04:00
|
|
|
}
|