how i can determine utcb loaction in order to make thread
Jason Philip
mored1759 at gmail.com
Fri Apr 1 01:02:22 CEST 2011
I take your advice but nothing change. I do not know what you mean
by "use the top of the stack rather than the bottom" if i say
"sp = (L4_Word_t)stack" would that mean the start address of the
array? But just in case I use "sp = stack[1023]" My new code
look like this:
#include <l4io.h>
#include <l4/thread.h>
#include <l4/kip.h>
#include <l4/schedule.h>
#include <l4/ipc.h>
char stack[1024];
void Jenev(void)
{
L4_MsgTag_t tag;
L4_ThreadId_t from;
tag = L4_Wait (&from);
printf("the thread was started\n");
}
void main()
{
printf("starting application [OK]\n");
L4_ThreadId_t me, jen;
L4_Word_t baseNo, baseVer;
L4_Word_t utcb_b, utcb_l;
void * kip;
L4_Word_t ip, sp;
kip = L4_KernelInterface();
L4_ThreadId_t mylocalid = L4_MyLocalId();
me = L4_MyGlobalId();
baseNo = L4_ThreadNo(me);
baseVer = L4_Version(me);
jen = L4_GlobalId(baseNo+1, baseVer);
utcb_b = *(L4_Word_t*)&mylocalid;
utcb_b &= ~(L4_UtcbAreaSize(kip) -1);
utcb_l = utcb_b + (L4_UtcbSize(kip) * ((L4_ThreadNo(jen) - baseNo)));
ip = (L4_Word_t)Jenev;
sp = (L4_Word_t)stack;
int res = L4_ThreadControl(jen, me, me, L4_nilthread, (void*)utcb_l);
printf("starting jenev-thread ");
if(!res)
{
printf("[FAIL]\n");
L4_Word_t err = L4_ErrorCode();
switch(err)
{
case 1:
printf("no privilege\n");
break;
case 2:
printf("unavailale thread\n");
break;
case 3:
printf("invalid space\n");
break;
case 4:
printf("invalid scheduler\n");
break;
case 6:
printf("invalid UTCB location\n");
printf("root-thread number is: %d\n", (int)baseNo);
printf("jenev-thread number is: %d\n", (int)L4_ThreadNo
(jen));
printf("the utcb size is: %d \n", (int)L4_UtcbSize
(kip));
printf("the additive is: %d\n", (int)(L4_UtcbSize(kip)
* (L4_ThreadNo(jen) - baseNo)));
break;
case 8:
printf("out of memory\n");
break;
printf("the utcb location of root-thread is: %d \n",
(int)utcb_b);
printf("the utcb loaction of jenev-thread is: %d \n",
(int)utcb_l);
}
}
else
printf("[OK]\n");
L4_Time_t snd_time_out = L4_TimePeriod(1000000);
L4_Msg_t msg;
L4_Clear(&msg);
L4_Append(&msg, ip);
L4_Append(&msg, sp);
L4_Load(&msg);
L4_MsgTag_t result = L4_Send(jen, snd_time_out);
printf("initial thread continued\n");
if(L4_IpcFailed(result))
{
L4_Word_t err = L4_ErrorCode();
printf("the ipc failed\n");
printf("error: [%d]\n", (int)err);
}
while(1)
{
printf("test loop\n")
}
}
More information about the l4-hackers
mailing list