00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "core/message.h"
00019 #include "proc/proc.h"
00020 #include "core/kint.h"
00021
00022 DB _msg[MAX_PROC][MAX_Q];
00023
00024 SDW send(DW pid,MSG *msg)
00025 {
00026 DW seg;
00027 DD linear, phy;
00028 MSG *m;
00029
00030 if(_proc[pid].avl == _true)
00031 return -1;
00032
00033 linear = logi_to_lin(cur_pid,_proc[cur_pid].cs,(DD)msg);
00034 phy = lin_to_phy(cur_pid,linear);
00035
00036 m = (MSG *) phy;
00037 m->from_pid = cur_pid;
00038 printf("\nsend %d %d %x",pid,cur_pid,phy);
00039 printf("\nAfter Send");
00040
00041 if(_proc[pid].msg_q_delim + m->length + 10 >= MAX_Q)
00042 return -1;
00043
00044 if(remove(&message_q,pid) == 0)
00045 {
00046 memcpy((void *)_proc[pid].recv_addr,(void *)m,m->length+10);
00047 printf("\nremove msg %s",((MSG *)_proc[pid].recv_addr)->msg_buf);
00048 enq(&ready_q,pid);
00049 }
00050 else
00051 {
00052 memcpy((void *)((DB *)_msg[pid] + _proc[pid].msg_q_delim),(void *)m,m->length+10);
00053 printf("\nmessage %s delim %d %d",((MSG *)((DB*)_msg[pid]+ _proc[pid].msg_q_delim))->msg_buf,_proc[pid].msg_q_delim,((MSG *)_msg[pid])->length);
00054 _proc[pid].msg_q_delim = _proc[pid].msg_q_delim + m->length + 10;
00055 }
00056 return 0;
00057 }
00058
00059 SDW recv(MSG *msg)
00060 {
00061 DW seg;
00062 DD linear, phy;
00063 MSG *dest_m,*src_m;
00064 DD i;
00065
00066 linear = logi_to_lin(cur_pid,_proc[cur_pid].cs,(DD)msg);
00067 phy = lin_to_phy(cur_pid,linear);
00068 dest_m = (MSG *) phy;
00069
00070 cls();
00071 if(_proc[cur_pid].msg_q_delim != 0)
00072 {
00073 src_m = (MSG *)(_msg[cur_pid]);
00074 memcpy((void *)dest_m,(void *)src_m,src_m->length+10);
00075 printf("\nrecv %d %s delin %d %d",cur_pid,dest_m->msg_buf,_proc[cur_pid].msg_q_delim,src_m->length);
00076 for(i=0;i <_proc[cur_pid].msg_q_delim - dest_m->length -10;i++)
00077 {
00078 _msg[cur_pid][i] = _msg[cur_pid][i+dest_m->length + 10];
00079 }
00080 _proc[cur_pid].msg_q_delim = _proc[cur_pid].msg_q_delim - dest_m->length - 10;
00081 }
00082 else
00083 {
00084 remove(&ready_q,cur_pid);
00085 enq(&message_q,cur_pid);
00086
00087 _proc[cur_pid].recv_addr = phy;
00088 printf("\nQueueing ptr %d %d %d",message_q.front,message_q.end,message_q.n);
00089 printf("\nMSG Q");
00090 printQ(&message_q);
00091 }
00092 }
00093
00094
00095 SDW ksend(DW pid, MSG *m)
00096 {
00097
00098 m->from_pid = KERNEL_PID;
00099
00100 printf("\n In ksend ");
00101 printf("\nKERNEL PID %x",m->from_pid);
00102
00103 if(_proc[pid].msg_q_delim + m->length + 10 >= MAX_Q)
00104 return -1;
00105
00106 if(remove(&message_q,pid) == 0)
00107 {
00108 memcpy((void *)_proc[pid].recv_addr,(void *)m,m->length+10);
00109 enq(&ready_q,pid);
00110 }
00111 else
00112 {
00113 memcpy((void *)((DB *)_msg[pid] + _proc[pid].msg_q_delim),(void *)m,m->length+10);
00114 _proc[pid].msg_q_delim = _proc[pid].msg_q_delim + m->length + 10;
00115 }
00116
00117 return;
00118 }