From 938672f7c99452ea2746a6dfc92d815d8b1f8c66 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Mon, 4 Feb 2008 16:44:11 +0000 Subject: [PATCH] Changed the virt-to-phys debug breakpoint name to break_virtual Changed l4id_t type to integer to recognise negative id values like L4_ANYTHREAD. Added an extremely simple script that cleans and builds everything in right order. Increased boot pmds by one: This is due to the fact that if the 1MB initial allocation area of the kernel is not 1MB-aligned, it is ought to be mapped from the middle of one MB to next, which requires 2 pmds. modified: .gdbinit modified: README new file: buildall.sh modified: include/l4/arch/arm/types.h modified: include/l4/generic/scheduler.h modified: loader/kernel.S modified: loader/main.c modified: loader/mylink.lds modified: loader/start.axf.S modified: src/glue/arm/init.c modified: src/glue/arm/memory.c modified: tasks/fs0/src/bdev.c modified: tasks/mm0/include/kdata.h modified: tasks/mm0/include/vm_area.h modified: tasks/mm0/src/init.c modified: tasks/mm0/src/task.c modified: tools/ksym_to_lds.py modified: tools/l4-qemu --- .gdbinit | 2 +- README | 2 +- buildall.sh | 28 ++++++++++++++++++ include/l4/arch/arm/types.h | 2 +- include/l4/generic/scheduler.h | 6 ++-- loader/kernel.S | 14 ++++----- loader/main.c | 18 +++++++----- loader/mylink.lds | 8 ++--- loader/start.axf.S | 6 ++-- src/glue/arm/init.c | 4 +-- src/glue/arm/memory.c | 4 +-- tasks/fs0/src/bdev.c | 2 +- tasks/mm0/include/kdata.h | 2 +- tasks/mm0/include/vm_area.h | 2 +- tasks/mm0/src/init.c | 34 +++++++++++---------- tasks/mm0/src/task.c | 54 +++++++++++++++++----------------- tools/ksym_to_lds.py | 2 +- tools/l4-qemu | 4 +-- 18 files changed, 114 insertions(+), 80 deletions(-) create mode 100755 buildall.sh diff --git a/.gdbinit b/.gdbinit index 01572c7..28b897b 100644 --- a/.gdbinit +++ b/.gdbinit @@ -2,7 +2,7 @@ target remote localhost:1234 load final.axf stepi sym final.axf -break bkpt_phys_to_virt +break break_virtual continue stepi sym start.axf diff --git a/README b/README index 6f0872c..7078054 100644 --- a/README +++ b/README @@ -37,7 +37,7 @@ Codezero microkernel: Based on L4 microkernel principles, there are only a few system calls and the microkernel provides purely mechanism; threads and address spaces, and the methods of inter-process communication between them. Anything beyond these are policy and they are implemented in the userspace. Due to this -rigorously simple design the microkernel can be used to design completely +rigorously simple design the same microkernel can be used to design completely different operating systems. In terms of other features, the microkernel is preemptive, and smp-ready. Currently only synchronous communication is implemented, but this will change in the near future. diff --git a/buildall.sh b/buildall.sh new file mode 100755 index 0000000..7450dcd --- /dev/null +++ b/buildall.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +rm -rf build +echo -e "\n--- Building kernel --- " +scons configure +scons build +cd tasks +echo -e "\n--- Building libraries --- " +cd libmem +scons +cd ../libl4 +scons +cd ../libposix +scons +echo -e "\n--- Building tasks --- " +cd ../mm0 +scons +cd ../fs0 +scons +cd ../test0 +scons +echo -e "\n--- Building bootdesc ---" +cd ../bootdesc +scons +cd ../.. +echo -e "\n--- Packing all up ---" +./packer.sh +echo -e "\n--- Build Completed ---\n" diff --git a/include/l4/arch/arm/types.h b/include/l4/arch/arm/types.h index 3106d6c..4c5df35 100644 --- a/include/l4/arch/arm/types.h +++ b/include/l4/arch/arm/types.h @@ -12,7 +12,7 @@ typedef signed short s16; typedef signed char s8; /* Thread/Space id type */ -typedef unsigned int l4id_t; +typedef int l4id_t; #endif /* !__ASSEMBLY__ */ #endif /* !__ARCH_TYPES_H__ */ diff --git a/include/l4/generic/scheduler.h b/include/l4/generic/scheduler.h index 5e31d04..19d32c0 100644 --- a/include/l4/generic/scheduler.h +++ b/include/l4/generic/scheduler.h @@ -10,9 +10,9 @@ #include INC_SUBARCH(mm.h) #include INC_GLUE(memory.h) -/* Ticks per second */ -#define HZ 1000 -#define TASK_TIMESLICE_DEFAULT 1 +/* Ticks per second, try ticks = 1000 + timeslice = 1 for regressed preemption test. */ +#define HZ 100 +#define TASK_TIMESLICE_DEFAULT 20 /* #define TASK_TIMESLICE_DEFAULT (HZ/100)*/ static inline struct ktcb *current_task(void) diff --git a/loader/kernel.S b/loader/kernel.S index 9ffa417..ebbece2 100644 --- a/loader/kernel.S +++ b/loader/kernel.S @@ -5,21 +5,21 @@ .section .kernel .incbin "start.axf" -.align 4 -.section .mm0 -.incbin "mm0.axf" .align 4 .section .bootdesc - .incbin "bootdesc.axf" +.align 4 +.section .mm0 +.incbin "mm0.axf" + +.align 4 .section .fs0 - .incbin "fs0.axf" -.align 4 +.align 4 .section .test0 - .incbin "test0.axf" + .align 4 diff --git a/loader/main.c b/loader/main.c index 448b4b3..91f4425 100644 --- a/loader/main.c +++ b/loader/main.c @@ -106,7 +106,6 @@ extern char _start_test0[]; extern char _end_test0[]; extern char _start_bootdesc[]; extern char _end_bootdesc[]; - /* This is a kernel symbol exported to loader's linker script from kernel build */ extern char bkpt_phys_to_virt[]; @@ -127,17 +126,22 @@ main(void) arch_init(); printf("elf-loader:\tStarted\n"); + printf("Loading the kernel...\n"); load_image(&kernel_entry, _start_kernel, _end_kernel); - printf("Loading the inittask\n"); - load_image(&mm0_entry, _start_mm0, _end_mm0); - printf("Loading the roottask\n"); - load_image(&fs0_entry, _start_fs0, _end_fs0); - printf("Loading the testtask\n"); - load_image(&test0_entry, _start_test0, _end_test0); + printf("Loading the bootdesc\n"); load_image(&bootdesc_entry, _start_bootdesc, _end_bootdesc); + printf("Loading mm0\n"); + load_image(&mm0_entry, _start_mm0, _end_mm0); + + printf("Loading fs0\n"); + load_image(&fs0_entry, _start_fs0, _end_fs0); + + printf("Loading test0\n"); + load_image(&test0_entry, _start_test0, _end_test0); + printf("elf-loader:\tkernel entry point is %p\n", kernel_entry); arch_start_kernel(kernel_entry); diff --git a/loader/mylink.lds b/loader/mylink.lds index f905bb4..c2b8a15 100644 --- a/loader/mylink.lds +++ b/loader/mylink.lds @@ -7,7 +7,7 @@ ENTRY(_start) SECTIONS { - . = 0x8000; + . = 0x2000000; .text : { *(.text) } .rodata : { *(.rodata) } .rodata1 : { *(.rodata1) } @@ -16,6 +16,9 @@ SECTIONS _start_kernel = .; *(.kernel) _end_kernel = .; + _start_bootdesc = .; + *(.bootdesc) + _end_bootdesc = .; _start_mm0 = .; *(.mm0) _end_mm0 = .; @@ -25,9 +28,6 @@ SECTIONS _start_test0 = .; *(.test0) _end_test0 = .; - _start_bootdesc = .; - *(.bootdesc) - _end_bootdesc = .; *(.data) } .got : { *(.got) *(.got.plt) } diff --git a/loader/start.axf.S b/loader/start.axf.S index 4837f11..964cb9d 100644 --- a/loader/start.axf.S +++ b/loader/start.axf.S @@ -10,7 +10,7 @@ .section .text .align 4 -.global bkpt_phys_to_virt; -.type bkpt_phys_to_virt, function; -.equ bkpt_phys_to_virt, 0x106f88 +.global break_virtual; +.type break_virtual, function; +.equ break_virtual, 0x106f9c diff --git a/src/glue/arm/init.c b/src/glue/arm/init.c index 222ec86..6ce7850 100644 --- a/src/glue/arm/init.c +++ b/src/glue/arm/init.c @@ -133,8 +133,8 @@ void start_vm() "add r0, pc, %0 \n" /* Special symbol that is extracted and included in the loader. * Debuggers can break on it to load the virtual symbol table */ - ".global bkpt_phys_to_virt;\n" - "bkpt_phys_to_virt:\n" + ".global break_virtual;\n" + "break_virtual:\n" "mov pc, r0 \n" /* (r0 has next instruction) */ : : "r" (KERNEL_OFFSET) diff --git a/src/glue/arm/memory.c b/src/glue/arm/memory.c index b3c4b01..4fbcdd3 100644 --- a/src/glue/arm/memory.c +++ b/src/glue/arm/memory.c @@ -39,8 +39,8 @@ unsigned int space_flags_to_ptflags(unsigned int flags) BUG(); return 0; } -#define NUM_PMD_TABLES 6 -#define NUM_PGD_TABLES 8 +#define NUM_PMD_TABLES 7 +//#define NUM_PGD_TABLES 8 /* Initial first level page table to provide startup mappings */ SECTION(".kspace.pgd") pgd_table_t kspace; diff --git a/tasks/fs0/src/bdev.c b/tasks/fs0/src/bdev.c index 526c021..f4fbcfa 100644 --- a/tasks/fs0/src/bdev.c +++ b/tasks/fs0/src/bdev.c @@ -6,7 +6,7 @@ extern char _start_bdev[]; extern char _end_bdev[]; -__attribute__((section(".data.memfs"))) char blockdevice[SZ_16MB]; +__attribute__((section(".data.memfs"))) char blockdevice[SZ_1MB*2]; void *vfs_rootdev_open(void) { diff --git a/tasks/mm0/include/kdata.h b/tasks/mm0/include/kdata.h index 2295561..d941c83 100644 --- a/tasks/mm0/include/kdata.h +++ b/tasks/mm0/include/kdata.h @@ -20,7 +20,7 @@ struct initdata { struct bootdesc *bootdesc; - struct vm_file *memfile; + struct list_head boot_file_list; struct page_bitmap page_map; }; diff --git a/tasks/mm0/include/vm_area.h b/tasks/mm0/include/vm_area.h index f3a78ad..0a648e5 100644 --- a/tasks/mm0/include/vm_area.h +++ b/tasks/mm0/include/vm_area.h @@ -83,7 +83,7 @@ struct inode { struct vm_file { struct inode inode; unsigned long length; - + struct list_head list; /* List of all vm files in memory */ /* This is the cache of physical pages that this file has in memory. */ struct list_head page_cache_list; struct vm_pager *pager; diff --git a/tasks/mm0/src/init.c b/tasks/mm0/src/init.c index 76fa6b1..827dde8 100644 --- a/tasks/mm0/src/init.c +++ b/tasks/mm0/src/init.c @@ -4,6 +4,7 @@ * Copyright (C) 2007 Bahadir Balban */ #include +#include #include #include #include @@ -52,27 +53,28 @@ void init_mm(struct initdata *initdata) /* Create temporary run-time files in memory to test with mmap */ void init_boot_files(struct initdata *initdata) { - struct bootdesc *bd = initdata->bootdesc; - int total_files = bd->total_images; - struct vm_file *memfile; + struct vm_file *f; struct svc_image *img; + struct bootdesc *bd = initdata->bootdesc; - memfile = kzalloc(sizeof(struct vm_file) * total_files); - initdata->memfile = memfile; - BUG(); - for (int i = BOOTDESC_IMAGE_START; i < total_files; i++) { + INIT_LIST_HEAD(&initdata->boot_file_list); + for (int i = BOOTDESC_IMAGE_START; i < bd->total_images; i++) { img = &bd->images[i]; + if (!(!strcmp(img->name, "fs0") || !strcmp(img->name, "test0"))) + continue; /* Img is not what we want */ + + f = kzalloc(sizeof(*f)); + INIT_LIST_HEAD(&f->list); + INIT_LIST_HEAD(&f->page_cache_list); + list_add(&f->list, &initdata->boot_file_list); + /* - * I have left the i_addr as physical on purpose. The inode is - * not a readily usable memory address, its simply a unique key - * that represents that file. Here, we use the physical address - * of the memory file as that key. The pager must take action in - * order to make use of it. + * For boot files, we use the physical address of the memory + * file as its inode. */ - memfile[i].inode.i_addr = img->phys_start; - memfile[i].length = img->phys_end - img->phys_start; - memfile[i].pager = &default_file_pager; - INIT_LIST_HEAD(&memfile[i].page_cache_list); + f->inode.i_addr = img->phys_start; + f->length = img->phys_end - img->phys_start; + f->pager = &default_file_pager; } } diff --git a/tasks/mm0/src/task.c b/tasks/mm0/src/task.c index 6ef938f..5e6ad8e 100644 --- a/tasks/mm0/src/task.c +++ b/tasks/mm0/src/task.c @@ -52,38 +52,34 @@ void dump_tasks(void) #endif -void create_init_tcbs(struct initdata *initdata) +struct tcb *create_init_tcb(struct tcb_head *tcbs) { - struct bootdesc *bd = initdata->bootdesc; - INIT_LIST_HEAD(&tcb_head.list); - tcb_head.total++; + struct tcb *task = kzalloc(sizeof(struct tcb)); - for (int i = BOOTDESC_IMAGE_START; i < bd->total_images; i++) { - struct tcb *task = kzalloc(sizeof(struct tcb)); + /* Ids will be acquired from the kernel */ + task->tid = TASK_ID_INVALID; + task->spid = TASK_ID_INVALID; + task->swap_file = kzalloc(sizeof(struct vm_file)); + task->swap_file->pager = &swap_pager; + vaddr_pool_init(task->swap_file_offset_pool, 0, + __pfn(TASK_SWAPFILE_MAXSIZE)); + INIT_LIST_HEAD(&task->swap_file->page_cache_list); + INIT_LIST_HEAD(&task->list); + INIT_LIST_HEAD(&task->vm_area_list); + list_add_tail(&task->list, &tcbs->list); + tcbs->total++; - /* Ids will be acquired from the kernel */ - task->tid = TASK_ID_INVALID; - task->spid = TASK_ID_INVALID; - task->swap_file = kzalloc(sizeof(struct vm_file)); - task->swap_file->pager = &swap_pager; - vaddr_pool_init(task->swap_file_offset_pool, 0, - __pfn(TASK_SWAPFILE_MAXSIZE)); - INIT_LIST_HEAD(&task->swap_file->page_cache_list); - INIT_LIST_HEAD(&task->list); - INIT_LIST_HEAD(&task->vm_area_list); - list_add_tail(&task->list, &tcb_head.list); - - } + return task; } -int start_init_tasks(struct initdata *initdata) +int start_boot_tasks(struct initdata *initdata, struct tcb_head *tcbs) { - struct tcb *task; + struct vm_file *file; int err; - int i = BOOTDESC_IMAGE_START; - list_for_each_entry(task, &tcb_head.list, list) { - struct vm_file *file = &initdata->memfile[i++]; + INIT_LIST_HEAD(&tcb_head.list); + list_for_each_entry(file, &initdata->boot_file_list, list) { + struct tcb *task = create_init_tcb(tcbs); unsigned int sp = align(USER_AREA_END - 1, 8); unsigned int pc = USER_AREA_START; struct task_ids ids = { .tid = task->tid, .spid = task->spid }; @@ -132,7 +128,7 @@ int start_init_tasks(struct initdata *initdata) /* Start the thread */ if ((err = l4_thread_control(THREAD_RUN, &ids) < 0)) { - printf("l4_thread_control failed with %d\n"); + printf("l4_thread_control failed with %d\n", err); goto error; } } @@ -144,10 +140,14 @@ error: void init_pm(struct initdata *initdata) { - create_init_tcbs(initdata); - start_init_tasks(initdata); + start_boot_tasks(initdata, &tcb_head); } +/* + * During its initialisation FS0 wants to learn how many boot tasks + * are running, and their tids, which includes itself. This function + * provides that information. + */ void send_task_data(l4id_t requester) { struct tcb *t; diff --git a/tools/ksym_to_lds.py b/tools/ksym_to_lds.py index c15aecd..c4325cb 100755 --- a/tools/ksym_to_lds.py +++ b/tools/ksym_to_lds.py @@ -5,7 +5,7 @@ from string import atoi from os import popen2 from os.path import join -symbols = ['bkpt_phys_to_virt'] +symbols = ['break_virtual'] builddir = "build" loaderdir = "loader" image = "start.axf" diff --git a/tools/l4-qemu b/tools/l4-qemu index 45a940d..b8d09b5 100755 --- a/tools/l4-qemu +++ b/tools/l4-qemu @@ -1,7 +1,7 @@ cd build #arm-none-eabi-insight & -qemu-system-arm -S -kernel final.axf -nographic -s -M versatilepb & -sleep 0.5 +#/opt/bin/qemu-system-arm -s -kernel final.axf -nographic -m 128 -M versatilepb & +qemu-system-arm -s -kernel final.axf -nographic -m 128 -M versatilepb & arm-none-eabi-insight ; pkill qemu-system-arm #arm-none-eabi-gdb ; pkill qemu-system-arm cd ..