Ejemplo n.º 1
0
void context_switch(){	
	pcb * transition;
	pcb * temp;
	
	atomic_up();	
	transition = running;
	transition->frame_ptr = old_fp;
	
	if(transition->next_process != NULL){
		ready_queue[prio] = ready_queue[prio]->next_process;
		temp = ready_queue[prio];
		while(temp->next_process != NULL){
			temp = temp->next_process;
		}
		temp->next_process = transition;
		transition->next_process = NULL;
	}
	transition->process_state = READY_STATE;
	
	clear_priority();
	
	while(1){
		if(ready_queue[prio] != NULL){
			if(ready_queue[prio]->process_state == READY_STATE){
				running = ready_queue[prio];
				running->process_state = RUNNING_STATE;
				old_fp = running->frame_ptr;
				atomic_down();
				return;
				
			} else if(ready_queue[prio]->process_state == NEW_STATE){
				running = ready_queue[prio];
				running->process_state = RUNNING_STATE;
				atomic_down();
				temp_sp = running->stack_ptr;
				asm("move.l temp_sp, %d0");
				asm("move.l %d0, %a7");
				process_bootstrap(running);
				return;
			}
			break;			
		} else {
			prio = (prio + 1) % 4;
		}
	}
	return;
}
Ejemplo n.º 2
0
/*
 * Initial boot sequence.
 */
static
void
boot(void)
{
	/*
	 * The order of these is important!
	 * Don't go changing it without thinking about the consequences.
	 *
	 * Among other things, be aware that console output gets
	 * buffered up at first and does not actually appear until
	 * dev_bootstrap() attaches the console device. This can be
	 * remarkably confusing if a bug occurs at this point. So
	 * don't put new code before dev_bootstrap if you don't
	 * absolutely have to.
	 *
	 * Also note that the buffer for this is only 1k. If you
	 * overflow it, the system will crash without printing
	 * anything at all. You can make it larger though (it's in
	 * dev/generic/console.c).
	 */

	kprintf("\n");
	kprintf("OS/161 base system version %s\n", BASE_VERSION);
	kprintf("%s", harvard_copyright);
	kprintf("\n");

	kprintf("Andrew K's system version %s (%s #%d)\n", 
		GROUP_VERSION, buildconfig, buildversion);
	kprintf("\n");

	ram_bootstrap();
	scheduler_bootstrap();
#if OPT_A2
    process_bootstrap();
#else // OPT_A2
	thread_bootstrap();
#endif
	vfs_bootstrap();
	dev_bootstrap();
	vm_bootstrap();
	kprintf_bootstrap();

	/* Default bootfs - but ignore failure, in case emu0 doesn't exist */
	vfs_setbootfs("emu0");


	/*
	 * Make sure various things aren't screwed up.
	 */
	assert(sizeof(userptr_t)==sizeof(char *));
	assert(sizeof(*(userptr_t)0)==sizeof(char));

	/* Assignment 0 Hello World Msg */
	#if OPT_A0
	    hello();
	#endif /* OPT_A0 */

    #if OPT_A2
        kprintf("Process %d initialized.\n", curproc->p_id);
        kprintf("Has parent id %d and thread named %s.\n", curproc->p_parent, curproc->p_thread->t_name);
    #endif // OPT_A2
}