Skip to content
Snippets Groups Projects
Commit f4a54838 authored by Tom Feng's avatar Tom Feng
Browse files

after merge

parents 1f197fed f845a6b4
No related branches found
No related tags found
1 merge request!16Withtime
......@@ -4,6 +4,7 @@
"bwio.h": "c",
"kernel.h": "c",
"scheduler.h": "c",
"k1.h": "c"
"k1.h": "c",
"buffer.h": "c"
}
}
\ No newline at end of file
#ifndef BUFFER_H
#define BUFFER_H
// FIFO queue
Pair* MakePair(int TaskID, char* Msg);
void PushToBuffer(Buffer B, int TaskID, char* Msg);
Pair* FrontBuffer(Buffer* B);
int PopFrontBuffer(Buffer* B);
#endif
\ No newline at end of file
#ifndef IPC_H
#define IPC_H
int doSend(KernelStruct* Colonel, int TaskID, void* Msg, int MsgLen, void* Reply, int ReplyLen);
int doReceive(KernelStruct* Colonel, int TaskID, void* Msg, int MsgLen);
int doReply(KernelStruct* Colonel, int TaskID, void* Reply, int ReplyLen);
#endif
......@@ -20,7 +20,7 @@ void Exit();
int Send (int TaskID, void* Msg, int MsgLen, void* Reply, int ReplyLen) {};
int Receive (int* TaskID, void* Msg, int MsgLen) {};
int Receive (int TaskID, void* Msg, int MsgLen) {};
int Reply (int TaskID, void* Reply, int ReplyLen) {};
......
#ifndef TYPES_H
#define TYPES_H
#define SUCCESS 0
#define FAILURE -1
#define MAX_NUM_PRIORITY 8
#define MAX_NUM_TD 60
......@@ -10,31 +13,57 @@
#define NULL 0
#define NAMESERVER_ID 6
#define NAMESERVER_TID 6
#define NS_MESSAGE_MAX_LENGTH 16
#define MSG_TRUNCATED -1
#define TASK_DNE -2
#define SRR_FAILED -3
#define TASK_NOT_REPLY_BLOCKED -3
#define NAMESERVER_TID_INVALID -1
#define MAX_NUM_BUFFER 20
#define NAME_LENGTH_MAX 16
#define HASH_SIZE
#define HASH_SIZE 257
typedef struct pair {
int TaskID;
char* Msg;
Pair* Next;
} Pair;
typedef struct buffer {
Pair* Head;
Pair* Tail;
int Num;
} Buffer;
typedef enum NameServerMessageType {
WhoIs,
RegisterAs
} NSMsgType;
typedef struct NameServerRequest {
typedef struct NameServerRequest{
int TaskID;
char Msg[NS_MESSAGE_MAX_LENGTH];
NSMsgType MsgType;
} NSReq;
typedef struct NameServerMessage {
char Msg[NS_MESSAGE_MAX_LENGTH];
} NSMsg;
typedef struct ArgumentPack{
void * arg0;
void * arg1;
void * arg2;
void * arg3;
void * arg4;
}AP;
typedef enum taskstate {
Active,
Ready,
......@@ -85,6 +114,7 @@ typedef struct kernel {
TD* Active;
TDPQ ArrayPQ[MAX_NUM_PRIORITY];
TD Tasks[MAX_NUM_TD];
Buffer B;
//index is TaskID; value of 1 = alive
// a free list of pointers to free TDs. This might take the form of bits set in a couple of words. WHAT?
// a structure for keeping the request currently being serviced, including its arguments.
......
#include <buffer.h>
#include <types.h>
void BufferInit(Buffer* B) {
B->Num = 0;
}
Pair* MakePair(int TaskID, char* Msg) {
Pair* P;
P->TaskID = TaskID;
P->Msg = Msg;
P->Next = NULL;
return P;
}
void PushToBuffer(Buffer* B, int TaskID, char* Msg) {
Pair* New = MakePair(TaskID, Msg);
if (B) {
if (B->Head == NULL) {
B->Head = New;
B->Tail = New;
}
else {
New->Next = B->Head;
B->Head = New;
}
B->Num += 1;
}
}
Pair* FrontBuffer(Buffer* B) {
if (B && B->Head) return B->Head;
return FAILURE;
}
int PopFrontBuffer(Buffer* B) {
if (B && B->Head) {
B->Head = B->Head->Next;
B->Num -= 1;
} else return FAILURE;
}
#include <ipc.h>
#include <kernel.h>
int doSend(KernelStruct* Colonel, int TaskID, void* Msg, int MsgLen, void* Reply, int ReplyLen) {
}
int doReceive(KernelStruct* Colonel, int TaskID, void* Msg, int MsgLen) {
}
int doReply(KernelStruct* Colonel, int TaskID, void* Reply, int ReplyLen) {
}
#include <nameserver.h>
#include <tools.h>
int WhoIs(char* Name) {
NSReqMsg SendMsg, ReplyMsg;
int Status;
AP Args;
register int r0 asm ("r0");
SendMsg.MsgType = WhoIs;
stringCopy(SendMsg.Msg, Name, NS_MESSAGE_MAX_LENGTH);
Args.arg0 = SendMsg;
Args.arg1 = sizeof(NSMsg);
Args.arg2 = ReplyMsg;
Args.arg3 = sizeof(NSMsg);
asm volatile ("swi 5\n\t");
Status = r0;
if (Status == sizeof(NSMsg)) return ReplyMsg.TaskID; // TODO FIXME TODO
else return NAMESERVER_TID_INVALID;
}
int WhoIs (char* Name);
int RegisterAs (char* Name) {
NameServerRequest Req;
int Status = 0;
Req.MsgType = RegisterAs;
stringCopy(Req.Msg, Name, NS_MESSAGE_MAX_LENGTH);
Status = Send()
\ No newline at end of file
NSReqMsg SendMsg, ReplyMsg;
int Status;
AP Args;
register int r0 asm ("r0");
SendMsg.MsgType = RegisterAs;
stringCopy(SendMsg.Msg, Name, NS_MESSAGE_MAX_LENGTH);
Args.arg0 = SendMsg;
Args.arg1 = sizeof(NSMsg);
Args.arg2 = ReplyMsg;
Args.arg3 = sizeof(NSMsg);
asm volatile ("swi 5\n\t");
Status = r0;
if (Status == sizeof(NSMsg)) return SUCCESS;
else return NAMESERVER_TID_INVALID;
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
#include <types.h>
#include <scheduler.h>
#include <bwio.h>
#include <buffer.h>
void handlerCreate(KernelStruct* Colonel) {
// bwprintf(COM2,"handlerCreate: just in\n\r");
......@@ -25,19 +26,59 @@ void handlerCreate(KernelStruct* Colonel) {
Colonel->Active->RetVal = NewTask->TaskID;
}
<<<<<<< HEAD
void handlerSend(TD* Task, int TaskID, char* Msg, int MsgLen, char* Reply, int ReplyLen) {
int result;
=======
int handlerSend(KernelStruct* Colonel) {
int Result;
>>>>>>> f845a6b4431f235529ed4297cf336ccd623a7a5f
AP* Args = Colonel->Active->Args;
int A0 = (int)Args->arg0; // Msg
int A1 = (int)Args->arg1; // MsgLen
int A2 = (int)Args->arg2; // Reply
int A3 = (int)Args->arg3; // ReplyLen
result = handlerSend()
int A0 = (int)Args->arg0;
int A1 = (int)Args->arg1;
int A2 = (int)Args->arg2;
int A3 = (int)Args->arg3;
int A4 = (int)Args->arg4
char* Msg = (char*)A1;
int MsgLen = (int)A2;
char* Reply = (char*)A3;
int ReplyLen = (int)A4;
Result = doSend(Colonel, A0, Msg, MsgLen, Reply, ReplyLen);
Colonel->Active->RetVal = Colonel->Active->TaskID;
}
int handlerReceive(int TaskID, void* Msg, int MsgLen) {
AP* Args = Colonel->Active->Args;
int A0 = (int)Args->arg0;
int A1 = (int)Args->arg1;
int A2 = (int)Args->arg2;
void* Msg = (void*)A1;
int MsgLen = (int)A2;
Result = doReceive(Colonel, A0, Msg, MsgLen);
}
void handlerReceive(int* TaskID, void* Msg, int MsgLen) {}
int handlerReply(int TaskID, void* Reply, int ReplyLen) {
AP* Args = Colonel->Active->Args;
void handlerReply(int TaskID, void* Reply, int ReplyLen) {}
int A0 = (int)Args->arg0;
int A1 = (int)Args->arg1;
int A2 = (int)Args->arg2;
void* Reply = (void*)A1;
int ReplyLen = (int)A2;
Result = doReply(Colonel, A0, Reply, ReplyLen);
}
......@@ -54,6 +95,7 @@ void handlerWhoIS(KernelStruct* Colnel){
void Handle(KernelStruct* Colonel, int n) {
// bwprintf(COM2,"Handle: n=%d\n\r",n);
<<<<<<< HEAD
switch(n) {
case SYS_Create:
......@@ -97,6 +139,43 @@ void Handle(KernelStruct* Colonel, int n) {
handlerRegAs(Colonel);
break;
}
=======
switch(n) {
case SYS_Create:
//bwprintf(COM2,"before, Args = %d\n\r",Args);
handlerCreate(Colonel);
break;
case SYS_MyTid:
(Colonel->Active)->RetVal = (Colonel->Active)->TaskID;
pushToScheduler(Colonel,Colonel->Active);
Colonel->Active = NULL;
break;
case SYS_ParentTid:
(Colonel->Active)->RetVal = (Colonel->Active)->ParentID;
pushToScheduler(Colonel,Colonel->Active);
Colonel->Active = NULL;
break;
case SYS_Pass:
pushToScheduler(Colonel,Colonel->Active);
Colonel->Active = NULL;
break;
case SYS_Exit:
(Colonel->Active)->TaskState = Zombie;
Colonel->Active = NULL;
break;
case SYS_Send:
(Colonel->Active)->RetVal = handlerSend(Colonel);
break;
case SYS_Receive:
(Colonel->Active)->RetVal = handlerReceive(Colonel);
break;
case SYS_Reply:
(Colonel->Active)->RetVal = handlerReply(Colonel);
break;
}
>>>>>>> f845a6b4431f235529ed4297cf336ccd623a7a5f
}
void fakeExit(TD* Task){
......
......@@ -45,6 +45,7 @@ void Exit() {
asm volatile ("swi 4\n\t");
}
// tid is that of the one its sending to
int Send (int TaskID, void* Msg, int MsgLen, void* Reply, int ReplyLen) {
asm volatile ("swi 5\n\t");
register int RetVal asm("r0");
......@@ -52,13 +53,18 @@ int Send (int TaskID, void* Msg, int MsgLen, void* Reply, int ReplyLen) {
return Return;
}
int Receive (int* TaskID, void* Msg, int MsgLen) {
int Receive (int TaskID, void* Msg, int MsgLen) {
asm volatile ("swi 6\n\t");
register int RetVal asm("r0");
int Return = RetVal;
return Return;
}
/*
The calling task and the sender return at the same logical time. If they are of the same priority the sender runs first.
*/
int Reply (int TaskID, void* Reply, int ReplyLen) {
asm volatile ("swi 7\n\t");
register int RetVal asm("r0");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment