# HG changeset patch # User Windel Bouwman # Date 1424517467 -3600 # Node ID ad6be54540679294a35b1ab4500ce98e89dfbbc0 # Parent 9eb1fc6aad6c104b22463b0f65fa02dbf6291c82 Added image build task diff -r 9eb1fc6aad6c -r ad6be5454067 build.xml --- a/build.xml Fri Feb 20 15:47:54 2015 +0100 +++ b/build.xml Sat Feb 21 12:17:47 2015 +0100 @@ -1,9 +1,11 @@ - - + + + + + - diff -r 9eb1fc6aad6c -r ad6be5454067 customtasks.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/customtasks.py Sat Feb 21 12:17:47 2015 +0100 @@ -0,0 +1,33 @@ +""" + Custom task to create boot image. +""" +from ppci import tasks +import struct + + +@tasks.register_task('mkimage') +class MkImageTask(tasks.Task): + """ Concatenate kernel and boot data in cunning manner """ + def run(self): + self.logger.info('Constructing boot image') + data = bytearray() + # TODO: parameterize: + + # Read kernel: + with open(self.relpath('kernel/obj/kernel.bin'), 'rb') as f: + data += f.read() + + # Read images: + with open(self.relpath('user/obj/init.bin'), 'rb') as f: + init = f.read() + + # Construct table: + table = struct.pack(' - - - - - + output="obj/kernel.bin" /> diff -r 9eb1fc6aad6c -r ad6be5454067 kernel/kernel.c3 --- 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(image_addr)); - io.print2("init address ", cast(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(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(image_ptr)); + memory.memcpy(prog_mem, image_ptr, init_size); + + var process.process_t* init_proc; + init_proc = process.create(); + // process.enqueue(init_proc); + } + } } diff -r 9eb1fc6aad6c -r ad6be5454067 kernel/memory.c3 --- a/kernel/memory.c3 Fri Feb 20 15:47:54 2015 +0100 +++ b/kernel/memory.c3 Sat Feb 21 12:17:47 2015 +0100 @@ -9,7 +9,7 @@ function void init() { - ptr = 0x80000; + ptr = 0x60080000; } function byte* alloc(int size) @@ -25,10 +25,24 @@ return ptr2; } +function byte* allocate_physical() +{ + return 0; +} + +function byte* allocate_virtual(byte* address) +{ + var byte* address2; + address2 = allocate_physical(); + return address2; +} + function void memcpy(byte* dst, byte* src, int size) { var int i; - for (i = 0; i < size; i = i + 1) + io.print2("memcpy to ", cast(dst)); + io.print2("memcpy from ", cast(src)); + for (i = 0; i < size; i += 1) { *(dst + i) = *(src + i); } diff -r 9eb1fc6aad6c -r ad6be5454067 kernel/process.c3 --- a/kernel/process.c3 Fri Feb 20 15:47:54 2015 +0100 +++ b/kernel/process.c3 Sat Feb 21 12:17:47 2015 +0100 @@ -14,6 +14,7 @@ var process_t* first_process; var process_t* last_process; var int next_pid; +var process_t* current; function void init() { @@ -69,3 +70,17 @@ return 0; } + +function void execute_next() +{ + var process.process_t *old; + + old = 0; + + if (old != current) + { + //execute(current); + } + + kernel.panic(); +} diff -r 9eb1fc6aad6c -r ad6be5454067 kernel/ramdisk.asm --- a/kernel/ramdisk.asm Fri Feb 20 15:47:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ - -section ramdisk - -ramdisk_begin: - diff -r 9eb1fc6aad6c -r ad6be5454067 kernel/schedule.c3 --- a/kernel/schedule.c3 Fri Feb 20 15:47:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - -module scheduler; - -import process; -import arch; - -var process.process_t *current; - -function void execute_next() -{ - var process.process_t *old; - - old = 0; - - if (old != current) - { - //execute(current); - } -} - diff -r 9eb1fc6aad6c -r ad6be5454067 kernel/syscall.c3 --- a/kernel/syscall.c3 Fri Feb 20 15:47:54 2015 +0100 +++ b/kernel/syscall.c3 Sat Feb 21 12:17:47 2015 +0100 @@ -5,7 +5,6 @@ */ import arch; -import scheduler; import process; diff -r 9eb1fc6aad6c -r ad6be5454067 run.sh --- a/run.sh Fri Feb 20 15:47:54 2015 +0100 +++ b/run.sh Sat Feb 21 12:17:47 2015 +0100 @@ -3,6 +3,6 @@ set -e # -S means halt at start: -qemu-system-arm -M vexpress-a9 -m 128M -kernel kernel/kernel_arm.bin \ +qemu-system-arm -M vexpress-a9 -m 128M -kernel image.img \ -serial stdio