Exemplo n.º 1
0
int k_release_processor()
{
    current_process->process_state=READY; //set state of process to ready;
    int retCode=rpq_enqueue(current_process);//enqueue onto ready queue;
    process_switch();
    return retCode;
}
Exemplo n.º 2
0
/**
 * @brief release_processor(). 
 * @return RTX_ERR on error and zero on success
 * POST: gp_current_process gets updated to next to run process
 */
int k_release_processor(void)
{
	PCB *p_pcb_old = NULL;
	int time;
	#ifdef TIMING
	start_timer();
	#endif
	
	if (gp_current_process != NULL && gp_current_process->m_priority < pq_peak(ready_queue)->m_priority && gp_current_process->m_state!=BLK && gp_current_process->m_state!=BLK_RCV) {
	#ifdef DEBUG_0 
		//printf("remaining on process %d\n", gp_current_process->m_pid);
	#endif /* ! DEBUG_0 */
		return RTX_OK;
	}
	
	p_pcb_old = gp_current_process;
	gp_current_process = scheduler();
	
	if ( gp_current_process == NULL  ) {
		gp_current_process = p_pcb_old; // revert back to the old process
		return RTX_ERR;
	}
	
  if ( p_pcb_old == NULL) {
		p_pcb_old = gp_current_process;
	}
	
	process_switch(p_pcb_old);
	#ifdef TIMING
	time = end_timer();
	#endif
	return RTX_OK;
}
Exemplo n.º 3
0
VOID process_switch_if_there_is_a_higher_priority_process()
{
  if ((SINT32)next_priority() < (SINT32)currentRunningProcess->priority)
  {
    currentRunningProcess->state = READY;
    process_switch();
  }
}
Exemplo n.º 4
0
// I PROCESSES
void i_process_switch(PCB *i_process) {
	PCB *p_pcb_old = NULL;
	p_pcb_old = gp_current_process;
	gp_current_process = i_process;
	if (i_process->state != NEW) {
		i_process->state = READY;
	}
	process_switch(p_pcb_old);
}
Exemplo n.º 5
0
struct thread *syscall_exit(struct thread *image) {

	if (image->proc->pid == 1) {
		debug_panic("init died");
	}

	process_switch(process_get(1));
	process_kill(image->proc);

	return thread_switch(image, schedule_next());
}
Exemplo n.º 6
0
msg_envelope * k_request_msg_env()
{
    msg_envelope *temp = msg_dequeue(free_env_Q);
    while (temp==NULL)
    {
		printf("k_request_msg_env: Process %i got blocked\n", current_process->process_id); 
		fflush(stdout); 
		current_process->process_state = BLOCKED_ON_RECEIVE;
		blocked_on_resource_Q_enqueue(current_process);
		process_switch();
    }
    return temp;
}
Exemplo n.º 7
0
/**
 * @brief release_processor(). 
 * @return RTX_ERR on error and zero on success
 * POST: gp_current_process gets updated to next to run process
 */
