24 extern uint64_t _asm_physmap;
26 /* Check if the compiler thinks if we are targeting the wrong operating system. */
27 #if defined(__linux__)
28 #error "compiling for linux, not target os"
31 #define STACK_SIZE 65536
32 __attribute__((aligned(16))) size_t stack[STACK_SIZE / sizeof(size_t)];
34 static void check_mbmagic(uint64_t magic) {
35 if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
36 printk("Invalid magic number: 0x%x\n", (unsigned) magic);
41 void kernel_main(struct multiboot_info *mbinfo, uint64_t mbmagic) {
43 /* we do this first so we can print debug messages */
44 terminal_initialize();
46 terminal.writestring("ZOS 64 bit booting...\n");
47 check_mbmagic(mbmagic);
49 printk("kernel_vma = 0x%llx\n", (uint64_t)_kernel_vma);
50 printk("kernel_end = 0x%llx\n", (uint64_t)_kernel_end);
51 printk("kernel_phys_end = 0x%llx\n", (uint64_t)_kernel_phys_end);
52 printk("kernel_size = %llu KB\n", (uint64_t)_kernel_size/1024);
53 printk("_asm_physmap = %llx\n", _asm_physmap);
55 #define MBADDR(x) (PHY2VIRTP((paddr_t)(x)))
58 if (mbinfo->mods_count > 0) {
60 struct multiboot_mod_list *modlist;
64 mod = MBADDR(mbinfo->mods_addr);
66 for (n=0;n<mbinfo->mods_count;n++) {
68 printk("Module: %s\n", MBADDR(modlist[n].cmdline));
69 start = MBADDR(modlist[n].mod_start);
70 memcpy(line, start,80);
78 printk("mem.kend = 0x%llx\n", (uint64_t)memory.kend);
85 init_timer(200); /* arg is timer tick interrupt Hz */
86 /* klog isn't really useful before here */
90 /* from here on out, we may be interrupted */
95 /* since we're the current task when we call schedule,
96 * we won't get back on the runqueue. The 0 task
97 * will still be allocated. That's ok, it's a static
98 * structure in process.c anyway.
99 * If it changes to dynamic alloc, would want to
102 printk("shouldn't happen\n");
109 void klog(int level, const char *fmt, ...) {
112 printk("[%u.%u] ", system_time.tv_sec, system_time.tv_nsec/1000000);
119 void panic(const char *fmt, ...) {