Exemplo n.º 1
0
void UART_i_Proc() {
	PCB *pcb;
	MSG_BUF *msg;
	Node *node;
	#ifdef DEBUG_0 
	printf("UART proc running\n");
	#endif /* ! DEBUG_0 */
	pcb = findPCB(PID_UART_IPROC);
	if (g_char_in != 0) {
		node = (Node*)k_nonblocking_request_memory_block();
		if (node != NULL) {
			msg = (MSG_BUF *)node;
			msg->m_send_pid = PID_UART_IPROC;
			msg->mtype = KEYBOARD_INPUT;
			msg->mtext[0] = g_char_in;
			g_char_in = 0;
			m_send_message(PID_KCD, PID_UART_IPROC, msg);
		}
	}
	msg = receive_message_nonblocking(pcb);
	while (msg != NULL) {
		if (msg->m_send_pid == PID_CRT) {
			uart_display_string((unsigned char *)msg->mtext);
			k_release_memory_block((void *)msg);
		}
		msg = receive_message_nonblocking(pcb); 
	}
}
Exemplo n.º 2
0
//Creates the PCB
void createPCB(char* processName, int PCBclass, int priority){
	char error[128];
	int len;
	PCB *pcbPointer;
	if (strlen(processName) > 8){
		//Name is too long
		print("Error: Incorrect Name to Many Characters \n");
	}else if (priority > 127){
		//Wrong priority
		print("Error: Incorrect Priority\n");
	}else if(priority < -128){
		//Wrong priority
		print("Error: Incorrect Priority\n");
	}else if ( PCBclass != 0 && PCBclass != 1){
		//Wrong Class
		print("Error: Incorrect Class\n");
	}else if (findPCB(processName)==NULL){
		//If no duplicate name
		pcbPointer = setupPCB(processName, PCBclass, priority);
		PriorityEnqueue(readyQueue,pcbPointer);
	}else{
		//If there is a duplicate name
		print("Error: Name is already in use.\n");
	}
}
Exemplo n.º 3
0
void showPCB() {
    serial_print("Please enter the name of the desired PCB to view: ");
    char* pcbName = polling();
    PCB* process = findPCB(pcbName);
    
    if (process == NULL) {
      serial_print(pcbName);
      serial_println(" is not a valid PCB");
      return;
    } 
    PrintPCB(process);
    sys_free_mem(pcbName);
    sys_free_mem(process);
}
Exemplo n.º 4
0
void InstallCommhand(){
	if (findPCB("COMMHAND")==NULL){
		COP = setupPCB("COMMHAND", 0 ,127); 
		aContext = (context*)COP -> stack;
		aContext -> IP = FP_OFF(&commhand);
		aContext -> CS = FP_SEG(&commhand);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP);
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'COMMHAND' is already in system\n");	
	}
}
Exemplo n.º 5
0
void setPCBpriority(char PCBName[20], int inputPriority){
	PCB *process = findPCB(PCBName); //find PCB
	if((inputPriority < -128) || (inputPriority > 127)){ 
		//if incorrect input priority
		print("Error: Invalid Priority: Must be between -128 and +127\n");
	}
	else if(process==NULL){
		print("Error: PCB not found\n");
	}
	else{ 
		removePCB(process);
		process -> priority = inputPriority;
		insertPCB(process);
		
	}
}
Exemplo n.º 6
0
void blockPCB(char PCBName[20]){
	PCB *process;
	int sus;//suspended
	int sta;//state
	process = findPCB(PCBName); //find PCB
	if(process==NULL){
		print("Error: PCB not found");	
	}
	else{//if found PCB
		//check state
		sus = (process->suspended);
		sta = (process->state);
		if(sta==0){//state is already blocked...
			print("Error: State is already blocked");
		}
		else if(sta==2){ //if PCB state is unblocked		
		
			if((sus==0)){ //if not suspended or suspended
			
				removePCB(process);//remove from readyQueue
				process->state = 0;//change state to blocked
				PriorityEnqueue(blockedQueue, process);//insert into blockedQueue

			}
			else if((sus==1)){
				removePCB(process);//remove from suspendedReadyQueue
				process->state = 0;//change state to blocked
				PriorityEnqueue(suspendedBlockedQueue, process);//insert into suspendedBlockedQueue

			}
			else{ //if invalid state
				print("Error suspended State is invalid");
			}
				
		}
		else if(sta==1){//if state is running		
			print("Error: PCB is running");		
		}
		else{
			print("Error: Suspended state invalid");
		}
	}
	
}
Exemplo n.º 7
0
void suspendPCB(char PCBName[20]){
	PCB *process;
	int sus;//suspended
	int sta;//state
	process = findPCB(PCBName); //find PCB
	if(process==NULL){
		print("Error: PCB not found");	
	}
	else{//if found PCB
	//check sus state
		sus = (process->suspended);
		sta = (process->state);
		if(sus==0){//if PCB is not suspended 
		
			if((sta==0)){ //if state is blocked
			
				removePCB(process);//remove from blockedQueue
				process->suspended = 1;//change state to suspended
				insertPCB(process);//insert into suspendedBlockedQueue

			}
			else if((sta==2)){
				removePCB(process);//remove from readyQueue
				process->suspended = 1;//change state to suspended
				insertPCB(process);//insert into suspendedReadyQueue

			}
			else if(sta==1){//if state is running		
				print("Error: PCB is running");		
			}
			else{//if state is invalid
				print("Error: PCB state is invalid");
			}
		}
		else if(sus==1){
			print("Error: Process is already suspended");
		}
		else{
			print("Error: Suspended state invalid");
		}
	}
}
Exemplo n.º 8
0
void setPriority()
{
	serial_print("Please enter the name of the process to alter: ");
	char* name = polling();
	PCB *target = findPCB(name);
	if(target == NULL)
	{
		serial_print("Process not found: \"");
		serial_print(name);
		serial_println("\" is not a valid process name");
	}
	else
	{
		serial_print("What is the new priority? ");
		char* newPriority = polling();
		int priority = atoi(newPriority);
		if(-1 < priority && 10 > priority)
		{
			target->priority = priority;
			int readyIndex = indexByNameReady(name);
			int blockedIndex = indexByNameBlocked(name);
			if (readyIndex >= 0) {
				removePCBAtIndexReady(readyIndex);
			} else {
				removePCBAtIndexBlocked(blockedIndex);
			}
			insertPCB(target);
			serial_print("The process \"");
			serial_print(name);
			serial_println("\" has successfully updated its priority");
		}
		else
		{
			serial_println("Cannot set priority: invalid range");
		}
		sys_free_mem(newPriority);
	}
	sys_free_mem(name);
	sys_free_mem(target);
	serial_println("");
}
Exemplo n.º 9
0
void resumePCB()
{
	serial_print("Please enter the name of the process to resume: ");
	char* name = polling();
	PCB *target = findPCB(name);
	if(target == NULL)
	{
		serial_print("Process not found: \"");
		serial_print(name);
		serial_println("\" is not a valid process name");
	}
	else
	{
		target->suspendedState = 0;
		serial_print("The process \"");
		serial_print(name);
		serial_println("\" has resumed successfully");
	}
	sys_free_mem(name);
	sys_free_mem(target);
	serial_println("");
}
Exemplo n.º 10
0
void Timer_i_Proc() {	
	PCB *pcb;
	Node *node;
	MSG_BUF *msg;
	pcb = findPCB(PID_TIMER_IPROC);
	msg = receive_message_nonblocking(pcb);
	while (msg != NULL) {
		msg->m_kdata[0] += g_timer_count;
		push_sorted_linkedlist(&timeout_queue, msg);
		msg = receive_message_nonblocking(pcb);
		#ifdef DEBUG_0
			printf("Timer proc added message to timeout queue");
		#endif
	}
	while (timeout_queue!=NULL && timeout_queue->m_kdata[0] <= g_timer_count){
		MSG_BUF *envelope = (MSG_BUF *)pop_linkedlist(&timeout_queue);
		int target_pid = envelope->m_recv_pid;
		#ifdef DEBUG_0
			printf("Time Proc sending delayed message to process %d\n\r", target_pid);
		#endif
		k_send_message(target_pid, envelope);
	}
}
Exemplo n.º 11
0
void deletePCB()
{
	serial_print("Please enter the name of the process to delete: ");
	char* name = polling();
	PCB* target = findPCB(name);
	if(target == NULL)
	{
		if(strlen(name) == 0) {
			serial_print("Process not found: \"");
			serial_print(name);
			serial_println("\" does not appear to exist");
		}
	}
	else
	{
		int readyIndex = indexByNameReady(name);
		int blockedIndex = indexByNameBlocked(name);
		PCB* removedPCB = NULL;
		if (readyIndex >- 0) {
			removedPCB = removePCBAtIndexReady(readyIndex);
		} else {
			removedPCB = removePCBAtIndexBlocked(blockedIndex);
		}
		FreePCB(removedPCB);
		// if (!FreePCB(removedPCB)) {
			serial_print("The process \"");
			serial_print(name);
			serial_print("\" has been deleted successfully");
		// } else {
		//	serial_print("An error occurred while attempting to remove the process \"");
		//	serial_print(name);
		//	serial_println("\"");
		//}
	}
	serial_println("");
}
Exemplo n.º 12
0
/**
 * Called when a signal is to be delivered to a process.
 * @param pid  the pid of the process to deliver the signal to
 * @param sig_no  the signal to deliver
 * @return 0 on success, -1 if PID is invalid, -2 if signal is invalid
 */
