Exemplo n.º 1
0
void setdate()
{
	serial_println("What day of the week is it?");
    char *response = polling();
  	char *bcdweekday = fromweekday(response);
    unsigned char portnum = 0x06; //weekday port
    writetoRTC(portnum, bcdweekday);

    serial_println("What month is it?");
    response = polling();
  	char *bcdmonth = frommonth(response);
    portnum = 0x08; //month port
  	writetoRTC(portnum, bcdmonth);

    serial_println("What day of the month is it?");
    response = polling();
    portnum = 0x07; //month day port
  	writetoRTC(portnum, response);

    serial_println("What year is it?");
    response = polling();
  	char *bcdyear = sys_alloc_mem(2);
  	if (strlen(response) != 4 || atoi(response) < 2000) {
  		bcdyear[0] = '\0';
  	} else {
  		bcdyear[0] = response[2];
  		bcdyear[1] = response[3];
  	}
    portnum = 0x09;
    writetoRTC(portnum, bcdyear);

    serial_print("Time successfully changed to -> ");
    getdate();
    sys_free_mem(response);
    sys_free_mem(bcdweekday);
    sys_free_mem(bcdmonth);
    sys_free_mem(bcdyear);
}
Exemplo n.º 2
0
void settime()
{
	serial_println("What is the current hour?");
    char *response = polling();
    unsigned char portnum = 0x04; //hours port
    writetoRTC(portnum, response);

    serial_println("What is the current minute?");
    response = polling();
    portnum = 0x02; //minutes port
    writetoRTC(portnum, response);

    serial_println("What is the current second?");
    response = polling();
    portnum = 0x00; //seconds port
    writetoRTC(portnum, response);

    serial_print("Time successfully changed to -> ");
    gettime();
    sys_free_mem(response);
}
Exemplo n.º 3
0
void gettime()
{
	outb(0x70, 0x04);
	unsigned char bcdtime = inb(0x71);
	char *convtime = sys_alloc_mem(5);
	fromBCD(bcdtime, convtime);
    serial_print(convtime);
    serial_print(":");

    outb(0x70, 0x02);
    bcdtime = inb(0x71);
    fromBCD(bcdtime, convtime);
    serial_print(convtime);
    serial_print(":");

    outb(0x70, 0x00);
    bcdtime = inb(0x71);
    fromBCD(bcdtime, convtime);
    serial_println(convtime);
    serial_println("");
    sys_free_mem(convtime);
}
Exemplo n.º 4
0
void prompt(){

  //declare variables.
	int retValue,i, result;
	char *command, *input, *arg;
	PCB * thisPCB;
  MainShell->isRunning = 1; // set isRunning to true.
  MainShell->prompt = ":>";	
  
 
	write("WELCOME to MPX \n");
    write("Type HELP for a command list\n\n");
	while(MainShell->isRunning){ //loop while MainShell is running.

		write(MainShell->prompt); //prompt user for input.
		
		
		input = trim(read(100)); //read input and trim it.

		command = strtok(input, " ,-|");//grab command from input.

    result = executeCommand(EXEC, command); //execute command.

    if(strcmpi(command, "exit") == 0){
	write("Exiting..\n");
	MainShell->isRunning = 0; //catch exit command.
	cleanR2();
	
		dispatcher();
	}
    if(result == 0 && strlen(input) != 0) write("Command not found!\n"); //command not valid
	
	
	sys_free_mem(input);
	
	sys_req(IDLE, NO_DEV, NULL, 0);
	}

}
Exemplo n.º 5
0
//Frees the memory of the PCB
void freePCB(PCB *pcb){
	sys_free_mem(pcb);
	sys_free_mem(pcb->stackBottom);
}
Exemplo n.º 6
0
void interrupt sys_call(void){

	static IOD *temp;
	
	//Saves the ss and sp register to a temp storage
	ss_save2 = _SS;
	sp_save2 = _SP;
	COP->stack = (unsigned char *)MK_FP(ss_save2,sp_save2);
	//Updates the stacktop for context switch
	
	
	//Access Parameters that sys_req placed on the stack
	param_ptr = (params*)(COP->stack+sizeof(context));
	
	//Switching to a temp stack
	new_ss = FP_SEG(sys_stack);
	new_sp = FP_OFF(sys_stack)+ SYS_STACK_SIZE;
	_SS = new_ss;
	_SP = new_sp;
	
	trm_getc();
	
	if(TerminalQueue->event_flag==1 && TerminalQueue->count > 0){
		TerminalQueue->event_flag = 0;
		temp = TerminalQueue->head;
		TerminalQueue->head = TerminalQueue->head->next;
		unblockPCB(temp->ppt->processName);
		sys_free_mem(temp);
		TerminalQueue->count--;
		if(TerminalQueue->count!=0){
			ProcessIORequest(1);
		}
	}
	if(Com_PortQueue->event_flag==1 && Com_PortQueue->count > 0){
		Com_PortQueue->event_flag = 0;
		temp = Com_PortQueue->head;
		Com_PortQueue->head = Com_PortQueue->head->next;
		unblockPCB(temp->ppt->processName);
		sys_free_mem(temp);
		Com_PortQueue->count--;
		if(Com_PortQueue->count!=0){
			ProcessIORequest(1);
		}
	}
	
	//Process is idle
	if (param_ptr -> op_code == IDLE){
		//Sets state to running and adds it back into the readyQueue
		COP -> state = 2; 
		PriorityEnqueue(readyQueue,COP);
	}
	//Process is completed and ready for deletion 
	if (param_ptr -> op_code == EXIT){
		//Frees the memory of the PCB and sets the PCB to NULL
		freePCB(COP);
		COP = NULL;
	}
	if (param_ptr -> op_code == READ ||param_ptr -> op_code == WRITE ||param_ptr -> op_code == CLEAR ||param_ptr -> op_code == GOTOXY ){
		IOScheduler();
	}
	//Dispatches the next process in the readyQueue
	dispatch();
}
Exemplo n.º 7
0
void comhandle()
{
	serial_println("");
	serial_println("Welcome to the MPX OS.");
	serial_println("Feel free to begin entering commands.");
	serial_println("");
	while(1) {
		sys_req(IDLE);
		char *command = polling();
		if (!strcmpigncase(command, "shutdown")) {
			if (shutdownConfirmed()) {
				serial_println("System shutting down...");
				clearAllQueues();
				break;
			} else {
				serial_println("Shutdown canceled.");
			}
		} else if (!strcmpigncase(command, "version")) {
			version();
		} else if (!strcmpigncase(command, "help")) {
			help();
		} else if (!strcmpigncase(command, "setdate")) {
			setdate();
		} else if (!strcmpigncase(command, "getdate")) {
			getdate();
		} else if (!strcmpigncase(command, "settime")) {
			settime();
		} else if (!strcmpigncase(command, "gettime")) {
			gettime();
		} else if (!strcmpigncase(command, "suspend")) {
			suspendPCB();
		} else if (!strcmpigncase(command, "resume")) {
			resumePCB();
		} else if (!strcmpigncase(command, "setpriority")) {
			setPriority();
		} else if (!strcmpigncase(command, "showPCB")) {
		        showPCB();
		} else if (!strcmpigncase(command, "deletePCB")) {
			deletePCB();
		} else if (!strcmpigncase(command, "showReady")) {
		        showReady();
		} else if (!strcmpigncase(command, "showBlocked")) {
		        showBlocked();
		} else if (!strcmpigncase(command, "showAll")) {
		        showAll();
		} else if (!strcmpigncase(command, "loadr3")) {
		        loadR3();
		} else if (!strcmpigncase(command, "allocate")) {
			allocateMem();
		} else if (!strcmpigncase(command, "freeMemory")) {
			freeMem();
		} else if (!strcmpigncase(command, "printAlloc")) {
			printAlloc();
		} else if (!strcmpigncase(command, "printFree")) {
			printFree();
		} else if (!strcmpigncase(command, "isEmpty")) {
			isEmpty();
		} else if (strcmp(command, '\0')) {
			serial_println("Command not recognized. Type help to view commands.");
			serial_println("");
		}
		sys_free_mem(command);
	}
	sys_req(EXIT);
}
Exemplo n.º 8
0
void help()
{
	while(1) {
		serial_println("Which command would you like to know more about?");
		serial_println("Enter \"commands\" for a list of commands.");
		serial_println("Enter \"quit\" to exit.");
		char *command = polling();
		if (!strcmpigncase(command, "commands")) {
			serial_println("Here's a list of available commands:");
			serial_println("Version");
			serial_println("Help");
			serial_println("Setdate");
			serial_println("Getdate");
			serial_println("Settime");
			serial_println("Gettime");
			serial_println("Shutdown");
			serial_println("Suspend");
			serial_println("Resume");
			serial_println("SetPriority");
			serial_println("ShowPCB");
			serial_println("ShowAll");
			serial_println("ShowReady");
			serial_println("ShowBlocked");
			serial_println("Loadr3");
			serial_println("Allocate");
			serial_println("printFree");
			serial_println("printAlloc");
			serial_println("freeMemory");
			serial_println("");
		}
		else if (!strcmpigncase(command, "quit")) {
			break;
		}
		else if (!strcmpigncase(command, "allocate")) {
			serial_println("Allocates the specified amount of memory from the heap.");
			break;
		}
		else if (!strcmpigncase(command, "printfree")) {
			serial_println("Displays a list of all free memory blocks, along with basic information.");
			break;
		}
		else if (!strcmpigncase(command, "printalloc")) {
			serial_println("Displays a list of all allocated memory blocks, along with basic information.");
			break;
		}
		else if (!strcmpigncase(command, "freememory")) {
			serial_println("Frees an allocated memory block with a specified address.");
			break;
		}
		else if (!strcmpigncase(command, "version")) {
			serial_println("Version shows the current version of the operating system, and it's release date.");
			break;
		}
		else if (!strcmpigncase(command, "help")) {
			serial_println("Help gets further help for a prompted command.");
			break;
		}
		else if (!strcmpigncase(command, "setdate")) {
			serial_println("Setdate allows the user to set the date of the operating system through a series of prompts.");
			serial_println("The prompt follows a format of yy mm dd.");
			break;
		}
		else if (!strcmpigncase(command, "getdate")) {
			serial_println("Getdate returns the current date of the operating system.");
			break;
		}
		else if (!strcmpigncase(command, "settime")) {
			serial_println("Settime allows the user to set the time of the operating system through a series of prompts.");
			serial_println("The prompt follows a format of HH MM SS.");
			break;
		}
		else if (!strcmpigncase(command, "gettime")) {
			serial_println("Gettime returns the current date of the operating system.");
			break;
		}
		else if (!strcmpigncase(command, "shutdown")) {
			serial_println("Shutdown presents the user with the option to terminate the system.");
			break;
		}
		else if (!strcmpigncase(command, "suspend"))  {
		  serial_println("Places a PCB in a suspended state and reinserts it into the appropriate queue.");
		  break;
		}

		else if (!strcmpigncase(command, "resume"))  {
		  serial_println("Places a PCB in in the not suspended state and reinserts it into the appropriate queue.");
		  break;
		}

		else if (!strcmpigncase(command, "setpriority"))  {
		  serial_println("Sets a PCB's priority and reinserts the process into the correct place in the correct queue");
		  break;
		}

		else if (!strcmpigncase(command, "showPCB"))  {
		  serial_println("Displays the following information for a PCB:");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "showall"))  {
		  serial_println("Displays the folling information for each PCB in the ready and blocked queues.");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "showready"))  {
		  serial_println("Displays the folling information for each PCB in the ready queue.");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "showblocked"))  {
		  serial_println("Displays the following information for each PCB in the blocked queue.");
		  serial_println("Process Name");
			serial_println("Class");
			serial_println("State");
			serial_println("Suspended Status");
			serial_println("Priority");
			serial_println("");
		  break;
		}

		else if (!strcmpigncase(command, "loadr3")) {
		  serial_println("Loads all r3 processes into memory in a ready blocked state. Used for testing of multiprogramming functionality.");
		  break;
		}

		else {
			serial_print("Unrecognized command: ");
			serial_println(command);
		}
		sys_free_mem(command);
	}
	serial_println("");
}