From 16617eed36a4e83717bf2d0921cb46d4773caacd Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Wed, 19 Mar 2008 02:27:53 +0000 Subject: [PATCH] Various changes to incorporate new utcb setup. Issues with l4_return value not reaching client side modified: libs/c/include/stdio.h modified: src/arch/arm/exception.c modified: src/glue/arm/init.c modified: tasks/fs0/src/task.c modified: tasks/libl4/include/l4lib/arch-arm/utcb.h modified: tasks/libl4/src/arm/syscalls.S modified: tasks/libl4/src/init.c deleted: tasks/libl4/tagfilelist modified: tasks/libposix/open.c modified: tasks/mm0/include/utcb.h modified: tasks/mm0/include/vm_area.h modified: tasks/mm0/main.c modified: tasks/mm0/src/init.c modified: tasks/mm0/src/task.c modified: tasks/mm0/src/utcb.c modified: tasks/mm0/src/vm_object.c --- libs/c/include/stdio.h | 2 +- src/arch/arm/exception.c | 11 +++++- src/glue/arm/init.c | 4 +-- tasks/fs0/src/task.c | 10 +++--- tasks/libl4/include/l4lib/arch-arm/utcb.h | 4 ++- tasks/libl4/src/arm/syscalls.S | 1 - tasks/libl4/src/init.c | 7 ++-- tasks/libl4/tagfilelist | 20 ----------- tasks/libposix/open.c | 3 +- tasks/mm0/include/utcb.h | 5 +++ tasks/mm0/include/vm_area.h | 2 +- tasks/mm0/main.c | 6 +++- tasks/mm0/src/init.c | 17 ++++----- tasks/mm0/src/task.c | 20 ++--------- tasks/mm0/src/utcb.c | 44 +++++++++++++++++++++++ tasks/mm0/src/vm_object.c | 8 ----- 16 files changed, 93 insertions(+), 71 deletions(-) delete mode 100644 tasks/libl4/tagfilelist diff --git a/libs/c/include/stdio.h b/libs/c/include/stdio.h index 1bf4ff1..374a87f 100644 --- a/libs/c/include/stdio.h +++ b/libs/c/include/stdio.h @@ -161,7 +161,7 @@ int setvbuf(FILE *, char *, int, size_t); /* 7.19.6 Format i/o functions */ int fprintf(FILE *, const char *, ...); int fscanf(FILE *, const char *, ...); -int printf(const char *format, ...); __attribute__((format (printf, 1, 2))); +int printf(const char *format, ...) __attribute__((format (printf, 1, 2))); int scanf(const char *, ...); int snprintf(char *, size_t , const char *, ...); int sprintf(char *, const char *, ...); diff --git a/src/arch/arm/exception.c b/src/arch/arm/exception.c index 76ec162..3c80ddc 100644 --- a/src/arch/arm/exception.c +++ b/src/arch/arm/exception.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include INC_PLAT(printascii.h) #include INC_ARCH(exception.h) @@ -17,7 +18,7 @@ #include INC_SUBARCH(mm.h) /* Abort debugging conditions */ -// #define DEBUG_ABORTS +//#define DEBUG_ABORTS #if defined (DEBUG_ABORTS) #define dbg_abort(...) dprintk(__VA_ARGS__) #else @@ -180,7 +181,15 @@ int check_aborts(u32 faulted_pc, u32 fsr, u32 far) void data_abort_handler(u32 faulted_pc, u32 fsr, u32 far) { set_abort_type(fsr, ARM_DABT); + + /* + * FIXME: Find why if we use a clause like if tid == PAGER_TID + * this prints just the faulted_pc but not the text "Data abort @ PC:" + * Strange. + */ dbg_abort("Data abort @ PC: ", faulted_pc); + + /* Check for more details */ if (check_aborts(faulted_pc, fsr, far) < 0) { printascii("This abort can't be handled by any pager.\n"); goto error; diff --git a/src/glue/arm/init.c b/src/glue/arm/init.c index 7dac98a..4088a7d 100644 --- a/src/glue/arm/init.c +++ b/src/glue/arm/init.c @@ -182,10 +182,10 @@ void kip_init() kip_init_syscalls(); - /* KIP + 0xFF0 is pointer to UTCB area for this thread group. */ + /* KIP + 0xFF0 is pointer to UTCB segment start address */ utcb_ref = (struct utcb **)((unsigned long)&kip + UTCB_KIP_OFFSET); - /* All thread groups have their utcb mapped at UTCB_AREA_START */ + /* All thread utcbs are allocated starting from UTCB_AREA_START */ *utcb_ref = (struct utcb *)UTCB_AREA_START; add_mapping(virt_to_phys(&kip), USER_KIP_PAGE, PAGE_SIZE, diff --git a/tasks/fs0/src/task.c b/tasks/fs0/src/task.c index fc46857..f3564de 100644 --- a/tasks/fs0/src/task.c +++ b/tasks/fs0/src/task.c @@ -79,14 +79,11 @@ struct task_data_head { struct task_data tdata[]; }; -/* Read task information into the utcb buffer, since it wont fit into mrs. */ +/* Read task information into the utcb page, since it won't fit into mrs. */ struct task_data_head *receive_pager_taskdata(void) { int err; - /* Ask pager to write the data at this address */ - write_mr(L4SYS_ARG0, (unsigned long)utcb->buf); - /* Make the actual ipc call */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_TASKDATA)) < 0) { @@ -100,10 +97,11 @@ struct task_data_head *receive_pager_taskdata(void) return PTR_ERR(err); } + /* Data is expected in the utcb page */ printf("%s: %d Total tasks.\n", __FUNCTION__, - ((struct task_data_head *)utcb->buf)->total); + ((struct task_data_head *)utcb_page)->total); - return (struct task_data_head *)utcb->buf; + return (struct task_data_head *)utcb_page; } /* Allocate a task struct and initialise it */ diff --git a/tasks/libl4/include/l4lib/arch-arm/utcb.h b/tasks/libl4/include/l4lib/arch-arm/utcb.h index 75ecdf6..9f76700 100644 --- a/tasks/libl4/include/l4lib/arch-arm/utcb.h +++ b/tasks/libl4/include/l4lib/arch-arm/utcb.h @@ -23,8 +23,10 @@ struct utcb { u32 mr[MR_TOTAL]; u32 tid; /* Thread id */ -}; __attribute__((__packed__)); +} __attribute__((__packed__)); + extern struct utcb utcb; +extern void *utcb_page; static inline struct utcb *l4_get_utcb() { diff --git a/tasks/libl4/src/arm/syscalls.S b/tasks/libl4/src/arm/syscalls.S index 911e649..cd289c3 100644 --- a/tasks/libl4/src/arm/syscalls.S +++ b/tasks/libl4/src/arm/syscalls.S @@ -9,7 +9,6 @@ .macro utcb_address rx ldr \rx, =utcb - ldr \rx, [\rx] .endm BEGIN_PROC(l4_thread_switch) diff --git a/tasks/libl4/src/init.c b/tasks/libl4/src/init.c index 1479b75..bf1a9e4 100644 --- a/tasks/libl4/src/init.c +++ b/tasks/libl4/src/init.c @@ -1,7 +1,7 @@ /* * Initialise system call offsets. * - * Copyright (C) 2007 Bahadir Balban + * Copyright (C) 2007, 2008 Bahadir Balban */ #include #include @@ -52,6 +52,9 @@ static void *l4_utcb_page(void) void *addr; int err; + /* We're asking it for ourself. */ + write_mr(L4SYS_ARG0, self_tid()); + /* Call pager with utcb address request. Check ipc error. */ if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_UTCB)) < 0) { printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); @@ -89,7 +92,7 @@ void __l4_init(void) /* Initialise utcb only if we're not the pager */ if (self_tid() != PAGER_TID) { utcb_page = l4_utcb_page(); - printf("UTCB Read from mm0 as: 0x%x\n", + printf("%s: UTCB Read from mm0 as: 0x%x\n", __FUNCTION__, (unsigned long)utcb_page); } } diff --git a/tasks/libl4/tagfilelist b/tasks/libl4/tagfilelist deleted file mode 100644 index 402e71e..0000000 --- a/tasks/libl4/tagfilelist +++ /dev/null @@ -1,20 +0,0 @@ -./src/init.c -./include/l4lib/kip.h -./include/l4lib/posix/l4shm.h -./include/l4lib/arch-arm/asm.h -./include/l4lib/arch-arm/types.h -./include/l4lib/arch-arm/utcb.h -./include/l4lib/arch-arm/syscalls.h -./include/l4lib/arch-arm/message.h -./include/l4lib/arch-arm/vregs.h -./include/l4lib/types.h -./include/l4lib/ipcdefs.h -./include/l4lib/utcb.h -./include/l4lib/examples/ipc.h -./include/l4lib/examples/message_stuff.h -./include/l4lib/examples/space.h -./include/l4lib/examples/thread.h -./include/l4lib/examples/syscalls.h -./include/l4lib/examples/message.h -./include/l4lib/examples/schedule.h -./src/arm/syscalls.S diff --git a/tasks/libposix/open.c b/tasks/libposix/open.c index 1833b36..cda8418 100644 --- a/tasks/libposix/open.c +++ b/tasks/libposix/open.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include INC_GLUE(memory.h) @@ -25,7 +26,7 @@ void *copy_to_utcb(void *arg, int size) { BUG_ON(size > PAGE_SIZE); - memcpy(utcb->buf, arg, size); + memcpy(utcb_page, arg, size); } static inline int l4_open(const char *pathname, int flags, mode_t mode) diff --git a/tasks/mm0/include/utcb.h b/tasks/mm0/include/utcb.h index 677b6ff..f1fe69a 100644 --- a/tasks/mm0/include/utcb.h +++ b/tasks/mm0/include/utcb.h @@ -1,7 +1,12 @@ #ifndef __MM0_UTCB_H__ #define __MM0_UTCB_H__ +#include void *utcb_vaddr_new(void); int utcb_pool_init(void); + +/* IPC to send utcb address information to tasks */ +int task_send_utcb_address(l4id_t sender, l4id_t taskid); + #endif diff --git a/tasks/mm0/include/vm_area.h b/tasks/mm0/include/vm_area.h index 203436b..137753a 100644 --- a/tasks/mm0/include/vm_area.h +++ b/tasks/mm0/include/vm_area.h @@ -14,7 +14,7 @@ #include #include -// #define DEBUG_FAULT_HANDLING +//#define DEBUG_FAULT_HANDLING #ifdef DEBUG_FAULT_HANDLING #define dprintf(...) printf(__VA_ARGS__) #else diff --git a/tasks/mm0/main.c b/tasks/mm0/main.c index ab7b8e8..00bde4f 100644 --- a/tasks/mm0/main.c +++ b/tasks/mm0/main.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include void handle_requests(void) { @@ -84,6 +84,10 @@ void handle_requests(void) (unsigned long)mr[2], (unsigned long)mr[3]); break; + case L4_IPC_TAG_UTCB: + task_send_utcb_address(sender, (l4id_t)mr[0]); + break; + case L4_IPC_TAG_READ: sys_read(sender, (int)mr[0], (void *)mr[1], (int)mr[2]); break; diff --git a/tasks/mm0/src/init.c b/tasks/mm0/src/init.c index 2e53c02..f7853a0 100644 --- a/tasks/mm0/src/init.c +++ b/tasks/mm0/src/init.c @@ -20,21 +20,22 @@ /* * Initialise the utcb virtual address pool and its own utcb. * NOTE: This allocates memory so kmalloc must be initialised first. + * FIXME: Is this necessary anymore??? Who maps mm0's page to share? */ -void init_utcb(void) +void init_utcb_page(void) { - void *utcb_virt, *utcb_page; + void *utcb_virt, *utcb_phys; /* Allocate and map one for self */ if (utcb_pool_init() < 0) printf("UTCB initialisation failed.\n"); utcb_virt = utcb_vaddr_new(); printf("%s: Mapping 0x%x as utcb to self.\n", __TASKNAME__, utcb_virt); - utcb_page = alloc_page(1); - l4_map(utcb_page, utcb_virt, 1, MAP_USR_RW_FLAGS, self_tid()); + utcb_phys = alloc_page(1); + l4_map(utcb_phys, utcb_virt, 1, MAP_USR_RW_FLAGS, self_tid()); - /* Also initialise the utcb reference that is inside l4lib. */ - utcb = utcb_virt; + /* Initialise the utcb page that is inside l4lib. */ + utcb_page = utcb_virt; } void init_mm(struct initdata *initdata) @@ -62,8 +63,8 @@ void init_mm(struct initdata *initdata) shm_init(); printf("%s: Initialised shm structures.\n", __TASKNAME__); - init_utcb(); - printf("%s: Initialised own utcb.\n", __TASKNAME__); + init_utcb_page(); + printf("%s: Initialised mm0 utcb page.\n", __TASKNAME__); /* Give the kernel some memory to use for its allocators */ l4_kmem_grant(__pfn(alloc_page(__pfn(SZ_1MB))), __pfn(SZ_1MB)); diff --git a/tasks/mm0/src/task.c b/tasks/mm0/src/task.c index fc43a8d..8569bbd 100644 --- a/tasks/mm0/src/task.c +++ b/tasks/mm0/src/task.c @@ -218,9 +218,6 @@ int start_boot_task(struct vm_file *file, struct task_ids *ids) task->tid = ids->tid; task->spid = ids->spid; - /* Allocate a utcb virtual address */ - task->utcb_address = (unsigned long)utcb_vaddr_new(); - /* Prepare environment boundaries. */ task->env_end = USER_AREA_END; task->env_start = task->env_end - DEFAULT_ENV_SIZE; @@ -280,16 +277,6 @@ int start_boot_task(struct vm_file *file, struct task_ids *ids) goto error; } - /* mmap each task's utcb as single page anonymous memory. */ - printf("%s: Mapping utcb for new task at: 0x%x\n", __TASKNAME__, - task->utcb_address); - if ((err = do_mmap(0, 0, task, task->utcb_address, - VM_READ | VM_WRITE | VMA_SHARED | VMA_ANONYMOUS, - __pfn(DEFAULT_UTCB_SIZE))) < 0) { - printf("do_mmap: Mapping utcb failed with %d.\n", err); - goto error; - } - /* Add the task to the global task list */ list_add(&task->list, &tcb_head.list); tcb_head.total++; @@ -440,7 +427,6 @@ void send_task_data(l4id_t requester) { int li, err; struct tcb *t, *vfs; - struct utcb *vfs_utcb; struct task_data_head *tdata_head; if (requester != VFS_TID) { @@ -451,16 +437,14 @@ void send_task_data(l4id_t requester) } BUG_ON(!(vfs = find_task(requester))); + BUG_ON(!vfs->utcb_address); /* Map in vfs's utcb. FIXME: Whatif it is already mapped? */ l4_map((void *)page_to_phys(task_virt_to_page(vfs, vfs->utcb_address)), (void *)vfs->utcb_address, 1, MAP_USR_RW_FLAGS, self_tid()); - /* Get a handle on vfs utcb */ - vfs_utcb = (struct utcb *)vfs->utcb_address; - /* Write all requested task information to utcb's user buffer area */ - tdata_head = (struct task_data_head *)vfs_utcb->buf; + tdata_head = (struct task_data_head *)vfs->utcb_address; /* First word is total number of tcbs */ tdata_head->total = tcb_head.total; diff --git a/tasks/mm0/src/utcb.c b/tasks/mm0/src/utcb.c index e70a3ad..05dd65f 100644 --- a/tasks/mm0/src/utcb.c +++ b/tasks/mm0/src/utcb.c @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include INC_GLUE(memlayout.h) static struct address_pool utcb_vaddr_pool; @@ -29,4 +32,45 @@ void *utcb_vaddr_new(void) return address_new(&utcb_vaddr_pool, 1); } +/* + * Sends utcb address information to requester task, allocates + * an address if it doesn't exist and the requester is asking + * for its own. + */ +int task_send_utcb_address(l4id_t sender, l4id_t taskid) +{ + struct tcb *task = find_task(taskid); + + /* Is the task asking for its own utcb address */ + if (sender == taskid) { + /* + * It hasn't got one allocated. We allocate one here, + * but only because the requester is requesting for its + * own utcb. + */ + if (!task->utcb_address) + task->utcb_address = (unsigned long)utcb_vaddr_new(); + + /* Return it to requester */ + printf("%s: Returning 0x%x\n", __FUNCTION__, task->utcb_address); + return l4_ipc_return(task->utcb_address); + + /* A task is asking for someone else's utcb */ + } else { + /* Only vfs is allowed to do so yet, because its a server */ + if (sender == VFS_TID) { + /* + * Return utcb address to requester. Note if there's + * none allocated so far, requester gets 0. We don't + * allocate one here. + */ + printf("%s: Returning 0x%x\n", __FUNCTION__, + task->utcb_address); + return l4_ipc_return(task->utcb_address); + } + } + return 0; +} + + diff --git a/tasks/mm0/src/vm_object.c b/tasks/mm0/src/vm_object.c index fa442db..47af0e9 100644 --- a/tasks/mm0/src/vm_object.c +++ b/tasks/mm0/src/vm_object.c @@ -8,14 +8,6 @@ #include #include - -// #define DEBUG_FAULT_HANDLING -#ifdef DEBUG_FAULT_HANDLING -#define dprintf(...) printf(__VA_ARGS__) -#else -#define dprintf(...) -#endif - #if defined(DEBUG_FAULT_HANDLING) void print_cache_pages(struct vm_object *vmo) {