Hi.
I am using okl4 2.1 (yes, I know it is a little old) on gumstix.
I recently wanted to study IPC with MR exchange (passing information from one thread to the other).
The existing iguana examples (like sleeping_barber) do not seem to be using the code sections of interest (for the default one barber and one consumer).
So I created my own example, and used L4_Send(), L4_Receive() and L4_Wait(), while testing the obtained results using L4_MsgStore() and L4_MsgWord().
I saw that the MR registers were corrupted when I read them in the "thread", when comparing with "main".
I expected MR[0] would be different (different tag), but I don't understand why are the other ones different... Is this because the inline L4_Send,
L4_Receive change ARM gp registers before they call L4_Ipc?
Are the helper message functions broken (the inlines aren't designed to work with L4_Send, L4_Receive) in okl4 2.1 ?
Thank you, Gabi Voiculescu
The Original file:
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <string.h>
#include <l4/thread.h> #include <l4/ipc.h>
#include <iguana/thread.h> #include <iguana/memsection.h> #include <iguana/env.h>
static volatile L4_Thread_Id_t main_tid;
void thread(int argc, char** argv) { L4_Msg_t msg; L4_MsgTag_t tag; L4_ThreadId_t from_tid; int i; L4_Word_t mr1;
.... L4_MsgClear(&msg); L4_Set_MsgLabel(&msg,
0x12);
L4_MsgLoad(&msg); //tag = L4_Receive(main_tid); tag = L4_Wait(&from_tid);
L4_MsgStore(tag, &msg);
if (L4_IpcFailed(tag)) { printf("Player thread error syncing with main (0x%lx) (%ld).\n", (long) from_tid.raw, (long) L4_ErrorCode() >> 1); }
printf("\n\n"); /* Get Information from MRs: register information is different than what I send !!!! */ for (i=0; i<6; i++) { mr1 = L4_MsgWord(&msg, i); printf("Thread: mr[%d]=%lx\n", i, mr1); } printf("msg.tag.X.u = %d\n", msg.tag.X.u); printf("L4_Label(tag) = %lx\n", L4_Label(tag) );
while(1); ....
}
int main(int argc, char **argv) { L4_ThreadId_t from_tid, thread_tid[2]; char thread_name[20]; L4_Msg_t msg; L4_MsgTag_t tag; int i; L4_Word_t mr1;
main_tid = thread_l4tid(env_thread(iguana_getenv("MAIN")));
for (i=0; i<2; i++) { sprintf(&thread_name[0], "THREAD%d", i); thread_tid = thread_l4tid(env_thread(iguana_getenv(thread_name))); }
L4_MsgClear(&msg); L4_Set_Label(&tag, (L4_Word_t) i); L4_Set_MsgLabel(&msg, i); L4_Set_MemoryCopy(&msg.tag); L4_Set_MsgTag(&msg.tag); &msg.tag.X.u=2; L4_MsgAppendWord(&msg, tag.raw); L4_MsgAppendWord(&msg, 0x1234); L4_MsgAppendWord(&msg, 0x5678); L4_MsgLoad(&msg);
tag = L4_Send(thread_l4tid(thread_tid[i]));
L4_MsgStore(tag, &msg);
for (int j=0; j<6; j++) { mr1 = L4_MsgWord(&msg, j); printf("Main: Thread[%d]: mr[%d]=%lx\n", i, j, mr1); }
printf("msg.tag.X.u = %d\n", msg.tag.X.u);
while(1); }
Gives me the result: Main: Thread[0]: mr[0]=80801c40 Main: Thread[0]: mr[1]=fffffff8 Main: Thread[0]: mr[2]=ffffffff Main: Thread[0]: mr[3]=1 Main: Thread[0]: mr[4]=0 Main: Thread[0]: mr[5]=80805c50 msg.tag.X.u = 0
Main: Thread[1]:
mr[0]=80801c40 Main: Thread[1]: mr[1]=fffffff8 Main: Thread[1]: mr[2]=ffffffff Main: Thread[1]: mr[3]=1 Main: Thread[1]: mr[4]=0 Main: Thread[1]: mr[5]=80805c50 msg.tag.X.u = 0
Thread: mr[0]=20001 Thread: mr[1]=8002c0b8 Thread: mr[2]=0 <---notice change from here on Thread: mr[3]=0 Thread: mr[4]=0 Thread:
mr[5]=0 msg.tag.X.u = 2
Thread: mr[0]=24001 Thread: mr[1]=8002c048 Thread: mr[2]=0 Thread: mr[3]=0 Thread: mr[4]=0 Thread: mr[5]=0 msg.tag.X.u = 2 L4_Label(tag) = 0
L4_Label(tag) = 0
|