283
|
1 module kernel;
|
292
|
2
|
283
|
3 import memory;
|
|
4 import process;
|
292
|
5 import arch;
|
355
|
6 import io;
|
402
|
7 import debug;
|
283
|
8
|
381
|
9
|
283
|
10 // Main entry point of the kernel:
|
293
|
11 function void start()
|
283
|
12 {
|
381
|
13 io.println("Welcome to lcfos!");
|
353
|
14 arch.init();
|
407
|
15 memory.init();
|
393
|
16 process.init();
|
407
|
17 load_init_process();
|
408
|
18 io.println("Kernel loading finished, now switching to next process");
|
|
19 process.execute_next();
|
283
|
20 }
|
|
21
|
367
|
22 // Called in total stress:
|
293
|
23 function void panic()
|
283
|
24 {
|
407
|
25 io.println("Kernel panic!");
|
308
|
26 arch.halt();
|
283
|
27 }
|
|
28
|
408
|
29 type struct {
|
|
30 int magic;
|
|
31 int num_images;
|
|
32 } ramdisk_header_t;
|
|
33
|
|
34 // Load init process (first image) from ram image:
|
407
|
35 function void load_init_process()
|
|
36 {
|
408
|
37 // Load image:
|
|
38 var byte* image_addr;
|
|
39 image_addr = arch.get_image_address();
|
|
40 io.print2("ramdisk address: ", cast<int>(image_addr));
|
407
|
41
|
408
|
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 }
|
407
|
69 }
|
|
70
|