int k_release_processor(void)
{
	PCB *p_pcb_old = NULL;
	
	p_pcb_old = gp_current_process;
	gp_current_process = scheduler();
	
	if ( gp_current_process == NULL  ) {
		gp_current_process = p_pcb_old; // revert back to the old process
		return RTX_ERR;
	}
        if ( p_pcb_old == NULL ) {
		p_pcb_old = gp_current_process;
	}
	process_switch(p_pcb_old);
	return RTX_OK;
}
Exemplo n.º 8
0
msg_envelope * k_receive_message()
{	
	printf("k_receive_message: Process %i calls receive\n", current_process->process_id); 
	fflush(stdout);
	while ( current_process->msg_envelope_q.size == 0)
	{
		if (current_process->process_priority == IPROCESS)
			return NULL;
		else {
			printf("k_receive_message: Process %i got blocked\n", current_process->process_id); 
			fflush(stdout); 
			current_process->process_state = BLOCKED_ON_RECEIVE;
			process_switch();
			printf("k_receive_message: Process %i resumes with msg q size: %i\n", current_process->process_id, current_process->msg_envelope_q.size);
			fflush(stdout);
		}
	}
	msg_queue *temp_queue;
	temp_queue = &current_process->msg_envelope_q;
	msg_envelope *temp_envelope = (msg_envelope *) msg_dequeue(temp_queue);
	//printf("k_receive_message: Sender id is %i",temp_envelope->sender_pid);
	//store the details of this receive transaction on the receive_trace_buffer
	/*if (send_tr_buf->index == 15) {
		//If the trace buffer is full
		int i;
		for (i = 0; i <receive_tr_buf->index; i++){
			//Shift the stored data by 1 unit
			receive_tr_buf->receive_trace_buffer_array[i].sender_pid = receive_tr_buf->receive_trace_buffer_array[i+1].sender_pid;
			receive_tr_buf->receive_trace_buffer_array[i].receiver_pid = receive_tr_buf->receive_trace_buffer_array[i+1].receiver_pid;
			receive_tr_buf->receive_trace_buffer_array[i].time = receive_tr_buf->receive_trace_buffer_array[i+1].time;
		}

		receive_tr_buf->receive_trace_buffer_array[15].sender_pid = temp_envelope->sender_pid;
		receive_tr_buf->receive_trace_buffer_array[15].receiver_pid = temp_envelope->receiver_pid;
		receive_tr_buf->receive_trace_buffer_array[15].time = kernel_clock;
	} else {
		receive_tr_buf->index++;
		receive_tr_buf->receive_trace_buffer_array[receive_tr_buf->index].sender_pid = temp_envelope->sender_pid;
		receive_tr_buf->receive_trace_buffer_array[receive_tr_buf->index].receiver_pid = temp_envelope->receiver_pid;
		receive_tr_buf->receive_trace_buffer_array[receive_tr_buf->index].time = kernel_clock;
	}*/
	return temp_envelope;
}
Exemplo n.º 9
0
void scheduler_yield(void) {
  struct process* next = NULL;
  assert(current_process != NULL);

  // Find the next runnable process and switch to it.
  next = current_process->next;
  while (next != current_process) {
    assert(next != NULL);
    if (next->state == PROCESS_ALIVE) {
      LOG("pid %d yields to pid %d\n", current_process->pid, next->pid);
      process_switch(&current_process->tss, &next->tss);
      LOG("pid %d returns from pid %d\n", current_process->pid, next->pid);
      return;
    }
    next = next->next;
  }

  // This should only happen when the current process is the idle process.
  // LOG("no process to yield to\n");
}
Exemplo n.º 10
0
struct thread *syscall_exit(struct thread *image) {
	struct thread *new_image;
	uint16_t pid;
	uint32_t parent;

	pid = image->proc->pid;

	if (pid == 1) {
		debug_panic("init died");
	}

	parent = image->proc->parent->pid;

	process_switch(process_get(1));

	new_image = thread_send(image, parent, PORT_CHILD, NULL);

	image->proc->status = image->eax;
	process_kill(image->proc);

