mirror of
https://github.com/drasko/codezero.git
synced 2026-01-31 04:03:13 +01:00
Towards finishing exchange_registers()
- Added mutex_trylock() - Implemented most of exchange_registers() - thread_control() now needs a lock for operations that can modify thread context. - thread_start() does not initialise scheduler flags, now done in thread_create. TODO: - Fork/clone'ed threads should retain their context in tcb, not syscall stack. - exchange_registers() calls in userspace need cleaning up.
This commit is contained in:
@@ -59,10 +59,10 @@ typedef int (*__l4_ipc_control_t)(unsigned int action, l4id_t blocked_sender,
|
||||
extern __l4_ipc_control_t __l4_ipc_control;
|
||||
int l4_ipc_control(unsigned int, l4id_t blocked_sender, u32 blocked_tag);
|
||||
|
||||
typedef int (*__l4_exchange_registers_t)(unsigned int pc, unsigned int sp,
|
||||
typedef int (*__l4_exchange_registers_t)(void *exregs_struct,
|
||||
l4id_t pager, l4id_t tid);
|
||||
extern __l4_exchange_registers_t __l4_exchange_registers;
|
||||
int l4_exchange_registers(unsigned int pc, unsigned int sp, int pager, l4id_t tid);
|
||||
int l4_exchange_registers(void *exregs_struct, l4id_t pager, l4id_t tid);
|
||||
|
||||
typedef int (*__l4_kmem_control_t)(unsigned long pfn, int npages, int grant);
|
||||
extern __l4_kmem_control_t __l4_kmem_control;
|
||||
|
||||
@@ -186,7 +186,7 @@ END_PROC(l4_space_control)
|
||||
|
||||
/*
|
||||
* Sets registers of a thread and its pager.
|
||||
* @r0 = pc to set, @r1 = sp to set @r2 = pager id, @r3 = tid of thread.
|
||||
* @r0 = ptr to exchange_registers structure, @r1 = pager id, @r2 = tid of thread.
|
||||
*/
|
||||
BEGIN_PROC(l4_exchange_registers)
|
||||
stmfd sp!, {lr}
|
||||
|
||||
22
tasks/mm0/include/exregs.h
Normal file
22
tasks/mm0/include/exregs.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef __MM0_EXREGS_H__
|
||||
#define __MM0_EXREGS_H__
|
||||
|
||||
#include <l4/api/exregs.h>
|
||||
|
||||
void exregs_set_stack(struct exregs_data *s, unsigned long sp);
|
||||
void exregs_set_mr_return(struct exregs_data *s, unsigned long retreg);
|
||||
void exregs_set_pc(struct exregs_data *s, unsigned long pc);
|
||||
|
||||
/*
|
||||
exregs_set_stack(unsigned long sp)
|
||||
exregs_set_pc(unsigned long pc)
|
||||
exregs_set_return(unsigned long retreg)
|
||||
exregs_set_arg0(unsigned long arg0)
|
||||
exregs_set_mr0(unsigned long mr0)
|
||||
exregs_set_mr_sender(unsigned long sender)
|
||||
exregs_set_mr_return(unsigned long retreg)
|
||||
exregs_set_all(unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3,
|
||||
unsigned long sp, unsigned long pc, u32 valid_vector, l4id_t pager);
|
||||
*/
|
||||
|
||||
#endif /* __MM0_EXREGS_H__ */
|
||||
@@ -168,7 +168,7 @@ int self_spawn(void)
|
||||
ids.tgid = self->tgid;
|
||||
|
||||
/* Create a new L4 thread in current thread's address space. */
|
||||
self_child = task_create(self, &ids, THREAD_CREATE_SAMESPC,
|
||||
self_child = task_create(self, &ids, THREAD_SAME_SPACE,
|
||||
TCB_SHARED_VM | TCB_SHARED_FILES);
|
||||
|
||||
if (IS_ERR(self_child = tcb_alloc_init(TCB_SHARED_VM
|
||||
|
||||
21
tasks/mm0/src/arch-arm/exregs.c
Normal file
21
tasks/mm0/src/arch-arm/exregs.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Generic to arch-specific interface for
|
||||
* exchange_registers()
|
||||
*
|
||||
* Copyright (C) 2008 Bahadir Balban
|
||||
*/
|
||||
#include <exregs.h>
|
||||
|
||||
|
||||
void exregs_set_stack(struct exregs_data *s, unsigned long sp)
|
||||
{
|
||||
s->context.sp = sp;
|
||||
s->valid_vect |= 1 << (offsetof(task_context_t, sp) >> 2);
|
||||
}
|
||||
|
||||
void exregs_set_pc(struct exregs_data *s, unsigned long pc)
|
||||
{
|
||||
s->context.pc = pc;
|
||||
s->valid_vect |= 1 << (offsetof(task_context_t, pc) >> 2);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ int do_fork(struct tcb *parent)
|
||||
* Create a new L4 thread with parent's page tables
|
||||
* kernel stack and kernel-side tcb copied
|
||||
*/
|
||||
if (IS_ERR(child = task_create(parent, &ids, THREAD_CREATE_COPYSPC,
|
||||
if (IS_ERR(child = task_create(parent, &ids, THREAD_COPY_SPACE,
|
||||
TCB_NO_SHARING))) {
|
||||
l4_ipc_return((int)child);
|
||||
return 0;
|
||||
@@ -121,7 +121,6 @@ int sys_clone(l4id_t sender, void *child_stack, unsigned int flags)
|
||||
struct task_ids ids;
|
||||
struct vm_file *utcb_shm;
|
||||
struct tcb *parent, *child;
|
||||
unsigned long stack, stack_size;
|
||||
|
||||
BUG_ON(!(parent = find_task(sender)));
|
||||
|
||||
@@ -129,7 +128,7 @@ int sys_clone(l4id_t sender, void *child_stack, unsigned int flags)
|
||||
ids.spid = parent->spid;
|
||||
ids.tgid = parent->tgid;
|
||||
|
||||
if (IS_ERR(child = task_create(parent, &ids, THREAD_CREATE_SAMESPC,
|
||||
if (IS_ERR(child = task_create(parent, &ids, THREAD_SAME_SPACE,
|
||||
TCB_SHARED_VM | TCB_SHARED_FILES))) {
|
||||
l4_ipc_return((int)child);
|
||||
return 0;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <task.h>
|
||||
#include <shm.h>
|
||||
#include <mmap.h>
|
||||
#include <exregs.h>
|
||||
|
||||
struct tcb_head {
|
||||
struct list_head list;
|
||||
@@ -303,6 +304,7 @@ int task_setup_registers(struct tcb *task, unsigned int pc,
|
||||
unsigned int sp, l4id_t pager)
|
||||
{
|
||||
int err;
|
||||
struct exregs_data regs;
|
||||
|
||||
/* Set up task's registers to default. */
|
||||
if (!sp)
|
||||
@@ -313,7 +315,9 @@ int task_setup_registers(struct tcb *task, unsigned int pc,
|
||||
pager = self_tid();
|
||||
|
||||
/* Set up the task's thread details, (pc, sp, pager etc.) */
|
||||
if ((err = l4_exchange_registers(pc, sp, pager, task->tid) < 0)) {
|
||||
exregs_set_stack(®s, sp);
|
||||
exregs_set_pc(®s, pc);
|
||||
if ((err = l4_exchange_registers(®s, pager, task->tid) < 0)) {
|
||||
printf("l4_exchange_registers failed with %d.\n", err);
|
||||
return err;
|
||||
}
|
||||
@@ -367,7 +371,7 @@ int task_exec(struct vm_file *f, unsigned long task_region_start,
|
||||
struct tcb *task;
|
||||
int err;
|
||||
|
||||
if (IS_ERR(task = task_create(0, ids, THREAD_CREATE_NEWSPC,
|
||||
if (IS_ERR(task = task_create(0, ids, THREAD_NEW_SPACE,
|
||||
TCB_NO_SHARING)))
|
||||
return (int)task;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user