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
This commit is contained in:
Bahadir Balban
2008-03-19 02:27:53 +00:00
parent ac3935a5d9
commit 16617eed36
16 changed files with 93 additions and 71 deletions

View File

@@ -161,7 +161,7 @@ int setvbuf(FILE *, char *, int, size_t);
/* 7.19.6 Format i/o functions */ /* 7.19.6 Format i/o functions */
int fprintf(FILE *, const char *, ...); int fprintf(FILE *, const char *, ...);
int fscanf(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 scanf(const char *, ...);
int snprintf(char *, size_t , const char *, ...); int snprintf(char *, size_t , const char *, ...);
int sprintf(char *, const char *, ...); int sprintf(char *, const char *, ...);

View File

@@ -8,6 +8,7 @@
#include <l4/generic/tcb.h> #include <l4/generic/tcb.h>
#include <l4/lib/printk.h> #include <l4/lib/printk.h>
#include <l4/api/ipc.h> #include <l4/api/ipc.h>
#include <l4/api/kip.h>
#include <l4/api/errno.h> #include <l4/api/errno.h>
#include INC_PLAT(printascii.h) #include INC_PLAT(printascii.h)
#include INC_ARCH(exception.h) #include INC_ARCH(exception.h)
@@ -17,7 +18,7 @@
#include INC_SUBARCH(mm.h) #include INC_SUBARCH(mm.h)
/* Abort debugging conditions */ /* Abort debugging conditions */
// #define DEBUG_ABORTS //#define DEBUG_ABORTS
#if defined (DEBUG_ABORTS) #if defined (DEBUG_ABORTS)
#define dbg_abort(...) dprintk(__VA_ARGS__) #define dbg_abort(...) dprintk(__VA_ARGS__)
#else #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) void data_abort_handler(u32 faulted_pc, u32 fsr, u32 far)
{ {
set_abort_type(fsr, ARM_DABT); 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); dbg_abort("Data abort @ PC: ", faulted_pc);
/* Check for more details */
if (check_aborts(faulted_pc, fsr, far) < 0) { if (check_aborts(faulted_pc, fsr, far) < 0) {
printascii("This abort can't be handled by any pager.\n"); printascii("This abort can't be handled by any pager.\n");
goto error; goto error;

View File

@@ -182,10 +182,10 @@ void kip_init()
kip_init_syscalls(); 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); 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; *utcb_ref = (struct utcb *)UTCB_AREA_START;
add_mapping(virt_to_phys(&kip), USER_KIP_PAGE, PAGE_SIZE, add_mapping(virt_to_phys(&kip), USER_KIP_PAGE, PAGE_SIZE,

View File

@@ -79,14 +79,11 @@ struct task_data_head {
struct task_data tdata[]; 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) struct task_data_head *receive_pager_taskdata(void)
{ {
int err; int err;
/* Ask pager to write the data at this address */
write_mr(L4SYS_ARG0, (unsigned long)utcb->buf);
/* Make the actual ipc call */ /* Make the actual ipc call */
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, if ((err = l4_sendrecv(PAGER_TID, PAGER_TID,
L4_IPC_TAG_TASKDATA)) < 0) { L4_IPC_TAG_TASKDATA)) < 0) {
@@ -100,10 +97,11 @@ struct task_data_head *receive_pager_taskdata(void)
return PTR_ERR(err); return PTR_ERR(err);
} }
/* Data is expected in the utcb page */
printf("%s: %d Total tasks.\n", __FUNCTION__, 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 */ /* Allocate a task struct and initialise it */

View File

@@ -23,8 +23,10 @@
struct utcb { struct utcb {
u32 mr[MR_TOTAL]; u32 mr[MR_TOTAL];
u32 tid; /* Thread id */ u32 tid; /* Thread id */
}; __attribute__((__packed__)); } __attribute__((__packed__));
extern struct utcb utcb; extern struct utcb utcb;
extern void *utcb_page;
static inline struct utcb *l4_get_utcb() static inline struct utcb *l4_get_utcb()
{ {

View File

@@ -9,7 +9,6 @@
.macro utcb_address rx .macro utcb_address rx
ldr \rx, =utcb ldr \rx, =utcb
ldr \rx, [\rx]
.endm .endm
BEGIN_PROC(l4_thread_switch) BEGIN_PROC(l4_thread_switch)

View File

@@ -1,7 +1,7 @@
/* /*
* Initialise system call offsets. * Initialise system call offsets.
* *
* Copyright (C) 2007 Bahadir Balban * Copyright (C) 2007, 2008 Bahadir Balban
*/ */
#include <l4lib/kip.h> #include <l4lib/kip.h>
#include <l4lib/arch/syslib.h> #include <l4lib/arch/syslib.h>
@@ -52,6 +52,9 @@ static void *l4_utcb_page(void)
void *addr; void *addr;
int err; int err;
/* We're asking it for ourself. */
write_mr(L4SYS_ARG0, self_tid());
/* Call pager with utcb address request. Check ipc error. */ /* Call pager with utcb address request. Check ipc error. */
if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_UTCB)) < 0) { if ((err = l4_sendrecv(PAGER_TID, PAGER_TID, L4_IPC_TAG_UTCB)) < 0) {
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); 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 */ /* Initialise utcb only if we're not the pager */
if (self_tid() != PAGER_TID) { if (self_tid() != PAGER_TID) {
utcb_page = l4_utcb_page(); 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); (unsigned long)utcb_page);
} }
} }

View File

@@ -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

View File

@@ -13,6 +13,7 @@
#include <l4lib/arch/syscalls.h> #include <l4lib/arch/syscalls.h>
#include <l4lib/arch/syslib.h> #include <l4lib/arch/syslib.h>
#include <l4lib/ipcdefs.h> #include <l4lib/ipcdefs.h>
#include <l4lib/utcb.h>
#include <fcntl.h> #include <fcntl.h>
#include <l4/macros.h> #include <l4/macros.h>
#include INC_GLUE(memory.h) #include INC_GLUE(memory.h)
@@ -25,7 +26,7 @@
void *copy_to_utcb(void *arg, int size) void *copy_to_utcb(void *arg, int size)
{ {
BUG_ON(size > PAGE_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) static inline int l4_open(const char *pathname, int flags, mode_t mode)

View File

@@ -1,7 +1,12 @@
#ifndef __MM0_UTCB_H__ #ifndef __MM0_UTCB_H__
#define __MM0_UTCB_H__ #define __MM0_UTCB_H__
#include <l4lib/types.h>
void *utcb_vaddr_new(void); void *utcb_vaddr_new(void);
int utcb_pool_init(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 #endif

View File

@@ -14,7 +14,7 @@
#include <arch/mm.h> #include <arch/mm.h>
#include <lib/spinlock.h> #include <lib/spinlock.h>
// #define DEBUG_FAULT_HANDLING //#define DEBUG_FAULT_HANDLING
#ifdef DEBUG_FAULT_HANDLING #ifdef DEBUG_FAULT_HANDLING
#define dprintf(...) printf(__VA_ARGS__) #define dprintf(...) printf(__VA_ARGS__)
#else #else

View File

@@ -18,7 +18,7 @@
#include <syscalls.h> #include <syscalls.h>
#include <file.h> #include <file.h>
#include <shm.h> #include <shm.h>
#include <task.h> #include <utcb.h>
void handle_requests(void) void handle_requests(void)
{ {
@@ -84,6 +84,10 @@ void handle_requests(void)
(unsigned long)mr[2], (unsigned long)mr[3]); (unsigned long)mr[2], (unsigned long)mr[3]);
break; break;
case L4_IPC_TAG_UTCB:
task_send_utcb_address(sender, (l4id_t)mr[0]);
break;
case L4_IPC_TAG_READ: case L4_IPC_TAG_READ:
sys_read(sender, (int)mr[0], (void *)mr[1], (int)mr[2]); sys_read(sender, (int)mr[0], (void *)mr[1], (int)mr[2]);
break; break;

View File

@@ -20,21 +20,22 @@
/* /*
* Initialise the utcb virtual address pool and its own utcb. * Initialise the utcb virtual address pool and its own utcb.
* NOTE: This allocates memory so kmalloc must be initialised first. * 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 */ /* Allocate and map one for self */
if (utcb_pool_init() < 0) if (utcb_pool_init() < 0)
printf("UTCB initialisation failed.\n"); printf("UTCB initialisation failed.\n");
utcb_virt = utcb_vaddr_new(); utcb_virt = utcb_vaddr_new();
printf("%s: Mapping 0x%x as utcb to self.\n", __TASKNAME__, utcb_virt); printf("%s: Mapping 0x%x as utcb to self.\n", __TASKNAME__, utcb_virt);
utcb_page = alloc_page(1); utcb_phys = alloc_page(1);
l4_map(utcb_page, utcb_virt, 1, MAP_USR_RW_FLAGS, self_tid()); l4_map(utcb_phys, utcb_virt, 1, MAP_USR_RW_FLAGS, self_tid());
/* Also initialise the utcb reference that is inside l4lib. */ /* Initialise the utcb page that is inside l4lib. */
utcb = utcb_virt; utcb_page = utcb_virt;
} }
void init_mm(struct initdata *initdata) void init_mm(struct initdata *initdata)
@@ -62,8 +63,8 @@ void init_mm(struct initdata *initdata)
shm_init(); shm_init();
printf("%s: Initialised shm structures.\n", __TASKNAME__); printf("%s: Initialised shm structures.\n", __TASKNAME__);
init_utcb(); init_utcb_page();
printf("%s: Initialised own utcb.\n", __TASKNAME__); printf("%s: Initialised mm0 utcb page.\n", __TASKNAME__);
/* Give the kernel some memory to use for its allocators */ /* Give the kernel some memory to use for its allocators */
l4_kmem_grant(__pfn(alloc_page(__pfn(SZ_1MB))), __pfn(SZ_1MB)); l4_kmem_grant(__pfn(alloc_page(__pfn(SZ_1MB))), __pfn(SZ_1MB));

View File

@@ -218,9 +218,6 @@ int start_boot_task(struct vm_file *file, struct task_ids *ids)
task->tid = ids->tid; task->tid = ids->tid;
task->spid = ids->spid; task->spid = ids->spid;
/* Allocate a utcb virtual address */
task->utcb_address = (unsigned long)utcb_vaddr_new();
/* Prepare environment boundaries. */ /* Prepare environment boundaries. */
task->env_end = USER_AREA_END; task->env_end = USER_AREA_END;
task->env_start = task->env_end - DEFAULT_ENV_SIZE; 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; 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 */ /* Add the task to the global task list */
list_add(&task->list, &tcb_head.list); list_add(&task->list, &tcb_head.list);
tcb_head.total++; tcb_head.total++;
@@ -440,7 +427,6 @@ void send_task_data(l4id_t requester)
{ {
int li, err; int li, err;
struct tcb *t, *vfs; struct tcb *t, *vfs;
struct utcb *vfs_utcb;
struct task_data_head *tdata_head; struct task_data_head *tdata_head;
if (requester != VFS_TID) { if (requester != VFS_TID) {
@@ -451,16 +437,14 @@ void send_task_data(l4id_t requester)
} }
BUG_ON(!(vfs = find_task(requester))); BUG_ON(!(vfs = find_task(requester)));
BUG_ON(!vfs->utcb_address);
/* Map in vfs's utcb. FIXME: Whatif it is already mapped? */ /* 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)), 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()); (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 */ /* 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 */ /* First word is total number of tcbs */
tdata_head->total = tcb_head.total; tdata_head->total = tcb_head.total;

View File

@@ -8,6 +8,9 @@
#include <utcb.h> #include <utcb.h>
#include <lib/addr.h> #include <lib/addr.h>
#include <l4/macros.h> #include <l4/macros.h>
#include <l4lib/arch/syscalls.h>
#include <l4lib/arch/syslib.h>
#include <task.h>
#include INC_GLUE(memlayout.h) #include INC_GLUE(memlayout.h)
static struct address_pool utcb_vaddr_pool; static struct address_pool utcb_vaddr_pool;
@@ -29,4 +32,45 @@ void *utcb_vaddr_new(void)
return address_new(&utcb_vaddr_pool, 1); 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;
}

View File

@@ -8,14 +8,6 @@
#include <l4/api/errno.h> #include <l4/api/errno.h>
#include <kmalloc/kmalloc.h> #include <kmalloc/kmalloc.h>
// #define DEBUG_FAULT_HANDLING
#ifdef DEBUG_FAULT_HANDLING
#define dprintf(...) printf(__VA_ARGS__)
#else
#define dprintf(...)
#endif
#if defined(DEBUG_FAULT_HANDLING) #if defined(DEBUG_FAULT_HANDLING)
void print_cache_pages(struct vm_object *vmo) void print_cache_pages(struct vm_object *vmo)
{ {