	return new_image;
}
Exemplo n.º 11
0
static int
process_sensors(int level, picl_nodehdl_t nodeh)
{
    picl_nodehdl_t  childh;
    picl_nodehdl_t  nexth;

    char            propname[PICL_PROPNAMELEN_MAX];
    char            propclass[PICL_CLASSNAMELEN_MAX];
    picl_errno_t    error_code;

    level++;

    DEBUGMSGTL(("ucd-snmp/lmSensors","in process_sensors() level %d\n",level));

    /* look up first child node */
    error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh,
                                        sizeof (picl_nodehdl_t));
    if (error_code != PICL_SUCCESS) {
                DEBUGMSGTL(("ucd-snmp/lmSensors",
                           "picl_get_propval_by_name(%s) %d\n",
                           PICL_PROP_CHILD, error_code));
                return (error_code);
    }

    /* step through child nodes, get the name first */
    while (error_code == PICL_SUCCESS) {

        error_code = picl_get_propval_by_name(childh, PICL_PROP_NAME,
                                               propname, (PICL_PROPNAMELEN_MAX - 1));
        if (error_code != PICL_SUCCESS) {  /*we found a node with no name.  Impossible.! */
            DEBUGMSGTL(("ucd-snmp/lmSensors",
                       "picl_get_propval_by_name(%s) = %d\n",
                       PICL_PROP_NAME, error_code));
            return (error_code);
        }

        error_code = picl_get_propval_by_name(childh, PICL_PROP_CLASSNAME,
                                                propclass, sizeof (propclass));
        if (error_code != PICL_SUCCESS) {  /*we found a node with no class.  Impossible.! */
            DEBUGMSGTL(("ucd-snmp/lmSensors",
                       "picl_get_propval_by_name(%s) = %d\n",
                       PICL_PROP_CLASSNAME, error_code));
            return (error_code);
        }

        DEBUGMSGTL(("ucd-snmp/lmSensors","found %s of class %s\n",propname,propclass)); 

        if (strstr(propclass,"fan-tachometer"))
           process_individual_fan(childh,propname);
        else if (strstr(propclass,"fan"))
            process_newtype_fan(childh,propname);
        else if (strstr(propclass,"temperature-sensor"))
            process_temperature_sensor(childh,propname);
        else if (strstr(propclass,"voltage-sensor"))
            process_voltage_sensor(childh,propname);
        else if (strstr(propclass,"digital-sensor"))
            process_digital_sensor(childh,propname);
        else if (strstr(propclass,"switch"))
            process_switch(childh,propname);
        else if (strstr(propclass,"led"))
            process_led(childh,propname);
        else if (strstr(propclass,"i2c"))
            process_i2c(childh,propname);
/*
        else if (strstr(propclass,"gpio"))
            process_gpio(childh,propname); 
*/


        /* look for children of children (note, this is recursive) */
       if (!(strstr(propclass,"picl") && 
             (strstr(propname,"frutree") || strstr(propname,"obp")))) {
           error_code = process_sensors(level,childh);
           DEBUGMSGTL(("ucd-snmp/lmSensors",
                      "process_sensors(%s) returned %d\n",
                       propname, error_code));
        }

         /* get next child node at this level*/
        error_code = picl_get_propval_by_name(childh, PICL_PROP_PEER,
                                   &nexth, sizeof (picl_nodehdl_t));
        if (error_code != PICL_SUCCESS) {/* no more children - buh bye*/
           DEBUGMSGTL(("ucd-snmp/lmSensors","Process sensors is out of children!  Returning...\n"));
           return (error_code);
        }

        childh = nexth;

    } /* while */
    return (error_code);
} /* process sensors */
Exemplo n.º 12
0
struct thread *init(struct multiboot *mboot, uint32_t mboot_magic) {
	struct process *idle, *init;
	struct module *module;
	struct memory_map *mem_map;
	size_t mem_map_count, i, addr;
	uintptr_t boot_image_size;
	void *boot_image;
	struct elf32_ehdr *init_image;
	struct elf32_ehdr *dl_image;

	/* initialize debugging output */
	debug_init();
	debug_printf("Rhombus Operating System Kernel v0.8a\n");

	/* check multiboot header */
	if (mboot_magic != 0x2BADB002) {
		debug_panic("bootloader is not multiboot compliant");
	}

	/* touch pages for the kernel heap */
	for (i = KSPACE; i < KERNEL_HEAP_END; i += SEGSZ) {
		page_touch(i);
	}

	/* identity map kernel boot frames */
	for (i = KSPACE + KERNEL_BOOT; i < KSPACE + KERNEL_BOOT_END; i += PAGESZ) {
		page_set(i, page_fmt(i - KSPACE, PF_PRES | PF_RW));
	}

	/* parse the multiboot memory map to find the size of memory */
	mem_map       = (void*) (mboot->mmap_addr + KSPACE);
	mem_map_count = mboot->mmap_length / sizeof(struct memory_map);

	for (i = 0; i < mem_map_count; i++) {
		if (mem_map[i].type == 1 && mem_map[i].base_addr_low <= 0x100000) {
			for (addr = 0; addr < mem_map[i].length_low; addr += PAGESZ) {
				frame_add(mem_map[i].base_addr_low + addr);
			}
		}
	}

	/* bootstrap process 0 (idle) */
	idle = process_alloc();
	idle->space = cpu_get_cr3();
	idle->user  = 0;

	/* fork process 1 (init) and switch */
	init = process_clone(idle, NULL);
	process_switch(init);

	/* get multiboot module information */
	if (mboot->mods_count < 3) {
		if (mboot->mods_count < 2) {
			if (mboot->mods_count < 1) {
				debug_panic("no boot or init or dl modules found");
			}
			else {
				debug_panic("no boot or dl modules found");
			}
		}
		else {
			debug_panic("no dl module found");
		}
	}
	module     = (void*) (mboot->mods_addr + KSPACE);
	init_image = (void*) (module[0].mod_start + KSPACE);
	boot_image = (void*) (module[1].mod_start + KSPACE);
	dl_image   = (void*) (module[2].mod_start + KSPACE);
	boot_image_size = module[1].mod_end - module[1].mod_start;

