#include <syscall.h>
#include <context-switch.h>
#include <bwio.h>

int Create (AP* Args) {
  //bwprintf(COM2,"Create: Arg location:%d\n\r",Args);
  asm volatile ("swi 0\n\t" );
//  bwprintf(COM2,"Back to Create\n\r");
  register int RetVal asm("r0");
  int Return = RetVal;
  return Return;
}

int MyTid() {
  int Address = (int )(&MyTid);
  //bwprintf(COM2,"MyTid Address: %d\n\r",Address);
  asm volatile ("swi 1\n\t");
  register int RetVal asm("r0");
  int R = RetVal;
  //bwprintf(COM2,"Back to MyTid, my tid is %d, My Address is %d\n\r",R);
  return RetVal;
}

int MyParentTid() {
    asm volatile ("swi 2\n\t");
    register int RetVal asm("r0");
    return RetVal;

}

void Pass() {
    asm volatile ("swi 3\n\t");
}

void Exit() {
  //bwprintf(COM2,"Before SWI exit\n\r");
  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");
  int Return = RetVal;
  return Return;
}



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");
  int Return = RetVal;
  return Return;
}