here is my latest source codes.
unfortunately i got this new error:

KERNEL: nothing mapped: (Mem_space) from [4]: 00005000 size: 00001000 to [5]

#include <l4/sys/types.h>
#include <l4/sys/syscalls.h>
#include <l4/sys/ipc.h>
#include <l4/rmgr/librmgr.h>
#include <l4/sigma0/sigma0.h> 

#include <stdio.h>

#define STACK_SIZE    4096
char stack001[STACK_SIZE];
char stack002[STACK_SIZE];

static void new_task_fn(void)
{
    l4_threadid_t cur_id = l4_myself();
    enter_kdebug("new_task_fn\n");
    while(1)
    {       
        printf("Currently running in task id: %d, thread no: %d\n", cur_id.id.task, cur_id.id.lthread);
    }
}

static void page_handler(void)
{
    int res;
    l4_timeout_t timeout = L4_IPC_NEVER;
    l4_msgdope_t result;
   
    /*int i = 0;
    while(1) {
        printf("page_handler, taskno: %d, thread id: %d\n", l4_myself().id.task, l4_myself().id.lthread);
        if (i%10 == 0) {
            //l4_thread_switch(new_task);
            l4_threadid_t switch_tid = l4_myself();
            switch_tid.id.lthread -= 1;
            l4_thread_switch(switch_tid);
            enter_kdebug("i/10\n");
        }
        i++;
    }*/
    l4_addr_t map_area = 0x60000000;
    l4_addr_t base;
    l4_umword_t rcv_fpage;
    l4_umword_t snd_fpage;

    res = l4_ipc_call(SIGMA0_ID,                    // thread id
                            L4_IPC_SHORT_MSG,         // send descriptor
                            SIGMA0_REQ_FPAGE_ANY,    // snd_dword0
                            snd_fpage,                    // snd_dword1
                            L4_IPC_MAPMSG(map_area, L4_WHOLE_ADDRESS_SPACE),// rcv_desc
                            base,                            // *rcv_dword0
                            &rcv_fpage,                    // *rcv_dword1
                            timeout,
                            &result);
   
    if (res) {
        printf("Error in ipc_call, mapping, err no: %d\n", res);
        enter_kdebug("Error in ipc_call\n");
    } else {
        enter_kdebug("successfully map fpage\n");
    }

    l4_threadid_t src_id;        // a faulting thread
    l4_umword_t rcv_dword0;     //    the faulting address
    l4_umword_t rcv_dword1;        //    the faulting eip
       
    res =    l4_ipc_wait(&src_id, L4_IPC_SHORT_MSG,
                            &rcv_dword0, &rcv_dword1,
                            timeout, &result);

    enter_kdebug("Page handler handle faulting thread\n");

    if (res) { //res == 0 ? SUCCESS : FAILED
        printf("Error occurs in l4_ipc_wait: %d\n", res);
        enter_kdebug("FAILED in l4_ipc_wait: %d\n");
    }   

    l4_umword_t fault_addr = rcv_dword0 &~ 0x00000003; //rcv_dword0 & 0xFFFFFFFC
                                                                        // mask lower bits for (write/grant) flags?
    l4_umword_t rw_addr    = fault_addr | 0x00000002;        // mask the 2 nd lower bits to set write flags

    while(1) {

        l4_snd_fpage_t fpage;
       
        fpage.snd_base = rw_addr; // do wee need to left shift the address???
       
        //we can also use the function l4_fpage(address, size, write, grant)
        fpage.fpage.fp.grant = 0;
        fpage.fpage.fp.write = 1;
        fpage.fpage.fp.page = rw_addr;
        fpage.fpage.fp.size =  L4_LOG2_PAGESIZE; //12

        res = l4_ipc_reply_and_wait(src_id,                    //dest_id
                                            L4_IPC_SHORT_FPAGE,    //send descriptor
                                            fpage.snd_base,        //snd_dword0
                                            fpage.fpage.fpage,    //snd_dword1 - might change later to .fp
                                            &src_id,                    //src_id
                                            L4_IPC_SHORT_MSG,        //rcv descriptor
                                            &rcv_dword0,            //rcv_dword0
                                            &rcv_dword1,            //rcv_dword1
                                            L4_IPC_NEVER,            //timeout
                                            &result);                //result

        if(res) {//res == 0 ? SUCCESS : FAILED
            printf("FAILED in reply wait: %d\n", res);
            enter_kdebug("FAILED in reply wait\n");
        }
    }       
}