	/* move boot image to BOOT_IMAGE in userspace */
	mem_alloc(BOOT_IMAGE, boot_image_size, PF_PRES | PF_USER | PF_RW);
	memcpy((void*) BOOT_IMAGE, boot_image, boot_image_size);

	/* bootstrap thread 0 in init */
	thread_bind(init->thread[0], init);
	init->thread[0]->useresp = init->thread[0]->stack + SEGSZ;
	init->thread[0]->esp     = (uintptr_t) &init->thread[0]->num;
	init->thread[0]->ss      = 0x23;
	init->thread[0]->ds      = 0x23;
	init->thread[0]->cs      = 0x1B;
	init->thread[0]->eflags  = cpu_get_eflags() | 0x3200; /* IF, IOPL = 3 */

	/* bootstrap idle thread */
	idle->thread[0] = &__idle_thread;
	__idle_thread.proc = idle;

	/* load dl */
	if (elf_check_file(dl_image)) {
		debug_panic("dl.so is not a valid ELF executable");
	}
	elf_load_file(dl_image);

	/* execute init */
	if (elf_check_file(init_image)) {
		debug_panic("init is not a valid ELF executable");
	}
	elf_load_file(init_image);
	init->thread[0]->eip = init_image->e_entry;

	/* register system calls */
	int_set_handler(SYSCALL_SEND, syscall_send);
	int_set_handler(SYSCALL_DONE, syscall_done);
	int_set_handler(SYSCALL_WHEN, syscall_when);
	int_set_handler(SYSCALL_RIRQ, syscall_rirq);
	int_set_handler(SYSCALL_ALSO, syscall_also);
	int_set_handler(SYSCALL_STAT, syscall_stat);
	int_set_handler(SYSCALL_PAGE, syscall_page);
	int_set_handler(SYSCALL_PHYS, syscall_phys);
	int_set_handler(SYSCALL_FORK, syscall_fork);
	int_set_handler(SYSCALL_EXIT, syscall_exit);
	int_set_handler(SYSCALL_STOP, syscall_stop);
	int_set_handler(SYSCALL_WAKE, syscall_wake);
	int_set_handler(SYSCALL_GPID, syscall_gpid);
	int_set_handler(SYSCALL_TIME, syscall_time);
	int_set_handler(SYSCALL_USER, syscall_user);
	int_set_handler(SYSCALL_AUTH, syscall_auth);
	int_set_handler(SYSCALL_PROC, syscall_proc);
	int_set_handler(SYSCALL_KILL, syscall_kill);
	int_set_handler(SYSCALL_VM86, syscall_vm86);
	int_set_handler(SYSCALL_NAME, syscall_name);
	int_set_handler(SYSCALL_REAP, syscall_reap);

	/* register fault handlers */
	int_set_handler(FAULT_DE, fault_float);
	int_set_handler(FAULT_DB, fault_generic);
	int_set_handler(FAULT_NI, fault_generic);
	int_set_handler(FAULT_BP, fault_generic);
	int_set_handler(FAULT_OF, fault_generic);
	int_set_handler(FAULT_BR, fault_generic);
	int_set_handler(FAULT_UD, fault_generic);
	int_set_handler(FAULT_NM, fault_nomath);
	int_set_handler(FAULT_DF, fault_double);
	int_set_handler(FAULT_CO, fault_float);
	int_set_handler(FAULT_TS, fault_generic);
	int_set_handler(FAULT_NP, fault_generic);
	int_set_handler(FAULT_SS, fault_generic);
	int_set_handler(FAULT_GP, fault_gpf);
	int_set_handler(FAULT_PF, fault_page);
	int_set_handler(FAULT_MF, fault_float);
	int_set_handler(FAULT_AC, fault_generic);
	int_set_handler(FAULT_MC, fault_generic);
	int_set_handler(FAULT_XM, fault_nomath);

	/* start timer (for preemption) */
	timer_set_freq(64);

	/* initialize FPU/MMX/SSE */
	cpu_init_fpu();

