Exemplo n.º 1
0
void DfsModuleInit() {
// You essentially set the file system as invalid and then open
// using DfsOpenFileSystem().
  sb.valid = 0;
  dfs_fbv_lock = LockCreate();
  dfs_inode_lock = LockCreate();
  DfsOpenFileSystem();
}
Exemplo n.º 2
0
void DfsModuleInit() {
// You essentially set the file system as invalid and then open 
// using DfsOpenFileSystem().
   int i,j;
   DfsInvalidate();
   lock_fbv = LockCreate();
   lock_inode = LockCreate();
   
   if (DfsOpenFileSystem()== DFS_FAIL){
      printf("Failed to open the file syatem\n");
   }
}
Exemplo n.º 3
0
//-------------------------------------------------------
//
// mbox_t MboxCreate();
//
// Allocate an available mailbox structure for use. 
//
// Returns the mailbox handle on success
// Returns MBOX_FAIL on error.
//
//-------------------------------------------------------
mbox_t MboxCreate() {
  
  int ct;
  mbox_t mbox_ct;
  uint32 intrval;
  
  // grabbing a mbox should be an atomic operation
  intrval = DisableIntrs();
  for(mbox_ct = 0; mbox_ct < MBOX_NUM_MBOXES; mbox_ct++){
    // inuse = 0: the mbox is reserved, but not opened for any process yet
    if(system_mbox[mbox_ct].num_of_pid_inuse == -1 ){
      system_mbox[mbox_ct].num_of_pid_inuse = 0;
      break;
    }
  }
  RestoreIntrs(intrval);

  if(mbox_ct == MBOX_NUM_MBOXES){
    return MBOX_FAIL;
  }

  system_mbox[mbox_ct].mbox_buffer_head = 0;
  system_mbox[mbox_ct].mbox_buffer_tail = 0;
  system_mbox[mbox_ct].mbox_buffer_slot_used = 0;
  system_mbox[mbox_ct].mbox_buffer_lock = LockCreate();
  system_mbox[mbox_ct].mbox_buffer_fill = CondCreate(system_mbox[mbox_ct].mbox_buffer_lock);
  system_mbox[mbox_ct].mbox_buffer_empty = CondCreate(system_mbox[mbox_ct].mbox_buffer_lock);

  for(ct = 0; ct < PROCESS_MAX_PROCS; ct++){
    // No proc opens the mbox when it is created
    system_mbox[mbox_ct].mbox_pid_list[ct] = 0;
  }

  return mbox_ct;
}
Exemplo n.º 4
0
//-------------------------------------------------------
//
// mbox_t MboxCreate();
//
// Allocate an available mailbox structure for use. 
//
// Returns the mailbox handle on success
// Returns MBOX_FAIL on error.
//
//-------------------------------------------------------
mbox_t MboxCreate() {
	mbox_t imbox;
	uint32 intrval;

	// grabbing a Mbox should be an atomic operation
	intrval = DisableIntrs();
	for(imbox = 0; imbox < MBOX_NUM_MBOXES; imbox++) {
		if(mboxes[imbox].inuse == false) {
			mboxes[imbox].inuse = true;
			break;
		}
	}
	RestoreIntrs(intrval);
	if(imbox == MAX_SEMS) return MBOX_FAIL;
	if ((mboxes[imbox].s_mbox_emptyslots = SemCreate(MBOX_MAX_BUFFERS_PER_MBOX - 1)) == SYNC_FAIL) {
		printf("Bad sem_create in MboxOpen");
		exitsim();
	}
	if ((mboxes[imbox].s_mbox_fillslots = SemCreate(0)) == SYNC_FAIL) {
		printf("Bad sem_create in MboxOpen");
		exitsim();
	}
	if((mboxes[imbox].l_mbox = LockCreate()) == SYNC_FAIL) {
		printf("Bad lock_create in MboxModInit");
		exitsim();
	}
	return imbox;
}
Exemplo n.º 5
0
void MboxModuleInit() {
	int i;
	int j;
	for(i = 0; i < MBOX_NUM_MBOXES; i++) {
		for(j = 0; j < PROCESS_MAX_PROCS; j++) {
			mboxes[i].opened_pids[j] = false;
		}

		for(j = 0; j < MBOX_MAX_BUFFERS_PER_MBOX; j++) {
			mboxes[i].cbobi[j] = -1; // invalid
		}

		mboxes[i].opened_pids_count = 0;
		mboxes[i].head_cbobi = 0;
		mboxes[i].tail_cbobi = 0;
		mboxes[i].inuse = false;
		mboxes[i].mbox_id = i;
	}
	for(i = 0; i < MBOX_NUM_BUFFERS; i++) {
		mbox_buffers[i].inuse = false;		
	}
	// if ((s_buff_emptyslots = SemCreate(MBOX_NUM_BUFFERS - 1)) == SYNC_FAIL) {
	// 	printf("Bad sem_create in MboxModInit");
	// 	exitsim();
	// }
	if((l_buff = LockCreate()) == SYNC_FAIL) {
		printf("Bad lock_create in MboxModInit");
		exitsim();
	}
}
Exemplo n.º 6
0
//-------------------------------------------------------
//
// mbox_t MboxCreate();
//
// Allocate an available mailbox structure for use. 
//
// Returns the mailbox handle on success
// Returns MBOX_FAIL on error.
//
//-------------------------------------------------------
mbox_t MboxCreate() {

	mbox_t mbox_no = MBOX_NUM_MBOXES;
	for(i = 0; i < MBOX_NUM_MBOXES;i++)
	{
		if(MailBox[i].inuse == false)
		{
			mbox_no = i;
			break;
		}
	}

	if(mbox_no == MBOX_NUM_MBOXES)
	{
		printf("MailBox cannot be assigned to the calling process : %d\n", GetCurrentPid());
		return MBOX_FAIL;
	}

	MailBox[mbox_no].inuse = true;

	if((MailBox[mbox_no].lock = LockCreate()) == SYNC_FAIL)
	{
		printf("MailBox cannot associate a lock with itself for calling process : %d\n", GetCurrentPid());
		return MBOX_FAIL;
	}

	if((MailBox[mbox_no].moreData = CondCreate(MailBox[mbox_no].lock)) == SYNC_FAIL)
	{
		printf("MailBox cannot associate a cond var for buffer emptiness calling process : %d\n", GetCurrentPid());
		return MBOX_FAIL;
	}

	if((MailBox[mbox_no].moreSpace = CondCreate(MailBox[mbox_no].lock)) == SYNC_FAIL)
	{
		printf("MailBox cannot associate a cond var for buffer saturation for calling process : %d\n", GetCurrentPid());
		return MBOX_FAIL;
	}

	if(AQueueInit(&MailBox[mbox_no].buffers) == QUEUE_FAIL)
	{
		printf("FATAL Error : Available mailbox : %d cannot have its buffer queue initialized for process : %d\n", mbox_no, GetCurrentPid());
		return MBOX_FAIL;
		//exitsim();
	}

	for(i = 0; i < PROCESS_MAX_PROCS; i++)
	{
		MailBox[mbox_no].procs_link[i] = 0;
	}

	//MailBox[mbox_no].tail = 0; 
	//MailBox[mbox_no].head = 1;
	MailBox[mbox_no].process_count = 0;


	//printf("Created mailbox with handle : %d\n", mbox_no);
	return mbox_no;
}
Exemplo n.º 7
0
static int Create(systimer* p)
{
	p->Node.Enum = (nodeenum)TimerEnum;
	p->Node.Get = (nodeget)Get;
	p->Node.Set = (nodeset)Set;
	p->Speed.Den = p->Speed.Num = 1;
	p->SpeedTime.Num = TICKSPERSEC;
	p->SpeedTime.Den = GetTimeFreq();
	p->Section = LockCreate();
	return ERR_NONE;
}
Exemplo n.º 8
0
bool SchedulingInited; void SchedulingInit() {
	if(!SchedulingInited) {
		MemoryInit();
		TimeInit();
		ControlRequests=1;
	        CurrentTask=SystemTasks=NULL;
		ActiveScheduler=NullScheduler;
	        InterruptVectorCount=0;
		SystemLock=LockCreate();
		//CurrentSP=NULL;
		SchedulingInited=TRUE;
	}
}
Exemplo n.º 9
0
//-------------------------------------------------------
//
// mbox_t MboxCreate();
//
// Allocate an available mailbox structure for use. 
//
// Returns the mailbox handle on success
// Returns MBOX_FAIL on error.
//
//-------------------------------------------------------
mbox_t MboxCreate() {
	int i;
	int j;
	for (i = 0; i < MBOX_NUM_MBOXES; i++) {  //modified (MBOX_NUM_BOXES)
		if (mbox_list[i].in_use == -1){
			mbox_list[i].in_use = 0;
			mbox_list[i].msg_count = 0;
			mbox_list[i].empty = SemCreate(MBOX_MAX_BUFFERS_PER_MBOX);  //modified (MBOX_MAX_BUFFERS)
			mbox_list[i].full = SemCreate(0);
			mbox_list[i].lock = LockCreate();
			for(j = 0; j < MBOX_NUM_BUFFERS; j++) {
				mbox_list[i].users[j] = -1;
			}
			return mbox_list[i].handle;
		}
	}
	return MBOX_FAIL;
}
Exemplo n.º 10
0
//-------------------------------------------------------
//
// mbox_t MboxCreate();
//
// Allocate an available mailbox structure for use. 
//
// Returns the mailbox handle on success
// Returns MBOX_FAIL on error.
//
//-------------------------------------------------------
mbox_t MboxCreate() {
    mbox_t mbox;
    uint32 intrval;

    //grabbing a mailbox should be an atomic operation
    intrval = DisableIntrs();
    for(mbox=0; mbox<MBOX_NUM_MBOXES; mbox++){
        if(mboxs[mbox].inuse == 0){
            mboxs[mbox].inuse = 1;
            break;
        }
    }
    RestoreIntrs(intrval);

    if((mboxs[mbox].l = LockCreate()) == SYNC_FAIL){
        printf("FATAL ERROR: Could not create lock for mbox\n");
        exitsim();
    }

    if((mboxs[mbox].s_msg_full = SemCreate(0)) == SYNC_FAIL) {
        printf("Bad sem create in mbox create\n ");
        exitsim();
    }

    if((mboxs[mbox].s_msg_empty = SemCreate(MBOX_MAX_BUFFERS_PER_MBOX)) == SYNC_FAIL) {
        printf("Bad sem create in mbox create\n ");
        exitsim();
    }

    if(mbox == MBOX_NUM_MBOXES) return MBOX_FAIL;

    if(AQueueInit(&mboxs[mbox].messages) != QUEUE_SUCCESS){
        printf("FATAL ERROR: Could not initialize mbox messsage queue\n");
        exitsim();
    }

    if(AQueueInit(&mboxs[mbox].pids) != QUEUE_SUCCESS){
        printf("FATAL ERROR: Could not initialize mbox pid queue\n");
        exitsim();
    }

    return mbox;
}
Exemplo n.º 11
0
void MboxModuleInit() {
  int ct;

  system_mbox_message.system_buffer_slot_used = 0;
  system_mbox_message.system_buffer_lock = LockCreate();

  system_mbox_message.system_buffer_empty = CondCreate(system_mbox_message.system_buffer_lock);

  // Initially, all system buffer slots are available for using
  for(ct = 0; ct < MBOX_NUM_BUFFERS; ct++){
    system_mbox_message.system_buffer_index_array[ct] = 0;
  }

  // inuse = -1: not activated, inuse = 0: activated, ready to be opened, no process is using it now
  // inuse > 0: some processes are using it
  for(ct = 0; ct < MBOX_NUM_MBOXES; ct++){
    system_mbox[ct].num_of_pid_inuse = -1;
  }

}
Exemplo n.º 12
0
//----------------------------------------------------------------------
//
//	doInterrupt
//
//	Handle an interrupt or trap.
//
//----------------------------------------------------------------------
void
dointerrupt (unsigned int cause, unsigned int iar, unsigned int isr,
	     uint32 *trapArgs)
{
  int	result;
  int	i;
  uint32	args[4];
  int	intrs;
  uint32 handle;
  int ihandle;

  dbprintf ('t',"Interrupt cause=0x%x iar=0x%x isr=0x%x args=0x%08x.\n",
	    cause, iar, isr, (int)trapArgs);
  // If the TRAP_INSTR bit is set, this was from a trap instruction.
  // If the bit isn't set, this was a system interrupt.
  if (cause & TRAP_TRAP_INSTR) {
    cause &= ~TRAP_TRAP_INSTR;
    switch (cause) {
    case TRAP_CONTEXT_SWITCH:
      dbprintf ('t', "Got a context switch trap!\n");
      ProcessSchedule ();
      ClkResetProcess();
      break;
    case TRAP_EXIT:
    case TRAP_USER_EXIT:
      dbprintf ('t', "Got an exit trap!\n");
      ProcessDestroy (currentPCB);
      ProcessSchedule ();
      ClkResetProcess();
      break;
    case TRAP_PROCESS_FORK:
      dbprintf ('t', "Got a fork trap!\n");
      break;
    case TRAP_PROCESS_SLEEP:
      dbprintf ('t', "Got a process sleep trap!\n");
      ProcessSuspend (currentPCB);
      ProcessSchedule ();
      ClkResetProcess();
      break;
    case TRAP_PRINTF:
      // Call the trap printf handler and pass the arguments and a flag
      // indicating whether the trap was called from system mode.
      dbprintf ('t', "Got a printf trap!\n");
      TrapPrintfHandler (trapArgs, isr & DLX_STATUS_SYSMODE);
      break;
    case TRAP_OPEN:
      // Get the arguments to the trap handler.  If this is a user mode trap,
      // copy them from user space.
      if (isr & DLX_STATUS_SYSMODE) {
	args[0] = trapArgs[0];
	args[1] = trapArgs[1];
      } else {
	char	filename[32];
	// trapArgs points to the trap arguments in user space.  There are
	// two of them, so copy them to to system space.  The first argument
	// is a string, so it has to be copied to system space and the
	// argument replaced with a pointer to the string in system space.
	MemoryCopyUserToSystem (currentPCB, (char *)trapArgs, (char *)args, sizeof(args[0])*2);
	MemoryCopyUserToSystem (currentPCB, (char *)(args[0]), (char *)filename, 31);
	// Null-terminate the string in case it's longer than 31 characters.
	filename[31] = '\0';
	// Set the argument to be the filename
	args[0] = (uint32)filename;
      }
      // Allow Open() calls to be interruptible!
      intrs = EnableIntrs ();
      ProcessSetResult (currentPCB, args[1] + 0x10000);
      printf ("Got an open with parameters ('%s',0x%x)\n", (char *)(args[0]), args[1]);
      RestoreIntrs (intrs);
      break;
    case TRAP_CLOSE:
      // Allow Close() calls to be interruptible!
      intrs = EnableIntrs ();
      ProcessSetResult (currentPCB, -1);
      RestoreIntrs (intrs);
      break;
    case TRAP_READ:
      // Allow Read() calls to be interruptible!
      intrs = EnableIntrs ();
      ProcessSetResult (currentPCB, -1);
      RestoreIntrs (intrs);
      break;
    case TRAP_WRITE:
      // Allow Write() calls to be interruptible!
      intrs = EnableIntrs ();
      ProcessSetResult (currentPCB, -1);
      RestoreIntrs (intrs);
      break;
    case TRAP_DELETE:
      intrs = EnableIntrs ();
      ProcessSetResult (currentPCB, -1);
      RestoreIntrs (intrs);
      break;
    case TRAP_SEEK:
      intrs = EnableIntrs ();
      ProcessSetResult (currentPCB, -1);
      RestoreIntrs (intrs);
      break;
    case TRAP_PROCESS_GETPID:
      ProcessSetResult(currentPCB, GetCurrentPid()); 
      break;
    case TRAP_PROCESS_CREATE:
      TrapProcessCreateHandler(trapArgs, isr & DLX_STATUS_SYSMODE);
      break;
    case TRAP_SEM_CREATE:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      ihandle = SemCreate(ihandle);
      ProcessSetResult(currentPCB, ihandle); //Return handle
      break;
    case TRAP_SEM_WAIT:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      handle = SemHandleWait(ihandle);
      ProcessSetResult(currentPCB, handle); //Return 1 or 0
      break;
    case TRAP_SEM_SIGNAL:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      handle = SemHandleSignal(ihandle);
      ProcessSetResult(currentPCB, handle); //Return 1 or 0
      break;
    case TRAP_MALLOC:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      ihandle = (int)malloc(currentPCB, ihandle);
      ProcessSetResult(currentPCB, ihandle); //Return handle
      break;
    case TRAP_MFREE:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      ihandle = mfree(currentPCB, (void*)ihandle);
      ProcessSetResult(currentPCB, ihandle); //Return handle
      break;
    case TRAP_LOCK_CREATE:
      ihandle = LockCreate();
      ProcessSetResult(currentPCB, ihandle); //Return handle
      break;
    case TRAP_LOCK_ACQUIRE:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      handle = LockHandleAcquire(ihandle);
      ProcessSetResult(currentPCB, handle); //Return 1 or 0
      break;
    case TRAP_LOCK_RELEASE:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      handle = LockHandleRelease(ihandle);
      ProcessSetResult(currentPCB, handle); //Return 1 or 0
      break;
    case TRAP_COND_CREATE:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      ihandle = CondCreate(ihandle);
      ProcessSetResult(currentPCB, ihandle); //Return handle
      break;
    case TRAP_COND_WAIT:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      ihandle = CondHandleWait(ihandle);
      ProcessSetResult(currentPCB, ihandle); //Return 1 or 0
      break;
    case TRAP_COND_SIGNAL:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      ihandle = CondHandleSignal(ihandle);
      ProcessSetResult(currentPCB, ihandle); //Return 1 or 0
      break;
    case TRAP_COND_BROADCAST:
      ihandle = GetIntFromTrapArg(trapArgs, isr & DLX_STATUS_SYSMODE);
      ihandle = CondHandleBroadcast(ihandle);
      ProcessSetResult(currentPCB, ihandle); //Return 1 or 0
      break;
    default:
      printf ("Got an unrecognized trap (0x%x) - exiting!\n",
	      cause);
      exitsim ();
      break;
    }
  } else {
    switch (cause) {
    case TRAP_TIMER:
      dbprintf ('t', "Got a timer interrupt!\n");
      // ClkInterrupt returns 1 when 1 "process quantum" has passed, meaning
      // that it's time to call ProcessSchedule again.
      if (ClkInterrupt()) {
        ProcessSchedule ();
      }
      break;
    case TRAP_KBD:
      do {
	i = *((uint32 *)DLX_KBD_NCHARSIN);
	result = *((uint32 *)DLX_KBD_GETCHAR);
	printf ("Got a keyboard interrupt (char=0x%x(%c), nleft=%d)!\n",
		result, result, i);
      } while (i > 1);
      break;
    case TRAP_ACCESS:
      printf ("Exiting after illegal access at iar=0x%x, isr=0x%x\n", iar, isr);
      exitsim ();
      break;
    case TRAP_ADDRESS:
      printf ("Exiting after illegal address at iar=0x%x, isr=0x%x\n",
	      iar, isr);
      exitsim ();
      break;
    case TRAP_ILLEGALINST:
      printf ("Exiting after illegal instruction at iar=0x%x, isr=0x%x\n",
	      iar, isr);
      exitsim ();
      break;
    case TRAP_PAGEFAULT:
      MemoryPageFaultHandler(currentPCB);
      break;
    default:
      printf ("Got an unrecognized system interrupt (0x%x) - exiting!\n",
	      cause);
      exitsim ();
      break;
    }
  }
  dbprintf ('t',"About to return from dointerrupt.\n");
  // Note that this return may schedule a new process!
  intrreturn ();
}