int main(void)
{
    // 1st thread
    l4_threadid_t first_tid;
    l4_umword_t first_eip, first_esp;
    l4_threadid_t preempter, pager_tid;
    l4_umword_t old_eflags, old_eip, old_esp;   

    first_tid = l4_myself();   
    first_eip = first_esp = 0xFFFFFFFF;
    preempter = pager_tid = L4_INVALID_ID;

    l4_thread_ex_regs(first_tid, first_eip, first_esp,
                            &preempter, &pager_tid,
                            &old_eflags, &old_eip, &old_esp);
   
    // 2nd thread
    l4_threadid_t sec_tid;
    l4_umword_t sec_eip, sec_esp;
    l4_threadid_t sec_pager_tid;

    sec_tid = first_tid;
    sec_tid.id.lthread += 1;
    sec_eip = (l4_umword_t)&page_handler;
    sec_esp = (l4_umword_t)&stack001[STACK_SIZE-1];
    sec_pager_tid = pager_tid;

    printf("sec_tid, task no: %d, threadid: %d\n eip: %lx esp: %lx\n",
            sec_tid.id.task, sec_tid.id.lthread, sec_eip, sec_esp);

    l4_thread_ex_regs(sec_tid, sec_eip, sec_esp,
                            &preempter, &sec_pager_tid,
                            &old_eflags, &old_eip, &old_esp);

    // new task
    l4_taskid_t new_task;
    l4_umword_t mcp;             //max controlled priority, min[creator_mcp, specified_mcp]
    l4_umword_t new_esp;        //initial stack pointer for thread000 if new task - active
    l4_umword_t new_eip;        //entry point for thread000 if new task - active
    l4_threadid_t new_task_pgr; //L4_NIL_ID -  inactive task.
   
   
    /* l4_task_new - create/delete task
     *    create inactive/active task
     * active task - create a new address space with 128 threads and thread000 is started
     * inactive task - occupies no resources, no address space and no threads
     * task can be deleted by its chief or higher-level chief
     */
    new_task = first_tid;
    new_task.id.task += 1;
    mcp = (l4_umword_t)255;
    new_esp = (l4_umword_t)&stack002[STACK_SIZE-1];
    new_eip = (l4_umword_t)&new_task_fn;
    new_task_pgr = sec_tid;

    //printf("new task, task no: %d, threadid: %d\n", new_task.id.task, new_task.id.lthread);
    printf("new pager, task no: %d, threadid: %d\n eip: %lx esp: %lx\n",
            new_task_pgr.id.task, new_task_pgr.id.lthread, new_eip, new_esp);

    if (!rmgr_init()) { // zero - true/error
        enter_kdebug("Failed in init RMGR\n");
        return 0;
    }

    if (rmgr_get_task(new_task.id.task)) {
        enter_kdebug("Failed in get the right of task creation\n");
        return 0;
    }

    new_task = l4_task_new(new_task, mcp, new_esp, new_eip, new_task_pgr);
//    l4_umword_t esp2 = 0x40000000 + (new_task.id.task << 20 | new_task.id.lthread << L4_PAGESHIFT) + L4_PAGESIZE;
//    l4_taskid_t new_task2 = l4_task_new(new_task, 255, esp2, (l4_umword_t)&new_task_fn, new_task_pgr);

    l4_threadid_t nil_tid = L4_NIL_ID;
    if (new_task.id.task == nil_tid.id.task)
    {
        enter_kdebug("Failed to create new task\n");
        return 0;
    } else {
        printf("new task, task no: %d, threadid: %d\n", new_task.id.task, new_task.id.lthread);
        enter_kdebug("new task is succesfully created\n");
    }

    //continue running thread0
    int i = 0;
    while(1)
    {   
        /*if (i%10 == 0) {
            //l4_thread_switch(new_task);
            //l4_thread_switch(sec_tid);
            //enter_kdebug("i/10\n");
        }*/
        printf("Continue running thread, task id: %d, thread no: %d\n", first_tid.id.task, first_tid.id.lthread);
        i++;
    }

    return 0;
}


----- Original Message ----
From: Adam Lackorzynski <adam@os.inf.tu-dresden.de>
To: l4-hackers@os.inf.tu-dresden.de
Sent: Monday, March 10, 2008 7:43:17 AM
Subject: Re: Failed to create a new task

Hi,

On Sat Mar 08, 2008 at 22:54:30 -0800, ahmad kamal wrote:
> I've failed to create a new task:
>
> the l4_task_new in my code return 0 (L4_NIL_ID) which is indicate
> either the task was create as inactive or didn't create at all.

Good you have posted the source.

I think the problem is that you need to get the right for creating new
tasks first. Depending whether simple_ts is started or not you need to
use
  l4ts_allocate_task2(0, &tid)
or
  rmgr_get_task(num)

before the l4_task_new. Then it should work.



Adam
--
Adam                adam@os.inf.tu-dresden.de
  Lackorzynski        http://os.inf.tu-dresden.de/~adam/

_______________________________________________
l4-hackers mailing list
l4-hackers@os.inf.tu-dresden.de
http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers



Never miss a thing. Make Yahoo your homepage.