extern int signal(int pid, int sig_no) {
    kprintf("In signal()\n");
    if (!isValidSignalNumber(sig_no)) return -2;
    
    pcb* p = findPCB(pid);
    
    if (!p) return -1;
        
    int signalsWaiting = p->signalsWaiting;
    
    signalEntry* signal_entry = &p->signalTable[sig_no];
    funcptr handler = (funcptr)(signal_entry->handler);
    long old_sp = p->esp;
    
    
    unsigned int stackPos = p->esp;
    stackPos -= sizeof(signal_stack);
    signal_stack* signalStack = (signal_stack*)(stackPos);
    signalStack->handler = handler;
    signalStack->esp = old_sp;
    signalStack->ret = p->ret;
    signalStack->old_sp = old_sp;

        
    stackPos -= sizeof(context_frame);
    context_frame* contextFrame = (context_frame*)(stackPos);
    contextFrame->ebp = stackPos;
    contextFrame->esp = stackPos;
    contextFrame->iret_eip = &sigtramp;
    contextFrame->iret_cs = getCS();
    contextFrame->eflags = 0x00003200;    
        
    p->esp = stackPos;
    
    kprintf("signalStack esp: %d, handler %d, old_sp %d, ret %d\n",
        signalStack->esp, signalStack->handler, signalStack->old_sp, signalStack->ret);
    
    kprintf("Handler: %d\n", handler);
    kprintf("context frame: %d; ebp: %d, esp: %d, eip: %d\n", 
            contextFrame, contextFrame->ebp, contextFrame->esp, contextFrame->iret_eip);
    
    
    /*
    if (!signalsWaiting) {
        kprintf("No signals waiting\n");
        // Nothing waiting
        context_frame* contextFrame = kmalloc(256);
        signalEntry* signal_entry = &p->signalTable[sig_no];
        funcptr handler = (funcptr)(signal_entry->handler);
        long old_sp = p->esp + 24;
        sigtramp(handler, contextFrame, old_sp);
        kprintf("called sigtramp...\n");
    } else if (signalsWaiting >= sig_no) {
        // place on wait list
    } else {
        // interrupt other signals
    }
    */
    
    return 0;
}
Exemplo n.º 13
0
void PCBToString(char PCBName[20],char printArray[10000]){
		//shows the contains of the certain PCB that was inserted
	
	int pri; //priority
	int sus; //suspend
	int sta; //states
	int class1; 
	char statement[128]; 
	int len;
	char susWord[128];
	char staWord[128];
	char classWord[128];
	PCB *pcbPointer;
	char priString[4];
	
	//find all the properties and initializing to variables
	pcbPointer = findPCB(PCBName);
	pri = pcbPointer->priority;
	sus = pcbPointer->suspended;
	sta = pcbPointer->state;
	class1 =pcbPointer->PCBclass;
	
	//sets all numbers to the current associated words
	if(sus==0){
		strcpy(susWord,"Resumed");
	}
	else if(sus==1){
		strcpy(susWord,"Suspended");
	}
	else{
		strcpy(susWord,"No sus State found");
	}
	
	if(sta==0){
		strcpy(staWord,"Blocked");
	}
	else if(sta==1){
		strcpy(staWord,"Running");
	}
	else if(sta==2){
		strcpy(staWord,"Ready");
	}
	else{
		strcpy(staWord,"No state found");
	}
	
	if(class1==0){
		strcpy(classWord,"System");
	}
	else if(class1==1){
		strcpy(classWord,"Application");
	}
	else{
		strcpy(classWord,"No Class found");
	}
	sprintf(priString,"%d",pri);
	
	//prints to terminate
	strcpy(printArray,"Name: ");
	strcat(printArray,PCBName);
	strcat(printArray," \nClass: ");
	strcat(printArray,classWord);
	strcat(printArray," \nPriority: ");
	strcat(printArray,priString);
	strcat(printArray," \nSuspended: ");
	strcat(printArray,susWord);
	strcat(printArray," \nStates: ");
	strcat(printArray,staWord);
	strcat(printArray,"\n\n");
	//print(printArray);
}
Exemplo n.º 14
0
//Deletes the PCB from the MPX system
void deletePCB(char PCBName[20]){
	PCB *pcbPointer;
	pcbPointer = findPCB(PCBName);
	removePCB(pcbPointer);
	freePCB(pcbPointer);
}
Exemplo n.º 15
0
void load_proc() { 
	//Creates Process1 that contains the test process test1_R3 then adds it to the ready readyQueue
	if (findPCB("Process1")==NULL){
		COP = setupPCB("Process1", 1 ,0); 
		aContext = (context*)COP -> stack;
		aContext -> IP = FP_OFF(&test1_R3);
		aContext -> CS = FP_SEG(&test1_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP);
		print("Process1 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process1' is already in system\n");	
	}
	//Creates Process2 that contains the test process test2_R3 then adds it to the ready readyQueue
	if(findPCB("Process2")==NULL){
		COP = setupPCB("Process2", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test2_R3);
		aContext -> CS = FP_SEG(&test2_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP); 
		print("Process2 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process2' is already in system\n");	
	}
	
	//Creates Process3 that contains the test process test3_R3 then adds it to the ready readyQueue
	if(findPCB("Process3")==NULL){
		COP = setupPCB("Process3", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test3_R3);
		aContext -> CS = FP_SEG(&test3_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP);
		print("Process3 is now Loaded!\n");		
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process3' is already in system\n");	
	}
	
	//Creates Process4 that contains the test process test4_R3 then adds it to the ready readyQueue
	if(findPCB("Process4")==NULL){
	COP = setupPCB("Process4", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test4_R3);
		aContext -> CS = FP_SEG(&test4_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP); 
		print("Process4 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process4' is already in system\n");	
	}
	
	//Creates Process5 that contains the test process test5_R3 then adds it to the ready readyQueue
	if(findPCB("Process5")==NULL){
		COP = setupPCB("Process5", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test5_R3);
		aContext -> CS = FP_SEG(&test5_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP);
		print("Process5 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process5' is already in system\n");
		
	}
 }