Mercurial > lcfOS
diff 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 diff
--- a/kernel/kernel.c3 Fri Feb 20 15:47:54 2015 +0100 +++ b/kernel/kernel.c3 Sat Feb 21 12:17:47 2015 +0100 @@ -2,7 +2,6 @@ import memory; import process; -import scheduler; import arch; import io; import debug; @@ -13,13 +12,11 @@ { io.println("Welcome to lcfos!"); arch.init(); - memory.init(); process.init(); load_init_process(); - - io.println("Kernel finished"); - panic(); + io.println("Kernel loading finished, now switching to next process"); + process.execute_next(); } // Called in total stress: @@ -29,12 +26,45 @@ 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() { - var process.process_t* init_proc; - init_proc = process.create(); - process.enqueue(init_proc); + // Load image: + var byte* image_addr; + image_addr = arch.get_image_address(); + io.print2("ramdisk address: ", cast<int>(image_addr)); - io.print2("init address ", cast<int>(init_proc)); + 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); + } + } }