comparison 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
comparison
equal deleted inserted replaced
407:9eb1fc6aad6c 408:ad6be5454067
1 module kernel; 1 module kernel;
2 2
3 import memory; 3 import memory;
4 import process; 4 import process;
5 import scheduler;
6 import arch; 5 import arch;
7 import io; 6 import io;
8 import debug; 7 import debug;
9 8
10 9
11 // Main entry point of the kernel: 10 // Main entry point of the kernel:
12 function void start() 11 function void start()
13 { 12 {
14 io.println("Welcome to lcfos!"); 13 io.println("Welcome to lcfos!");
15 arch.init(); 14 arch.init();
16
17 memory.init(); 15 memory.init();
18 process.init(); 16 process.init();
19 load_init_process(); 17 load_init_process();
20 18 io.println("Kernel loading finished, now switching to next process");
21 io.println("Kernel finished"); 19 process.execute_next();
22 panic();
23 } 20 }
24 21
25 // Called in total stress: 22 // Called in total stress:
26 function void panic() 23 function void panic()
27 { 24 {
28 io.println("Kernel panic!"); 25 io.println("Kernel panic!");
29 arch.halt(); 26 arch.halt();
30 } 27 }
31 28
29 type struct {
30 int magic;
31 int num_images;
32 } ramdisk_header_t;
33
34 // Load init process (first image) from ram image:
32 function void load_init_process() 35 function void load_init_process()
33 { 36 {
34 var process.process_t* init_proc; 37 // Load image:
35 init_proc = process.create(); 38 var byte* image_addr;
36 process.enqueue(init_proc); 39 image_addr = arch.get_image_address();
40 io.print2("ramdisk address: ", cast<int>(image_addr));
37 41
38 io.print2("init address ", cast<int>(init_proc)); 42 var ramdisk_header_t* ramdisk_header;
43 ramdisk_header = image_addr;
44 var byte* image_ptr;
45 image_ptr = image_addr;
46 if (0x1337 == ramdisk_header->magic)
47 {
48 image_ptr += 8;
49 io.print2("Number of images: ", ramdisk_header->num_images);
50 if (ramdisk_header->num_images > 0)
51 {
52 io.println("Loading init");
53 var int init_size;
54 init_size = *(cast<int*>(image_ptr));
55 io.print2("Init size:", init_size);
56 image_ptr += 4;
57
58 // Allocate physical memory:
59 var byte* prog_mem;
60 prog_mem = memory.alloc(init_size);
61 io.print2("Image_ptr:", cast<int>(image_ptr));
62 memory.memcpy(prog_mem, image_ptr, init_size);
63
64 var process.process_t* init_proc;
65 init_proc = process.create();
66 // process.enqueue(init_proc);
67 }
68 }
39 } 69 }
40 70