view kernel/kernel.c3 @ 408:ad6be5454067

Added image build task
author Windel Bouwman
date Sat, 21 Feb 2015 12:17:47 +0100
parents 9eb1fc6aad6c
children 6aa9743ed362
line wrap: on
line source

module kernel;

import memory;
import process;
import arch;
import io;
import debug;


// Main entry point of the kernel:
function void start()
{
    io.println("Welcome to lcfos!");
    arch.init();
    memory.init();
    process.init();
    load_init_process();
    io.println("Kernel loading finished, now switching to next process");
    process.execute_next();
}

// Called in total stress:
function void panic()
{
    io.println("Kernel panic!");
    arch.halt();
}

type struct {
    int magic;
    int num_images;
} ramdisk_header_t;

// Load init process (first image) from ram image:
function void load_init_process()
{
    // Load image:
    var byte* image_addr;
    image_addr = arch.get_image_address();
    io.print2("ramdisk address: ", cast<int>(image_addr));

    var ramdisk_header_t* ramdisk_header;
    ramdisk_header = image_addr;
    var byte* image_ptr;
    image_ptr = image_addr;
    if (0x1337 == ramdisk_header->magic)
    {
        image_ptr += 8;
        io.print2("Number of images: ", ramdisk_header->num_images);
        if (ramdisk_header->num_images > 0)
        {
            io.println("Loading init");
            var int init_size;
            init_size = *(cast<int*>(image_ptr));
            io.print2("Init size:", init_size);
            image_ptr += 4;

            // Allocate physical memory:
            var byte* prog_mem;
            prog_mem = memory.alloc(init_size);
            io.print2("Image_ptr:", cast<int>(image_ptr));
            memory.memcpy(prog_mem, image_ptr, init_size);

            var process.process_t* init_proc;
            init_proc = process.create();
            // process.enqueue(init_proc);
        }
    }
}