	/* drop to usermode, scheduling the next thread */
	debug_printf("dropping to usermode\n");
	return thread_switch(NULL, schedule_next());
}
Exemplo n.º 13
0
static int
process_sensors(picl_nodehdl_t nodeh)
{
    picl_nodehdl_t  childh;
    picl_nodehdl_t  nexth;

    char            propname[PICL_PROPNAMELEN_MAX];
    char            propclass[PICL_CLASSNAMELEN_MAX];
    picl_errno_t    error_code;

    /* look up first child node */
    error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh,
                                        sizeof (picl_nodehdl_t));
    if (error_code != PICL_SUCCESS) {
                return (error_code);
    }

    /* step through child nodes, get the name first */
    while (error_code == PICL_SUCCESS) {
        error_code = picl_get_propval_by_name(childh, PICL_PROP_NAME,
                                               propname, (PICL_PROPNAMELEN_MAX - 1));
        if (error_code != PICL_SUCCESS) {  /*we found a node with no name.  Impossible.! */
            return (error_code);
        }

        if (strcmp(propname,PICL_NODE_PLATFORM)==0){ /*end of the chain*/
                return (255);
        }

        error_code = picl_get_propval_by_name(childh, PICL_PROP_CLASSNAME,
                                                propclass, sizeof (propclass));
        if (error_code != PICL_SUCCESS) {  /*we found a node with no class.  Impossible.! */
            return (error_code);
        }

/*        DEBUGMSGTL(("ucd-snmp/lmSensors","found %s of class %s\n",propname,propclass)); */

        if (strstr(propclass,"fan-tachometer"))
            process_individual_fan(childh,propname);
        if (strstr(propclass,"temperature-sensor"))
            process_temperature_sensor(childh,propname);
        if (strstr(propclass,"digital-sensor"))
            process_digital_sensor(childh,propname);
        if (strstr(propclass,"switch"))
            process_switch(childh,propname);
        if (strstr(propclass,"led"))
            process_led(childh,propname);
        if (strstr(propclass,"i2c"))
            process_i2c(childh,propname);
/*
        if (strstr(propclass,"gpio"))
            process_gpio(childh,propname); 
*/


           /* look for children of children (note, this is recursive) */
 
        if (process_sensors(childh) == PICL_SUCCESS) {
            return (PICL_SUCCESS);
        }

          /* get next child node at this level*/
        error_code = picl_get_propval_by_name(childh, PICL_PROP_PEER,
                                        &nexth, sizeof (picl_nodehdl_t));
        if (error_code != PICL_SUCCESS) {/* no more children - buh bye*/
            return (error_code);
        }

        childh = nexth;

    } /* while */
    return (error_code);
} /* process sensors */
Exemplo n.º 14
0
int main()
{
 #ifdef _DEBUG
  rtx_dbug_outs((CHAR *)"rtx: Entering main()\r\n");
#endif


  /* get the third party test proc initialization info */
  __REGISTER_TEST_PROCS_ENTRY__();

  /* The following  is just to demonstrate how to reference
   * the third party test process entry point inside rtx.
   * Your rtx should NOT call the test process directly!!!
   * Instead, the scheduler picks the test process to run
   * and the os context switches to the chosen test process
   */

   /* Load the vector table for TRAP #0 with our assembly stub
       address */
   asm( "move.l #asm_trap_entry,%d0" );
   asm( "move.l %d0,0x10000080" );

  //UINT32 turn = 100;
  //CALL_TRAP(SEND_MESSAGE_TRAP_CALL, 300,200,100, turn);

  //g_test_proc[0].entry(); /* DO NOT invoke test proc this way !!*/

  // Assign the start of free memory
  // (so we can start initializations that require memory.)
  freeMemoryBegin = &__end + 2; // Add two because __end is used.

  int diff = ((UINT32)freeMemoryBegin)%4;
  if (diff != 0){
    freeMemoryBegin  += (4-diff);
  }

  rtx_memset(freeMemoryBegin, 0, (char*)0x10200000 - freeMemoryBegin);

  init_user_heap();
 #ifdef _DEBUG
  rtx_dbug_outs((CHAR *)"Created user heap.\r\n");
#endif


  MemoryPool_init();
 #ifdef _DEBUG
  rtx_dbug_outs((CHAR *)"Created memory pool.\r\n");
#endif


  initialize(register_sys_proc(), create_user_table());
 #ifdef _DEBUG
  rtx_dbug_outs((CHAR *)"Initialization finished.\r\n");
#endif


          int b;
        asm ("move.w %%sr, %0;":"=r"(b)  );    
rtx_dbug_out_number(b);		

  //UINT32 mask;
     /*
     * Set the interupt mask
     */
    //mask = SIM_IMR;
    //mask &= 0x0003ddff;
    //SIM_IMR = mask;
  process_switch();


  return 0;
}