コード例 #1
0
ファイル: user_a.c プロジェクト: solb/sysprogos
int main( void ) {
	int i, j, ch;

	c_puts( "User A running\n" );
	ch = writech( 'A' );
	if( ch != 'A' ) {
		c_printf( "User A, write 1 char '%c'\n", ch );
	}
	for( i = 0; i < 30; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		ch = writech( 'A' );
		if( ch != 'A' ) {
			c_printf( "User A, write 2 char '%c'\n", ch );
		}
	}

	c_puts( "User A exiting\n" );
	exit();

	ch = writech( 'a' );	/* shouldn't happen! */
	if( ch != 'a' ) {
		c_printf( "User A, write 3 char '%c'\n", ch );
	}
}
コード例 #2
0
ファイル: queue.c プロジェクト: HostClub/HostOS
void _q_dump( char *which, queue_t *queue ) {
	qnode_t *tmp;


	c_printf( "%s: ", which );
	if( queue == NULL ) {
		c_puts( "NULL???" );
		return;
	}

	c_printf( "head %08x tail %08x len %d comp %08x rem %08x\n",
		  queue->head, queue->tail, queue->length,
		  queue->compare, queue->remove );
	
	if( queue->length ) {
		c_puts( " i/s/p: " );
		for( tmp = queue->head; tmp != NULL; tmp = tmp->next ) {
			c_printf( " [%d/%d/0x%x]",
				((pcb_t *)(tmp->data))->pid,
				((pcb_t *)(tmp->data))->state,
				((pcb_t *)(tmp->data))->prio );
		}
		c_puts( "\n" );
	}

}
コード例 #3
0
ファイル: vmem.c プロジェクト: benrr101/sp2_derpos
void _vmem_init( void )
{
	//builds the first 4MB of memory
	Uint32 address = _vmem_first_4MB();
	_vmem_init_bitmap( address );
	//build the memeory mapped into every process
	_vmem_make_reserve();

	c_puts(" vmem" );
#ifdef _VMEM_DEBUG
	//*((Uint32*)0xD0000000) = 0x1234;
	_vmem_addresses_test();
	c_printf("Next availible address %x \n", _vmem_get_next_address());
	c_printf("Next availible 4MB address %x \n", _vmem_get_next_4MB_address());
	_vmem_set_address(0x3000000);
	c_printf("Next availible address %x \n", _vmem_get_next_address());
	c_printf("Next availible 4MB address %x \n", _vmem_get_next_4MB_address());
	_vmem_set_address(0x3001000);
	c_printf("Next availible address %x \n", _vmem_get_next_address());
	_vmem_set_address(0x3008000);
	c_printf("Next availible address %x \n", _vmem_get_next_address());
	_vmem_clear_address(0x3000000);
	c_printf("Next availible address %x \n", _vmem_get_next_address());
	_vmem_clear_address(0x3001000);
	_vmem_clear_address(0x3008000);
	_vmem_set_address(0x3300000);
	c_printf("Next availible 4MB address %x \n", _vmem_get_next_4MB_address());
#endif
	
}
コード例 #4
0
ファイル: clock.c プロジェクト: robopt/systems-programming
void _clock_modinit( void ) {
	uint32_t divisor;

	// start the pinwheel

	_pinwheel = _pindex = 0;

	// return to the epoch

	_system_time = 0;

	// set the clock to tick at CLOCK_FREQUENCY Hz.

	divisor = TIMER_FREQUENCY / CLOCK_FREQUENCY;
	__outb( TIMER_CONTROL_PORT, TIMER_0_LOAD | TIMER_0_SQUARE );
        __outb( TIMER_0_PORT, divisor & 0xff );        // LSB of divisor
        __outb( TIMER_0_PORT, (divisor >> 8) & 0xff ); // MSB of divisor

	// register the ISR

	__install_isr( INT_VEC_TIMER, _clock_isr );

        // announce that we have initialized the clock module

        c_puts( " CLOCK" );
}
コード例 #5
0
ファイル: vmem_ref.c プロジェクト: benrr101/sp2_derpos
void _vmem_ref_init( void )
{
	//reserves the addresses in the virtual memory
	_vmeml2_static_address( REF_START, REF_END, TRUE);
	//marks all entries as empty
	int i;
	for( i =0; i < REF_SIZE; i++ )
	{
		ref[i] = REF_EMPTY;	
	}
	
	c_puts( " vmem_ref"); 
#ifdef _VMEM_REF_DEBUG
	c_printf("Should be 0 %x\n", _vmem_ref_get_count(0x400000, TRUE));
	c_printf("Should be 0 %x\n", _vmem_ref_get_count(0x400000, FALSE));
	_vmem_ref_inc_count(0x400000, TRUE);
	c_printf("Should be 1 %x\n", _vmem_ref_get_count(0x400000, TRUE));
	c_printf("Should be 0 %x\n", _vmem_ref_get_count(0x400000, FALSE));
	_vmem_ref_inc_count(0x400000, TRUE);
	_vmem_ref_inc_count(0x400000, FALSE);
	c_printf("Should be 2 %x\n", _vmem_ref_get_count(0x400000, TRUE));
	c_printf("Should be 1 %x\n", _vmem_ref_get_count(0x400000, FALSE));
	_vmem_ref_dec_count(0x400000, TRUE);
	c_printf("Should be 1 %x\n", _vmem_ref_get_count(0x400000, TRUE));
	_vmem_ref_dec_count(0x400000, TRUE);
	c_printf("Should be 0 %x\n", _vmem_ref_get_count(0x400000, TRUE));

	for( ;; )
	{
		c_printf("Count %d\n", _vmem_ref_get_count(0x400000, TRUE));
		_vmem_ref_inc_count(0x400000, TRUE);
	}
#endif
}
コード例 #6
0
ファイル: basic.c プロジェクト: FREEWING-JP/ttbasic_lin
// Print numeric specified columns
void putnum(short value, short d){
	unsigned char i;
	unsigned char sign;

	if(value < 0){
		sign = 1;
		value = -value;
	} else {
		sign = 0;
	}

	lbuf[6] = 0;
	i = 6;
	do {
		lbuf[--i] = (value % 10) + '0';
		value /= 10;
	} while(value > 0);

	if(sign)
		lbuf[--i] = '-';

	//String length = 6 - i
	while(6 - i < d){ // If short
		c_putch(' '); // Fill space
		d--;
	}
	c_puts(&lbuf[i]);
}
コード例 #7
0
ファイル: system.c プロジェクト: HostClub/HostOS
void _ap_init( void ) {
	//*((int *)0x9000) = 11;
	//c_io_init();
	c_puts( "AP INIT" );

	while (1);
}
コード例 #8
0
ファイル: user_r.c プロジェクト: solb/sysprogos
int main( void ) {
	int i;
	char ch = '&';

	c_puts( "User R running\n" );
	sleep( seconds_to_ms(10) );
	for( i = 0; i < 3; ++i ) {
		do {
			writech( 'R' );
			ch = readch();
			if( ch == -1 ) {	/* wait a bit */
				sleep( seconds_to_ms(1) );
			}
		} while( ch == -1 );
		writech( ch );
		c_printf("%c is %d\n", ch, ch);
	}

	c_puts( "User R exiting\n" );
	exit();
}
コード例 #9
0
ファイル: user_t.c プロジェクト: solb/sysprogos
int main( void ) {
	prio_t prio1, prio2;
	int i, j;
	pid_t pid;

	pid = getpid();
	prio1 = getprio();
	c_printf( "User T (%d) running, initial prio %d\n", pid, prio1 );
	
	writech( 'T' );
	for( i = 0; i < 20; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	prio2 = setprio( PRIO_HIGH );
	prio1 = getprio();
	c_printf( "User T, set prio #1 old %d new %d\n", prio2, prio1 );
	
	writech( 'T' );
	for( i = 0; i < 20; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	prio2 = setprio( PRIO_LOW );
	prio1 = getprio();
	c_printf( "User T, set prio #2 old %d new %d\n", prio2, prio1 );

	writech( 'T' );
	for( i = 0; i < 20; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	prio2 = setprio( PRIO_STD );
	prio1 = getprio();
	c_printf( "User T, set prio #3 old %d new %d\n", prio2, prio1 );
	
	writech( 'T' );
	for( i = 0; i < 30; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	c_puts( "User T exiting\n" );
	exit();
}
コード例 #10
0
ファイル: queue.c プロジェクト: HostClub/HostOS
void _q_init( void ) {
	int i;

	// add all the qnodes to the free qnode list

	_qnode_avail = NULL;
	for( i = 0 ; i < N_QNODES; ++i ) {
		_qnodes[i].next = _qnode_avail;
		_qnode_avail = &_qnodes[i];
	}

	c_puts( " queues" );
}
コード例 #11
0
ファイル: user_g.c プロジェクト: solb/sysprogos
int main( void ) {
	int i;
	pid_t pid;

	pid = getpid();
	c_printf( "User G (%d) running\n", pid );
	writech( 'G' );
	for( i = 0; i < 5; ++i ) {
		sleep( seconds_to_ms(15) );
		writech( 'G' );
	}

	c_puts( "User G exiting\n" );
	exit();
}
コード例 #12
0
ファイル: scheduler.c プロジェクト: rit-sos/SOS
void _sched_init( void ) {
	int i;
	Status status;

	for( i = 0; i < N_READYQ; ++i ) {
		status = _q_alloc( &_ready[i], NULL );
		if( status != SUCCESS ) {
			_kpanic( "_sched_init",
				 "readyq alloc status %s",
				 status );
		}
	}

	_current = NULL;

	c_puts( " scheduler" );
}
コード例 #13
0
ファイル: klibc.c プロジェクト: benrr101/sp2_derpos
void _kpanic( char *mod, char *msg, Status code ) {

	c_puts( "\n\n***** KERNEL PANIC *****\n\n" );
	c_printf( "Module: %s\n", mod );
	if( msg != NULL ) {
		c_printf( msg, _kstatus(code) );
		c_putchar( '\n' );
	}
	if( code >= STATUS_SENTINEL ) {
		c_printf( "*** bad code %d\n", code );
	}

	//
	// This might be a good place to do a stack frame
	// traceback
	//

	__panic( "KERNEL PANIC" );

}
コード例 #14
0
ファイル: klibc.c プロジェクト: agargiulo/DOSS
void _kpanic( char *mod, char *msg, status_t code ) {

	c_puts( "\n\n***** KERNEL PANIC *****\n\n" );
	c_printf( "Module: %s\n", mod );
	if( msg != NULL ) {
		c_printf( msg, _kstatus(code) );
		c_putchar( '\n' );
	}
	if( code >= N_STATUS ) {
		c_printf( "*** bad code %d\n", code );
	}

	//
	// This might be a good place to do a stack frame
	// traceback
	//

	// dump out all the queues

	_q_dump_all();

	__panic( "KERNEL PANIC" );

}
コード例 #15
0
ファイル: stacks.c プロジェクト: gcsmith/vm-framework
void _init_stacks( void ) {
    int i;

    // first, put all stacks into the free pool
    //
    // NOTE:  queues must have been initialized first!

    for( i = 0; i < N_PROCESSES; ++i ) {
        if( _free_stack(&g_stacks[i]) != ERR_NONE ) {
            _kpanic( "init stacks:  enqueue failed" );
        }
    }

    // set up the system stack

    _memclr( (void *)&g_system_stack, sizeof(Stack) );

    g_system_esp = ((unsigned int *)(&g_system_stack + 1)) - 2;

    // announce that we have initialized the stack module

    c_puts( " stacks" );

}
コード例 #16
0
ファイル: mouse.c プロジェクト: benrr101/sp2_derpos
void _ps2_mouse_isr( int vec, int code ){

	static int byte_c = 0;
	static char mouse_p = '+';
	static char m_bytes[3];

	// temp vars
	char button_change = 0;

	if(_init)
		m_bytes[byte_c++] = __inb(PS2_PORT);

	// Only dump information once we have everything the mouse sent
	if(byte_c == 3){
		if( (m_bytes[0] & 0x80) || (m_bytes[0] & 0x40) ){
			// overflow! throw away packet
			c_puts( "Mouse overflow!\n" );
		}
		else{

			// Check left-button status
			if( m_bytes[0] & 0x1 ){
				if( _left_button != 1)
					//c_puts( "Left Button Pressed!\n" );
				_left_button = 1;
				button_change = 1;
			}
			else if( _left_button ){
				//c_puts( "Left Button Released!\n" );
				_left_button = 0;
				button_change = 1;
			}
				
			// check right-button status
			if( m_bytes[0] & 0x2 ){
				if(_right_button != 1)
					//c_puts( "Right Button Pressed!\n" );
				_right_button = 1;
				button_change = 1;
			}
			else if( _right_button ){
				//c_puts( "Right Button Released!\n" );
				_right_button = 0;
				button_change = 1;
			}

			// check middle-button status
			if( m_bytes[0] & 0x4 ){
				if(_middle_button != 1)
					//c_puts( "Middle Button Pressed!\n" );
				_middle_button = 1;
				button_change = 1;
			}
			else if( _middle_button ){
				//c_puts( "Middle Button Released!\n" );
				_middle_button = 0;
				button_change = 1;
			}
			
			_x_move = m_bytes[1];
			if( (m_bytes[0] & 0x8) == 0 ){
				_x_move *= -1;
			}
			if( (m_bytes[0] & 0x20) != 0 ){
				_y_move *= -1;
			}
			_y_move = m_bytes[2];
			//c_printf( "X: %dmm\n", _x_move );
			//c_printf( "Y: %dmm\n", _y_move );
		}
		byte_c = 0;
	}

	// remove the mouse cursor at the previous location
	c_putchar_at(_x_pos, _y_pos, ' ');

	// limit total possible movement
	_x_move = _x_move > 80 ? 80 : _x_move;
	_x_move = _x_move < -80 ? -80 : _x_move;
	_y_move = _y_move > 64 ? 64 : _y_move;
	_y_move = _y_move < -64 ? -64 : _y_move;

	// move mouse cursor
	_x_t_move += ( _x_move / 2 );
	_y_t_move += ( _y_move / 6 );

	/*
	// apply a minimum bound of movement
	if( _x_move < 0 && _x_move > -16 )
		_x_t_move -= 1;
	else if( _x_move > 0 && _x_move < 16 )
		_x_t_move += 1;
	if( _y_move < 0 && _y_move > -16 )
		_y_t_move += 1;
	else if( _y_move > 0 && _y_move < 16 )
		_y_t_move -= 1;
	*/

	if(_x_t_move > 6){
		_x_pos++;
		_x_t_move = 0;
	}
	else if(_x_t_move < -6){
		_x_pos--;
		_x_t_move = 0;
	}
	if(_y_t_move > 8){
		_y_pos--;
		_y_t_move = 0;
	}
	else if(_y_t_move < -8){
		_y_pos++;
		_y_t_move = 0;
	}

	// enforce boundaries
	if( _x_pos > 79 )
		_x_pos = 79;
	if( _x_pos < 0 )
		_x_pos = 0;
	if( _y_pos > 24)
		_y_pos = 24;
	if( _y_pos < 0)
		_y_pos = 0;

	if(_left_button)
		mouse_p = 'x';
	else if(_right_button)
		mouse_p = '#';
	else if(_middle_button)
		mouse_p = '|';
	else
		mouse_p = '+';

	c_putchar_at( _x_pos, _y_pos, mouse_p );

	update_cursor_pos( _x_pos, _y_pos );
	if( button_change == 1 )
		update_mouse_button( _left_button, _right_button, _middle_button );

	// indicate that we have read the interrupt
	__outb( 0x20, 0x20 );
	__outb( 0xA0, 0x20 );
}
コード例 #17
0
ファイル: ws28xx-pru0.c プロジェクト: jadonk/pruduino
static int prompt_thread(struct pt *pt)
{
	static char ch1;
	static char *pp;
	static char linebuf[80];
	char buf[8];
	char *p;
	static int linesz;
	static u8 current_universe;
	u32 val;

	PT_BEGIN(pt);

	for (;;) {
again:
		sprintf((char *) &buf, "PRU#%d> ", current_universe);
		c_puts(buf);
		linesz = sizeof(linebuf);
		c_readline(linebuf, linesz);
		c_puts("\n");
		if (linesz == 0)
			goto again;

		ch1 = linebuf[0];
		pp = "";

		PT_WAIT_UNTIL(pt, !(PINTC_SRSR0 & BIT(SYSEV_THIS_PRU_TO_OTHER_PRU)));

		if (ch1 == '?') {
			c_puts("Help\n"
		 		" s <universe>              "
				"select universe 0-13\n"
		  		" b                         "
				"blanks slots 1-170\n"
				" m <val>                   "
				"max number of slots per universe 0-169\n"
		  		" w <num> <v1>.<v2>.<v3>    "
				"write 24-bit GRB value to slot number\n"
		  		" l                         "
				"latch data out the PRU1\n");
		} else if (ch1 == 's') {
			p = parse_u32(linebuf + 1, &val);
			if (val > MAX_UNIVERSES - 1) {
				pp = "*BAD*\n";
			} else { 
				current_universe = val;
			}
		} else if (ch1 == 'b') {
			blank_slots(current_universe);
		} else if (ch1 == 'm') {
			p = parse_u32(linebuf + 1, &val);
			
			if (val > MAX_SLOTS || val == 0) {
				pp = "*BAD\n";
			} else {
				SHARED_MEM[CONFIG_MAX_SLOTS] = val;
				*((u32 *) PRU_LED_DATA) = val;
			}
		} else if (ch1 == 'w') {
			p = parse_u32(linebuf + 1, &val);

			if (val > MAX_SLOTS) {
				pp = "*BAD*\n";
			} else {
				u32 rgb_data;
				p = parse_u24(p, &rgb_data);
				write_data(current_universe, val, rgb_data);
			}
		} else if (ch1 == 'l') {
			/*
			 * Tell PRU1 to update the LED strings
	 		*/

			SIGNAL_EVENT(SYSEV_THIS_PRU_TO_OTHER_PRU);
		} else {
			pp = "*BAD*\n";
		}

		c_puts(pp);
	}

	PT_YIELD(pt);

	PT_END(pt);
}
コード例 #18
0
ファイル: system.c プロジェクト: HostClub/HostOS
void _init( void ) {
	pcb_t *pcb;
	context_t *context;
	status_t stat;

	/*
	** BOILERPLATE CODE - taken from basic framework
	**
	** Initialize interrupt stuff.
	*/

	__init_interrupts();	// IDT and PIC initialization

	/*
	** Console I/O system.
	*/

	c_io_init();
	c_setscroll( 0, 7, 99, 99 );
	c_puts_at( 0, 6, "================================================================================" );

	/*
	** 20103-SPECIFIC CODE STARTS HERE
	*/

	/*
	** Initialize various OS modules
	*/

	c_puts( "Starting module init: " );

	_q_init();		// must be first
	_pcb_init();
	_stack_init();
	_sio_init();
	_syscall_init();
	_sched_init();
	_clock_init();
	//_pci_init();
	build_lapic_info();
	_paging_init();

	c_puts( "\n" );

	c_puts(" Ending init\n");
	initSMP();

	/*
	** Create the initial system ESP
	**
	** This will be the address of the next-to-last
	** longword in the system stack.
	*/

	_system_esp = ((uint32_t *) ( (&_system_stack) + 1)) - 2;

	/*
	** Install the ISRs
	*/

	__install_isr( INT_VEC_TIMER, _isr_clock );
	__install_isr( INT_VEC_SYSCALL, _isr_syscall );
	__install_isr( INT_VEC_SERIAL_PORT_1, _isr_sio );

	/*
	** Create the initial process
	**
	** Code mostly stolen from _sys_fork() and _sys_exec();
	** if either of those routines change, SO MUST THIS!!!
	**
	** First, get a PCB and a stack
	*/

	stat = _pcb_alloc( &pcb );
	if( stat != E_SUCCESS ) {
		_kpanic( "_init", "first pcb alloc status %s", stat );
	}

	stat = _stack_alloc( &(pcb->stack) );
	if( stat != E_SUCCESS ) {
		_kpanic( "_init", "first stack alloc status %s", stat );
	}

	/*
	** Next, set up various PCB fields
	*/

	pcb->pid  = PID_INIT;
	pcb->ppid = PID_INIT;
	pcb->prio = PRIO_MAXIMUM;

	/*
	** Set up the initial process context.
	*/

	context = _setup_stack( pcb->stack, (uint32_t) init );

	// Finally, set up the process' ESP

	context->esp = (uint32_t) context;

	// Make it the "current" process

	_current = pcb;
	_current->context = context;

	/*
	** Starting up the idle routine is the responsibility
	** of the initial user process.
	*/

	/*
	** Turn on the SIO receiver (the transmitter will be turned
	** on/off as characters are being sent)
	*/

	_sio_enable( SIO_RX );

	/*
	** END OF 20103-SPECIFIC CODE
	**
	** Finally, report that we're all done.
	*/


	c_puts( "System initialization complete.\n" );

}
コード例 #19
0
ファイル: clock.c プロジェクト: robopt/systems-programming
static void _clock_isr( int vector, int code ) {
	(void)(vector);
	(void)(code);

	pcb_t *pcb;

	// spin the pinwheel

	++_pinwheel;
	if( _pinwheel == (CLOCK_FREQUENCY / 10) ) {
		_pinwheel = 0;
		++_pindex;
		c_putchar_at( 79, 0, "|/-\\"[ _pindex & 3 ] );
	}

	// increment the system time

	++_system_time;

	/*
	** wake up any sleeper whose time has come
	**
	** we give awakened processes preference over the
	** current process (when it is scheduled again)
	*/

	while( !_queue_empty(_sleeping) &&
	       (uint32_t) _queue_kpeek(_sleeping) <= _system_time ) {

		// time to wake up!  remove it from the queue
		pcb = (pcb_t *) _queue_remove( _sleeping );
		if( pcb == NULL ) {
#ifdef DEBUG
			_kpanic( "_clock_isr", "NULL from sleep queue remove" );
#else
			c_puts( "*** _clock_isr: NULL from sleep queue\n" );
			break;
#endif
		}

		// and schedule it for dispatch
		_schedule( pcb );
	}

	// check the current process to see if it needs to be scheduled

	// sanity check!

	_current->quantum -= 1;
	if( _current->quantum < 1 ) {
		_schedule( _current );
		_dispatch();
	}

#ifdef DUMP_QUEUES
	// Approximately every 10 seconds, dump the queues, and
	// print the contents of the SIO buffers.

	if( (_system_time % SECONDS_TO_TICKS(10)) == 0 ) {
		c_printf( "Queue contents @%08x\n", _system_time );
		_queue_dump( "ready[0]", _ready[0] );
		_queue_dump( "ready[1]", _ready[1] );
		_queue_dump( "ready[2]", _ready[2] );
		_queue_dump( "ready[3]", _ready[3] );
		_queue_dump( "sleep", _sleeping );
		_sio_dump();
	}
#endif

	// tell the PIC we're done

	__outb( PIC_MASTER_CMD_PORT, PIC_EOI );

}
コード例 #20
0
ファイル: system.c プロジェクト: gcsmith/vm-framework
void _init( void ) {
    Pcb *pcb;

    //
    // BOILERPLATE CODE - taken from basic framework
    //
    // Initialize interrupt stuff.
    //

    __init_interrupts();	// IDT and PIC initialization

    //
    // I/O system.
    //

    c_io_init();
    c_clearscreen();
    c_setscroll( 0, 7, 99, 99 );
    c_puts_at( 0, 6, "================================================================================" );

    c_puts( "Init: " );

    //
    // 20073-SPECIFIC CODE STARTS HERE
    //

    //
    // Initialize various OS modules
    //

    _init_queues();		// must be first
    _init_memory();
    _init_processes();
    _init_stacks();
    _init_sio();
    _init_clock();
    _init_syscalls();

    c_puts( "\n" );

    //
    // Create the initial process
    //
    // Code mostly stolen from _sys_fork() and _sys_exec();
    // if either of those routines change, SO MUST THIS!!!
    //

    //
    // First, get a PCB and a stack
    //

    pcb = _get_pcb();
    if( pcb == 0 ) {
        _kpanic( "_init - can't allocate first pcb" );
    }

    pcb->stack = _get_stack();
    if( pcb->stack == 0 ) {
        _kpanic( "_init - can't allocate first stack" );
    }

    //
    // Next, set up various PCB fields
    //

    pcb->pid  = g_next_pid++;
    pcb->prio = PRI_NORMAL;

    //
    // Set up the initial process context.
    //
    // See _sys_exec() for an explanation of how this works.
    //

    pcb->context = _setup_stack( pcb->stack, (unsigned int) first_main );

    // Initialize memory segment. Equals that of the kernel's in the GDT.
    pcb->seg.mem.offset = 0x0;
    pcb->seg.mem.length = 0xFFFFFFFF;

    // Initialize LDT entries for this PCB
    // This is a "kernel" process, so we will just copy over the
    // descriptors from the GDT and stick them into this process' LDT.
    __copy_gdt_entry( &(pcb->seg.ldt.cseg), (GDT_INDEX(GDT_CODE)) );
    __copy_gdt_entry( &(pcb->seg.ldt.dseg), (GDT_INDEX(GDT_DATA)) );

    // Allocate a slot in the GDT for the LDT descriptor,
    // and initialize this PCB's LDT register variable.
    pcb->seg.ldtr = SEL_SETINDEX(_gdt_alloc()) | SEL_GDT | SEL_RPL(0);

    // Initialize the LDT descriptor located in the GDT
    __gdt_set_entry( SEL_GETINDEX(pcb->seg.ldtr),
                     (u32_t)&(pcb->seg.ldt), sizeof(ldt_t),
                     ACC_PRES | ACC_DPL(0) | ACC_SYS | SYS_LDT );

    //
    // Give it to the scheduler.
    //

    _schedule( pcb );

    //
    // Do it all again for the idle process.
    //

    pcb = _get_pcb();
    if( pcb == 0 ) {
        _kpanic( "_init - can't allocate idle pcb" );
    }

    pcb->stack = _get_stack();
    if( pcb->stack == 0 ) {
        _kpanic( "_init - can't allocate idle stack" );
    }

    pcb->pid  = g_next_pid++;
    pcb->prio = PRI_MINIMUM;

    pcb->context = _setup_stack( pcb->stack, (unsigned int) idle_main );

    pcb->seg.mem.offset = 0x0;
    pcb->seg.mem.length = 0xFFFFFFFF;

    __copy_gdt_entry( &(pcb->seg.ldt.cseg), (GDT_INDEX(GDT_CODE)) );
    __copy_gdt_entry( &(pcb->seg.ldt.dseg), (GDT_INDEX(GDT_DATA)) );

    pcb->seg.ldtr = SEL_SETINDEX(_gdt_alloc()) | SEL_GDT | SEL_RPL(0);

    __gdt_set_entry( SEL_GETINDEX(pcb->seg.ldtr),
                     (u32_t)&(pcb->seg.ldt), sizeof(ldt_t),
                     ACC_PRES | ACC_DPL(0) | ACC_SYS | SYS_LDT );

    _schedule( pcb );

    //
    // Dispatch the initial current process
    //

    _dispatch();

    //
    // END OF 20073-SPECIFIC CODE
    //
    // Finally, report that we're all done.
    //

    c_puts( "System initialization complete.\n" );

}
コード例 #21
0
ファイル: sio.c プロジェクト: gcsmith/vm-framework
/*
** _init_sio
**
** Initialize the UART chip.
*/
void _init_sio( void ) {

	//
	// Initialize SIO variables.
	//

	_memclr( (void *) g_inbuffer, sizeof(g_inbuffer) );
	g_inlast = g_innext = g_inbuffer;
	g_incount = 0;

	_memclr( (void *) g_outbuffer, sizeof(g_outbuffer) );
	g_outlast = g_outnext = g_outbuffer;
	g_outcount = 0;
	g_sending = 0;

	//
	// Next, initialize the UART.
	//

	// Initialize the FIFOs
	//
	// this is a bizarre little sequence of operations

	__outb( UA4_FCR, 0x20 );
	__outb( UA4_FCR, 0x00 );		// reset
	__outb( UA4_FCR, UA5_FCR_FIFO_EN );	// 0x01
	__outb( UA4_FCR, UA5_FCR_FIFO_EN |
			 UA5_FCR_RXSR );	// 0x03
	__outb( UA4_FCR, UA5_FCR_FIFO_EN |
			 UA5_FCR_RXSR |
			 UA5_FCR_TXSR );	// 0x07

	// disable interrupts

	__outb( UA4_IER, 0 );

	// select bank 1 and set the data rate

	__outb( UA4_LCR, UA4_LCR_BANK1 );
	__outb( UA4_LBGD_L, BAUD_LOW_BYTE( BAUD_9600 ) );
	__outb( UA4_LBGD_H, BAUD_HIGH_BYTE( BAUD_9600 ) );

	// Select bank 0, and at the same time set the LCR for our
	// data characteristics.

	__outb( UA4_LCR, UA4_LCR_BANK0 |
			 UA4_LCR_BITS_8 |
			 UA4_LCR_1_STOP_BIT |
			 UA4_LCR_NO_PARITY );
	
	// Set the ISEN bit to enable the interrupt request signal.

	__outb( UA4_MCR, UA4_MCR_ISEN | UA4_MCR_DTR | UA4_MCR_RTS );

	// Install our ISR

	__install_isr( INT_VEC_SERIAL_PORT_1, _isr_sio );

	// Enable device interrupts.

	__outb( UA4_IER, UA4_IER_TX_INT_ENABLE | UA4_IER_RX_INT_ENABLE );

	// Report that we're done.

	c_puts( " sio" );

}
コード例 #22
0
ファイル: system.c プロジェクト: agargiulo/DOSS
void _init( void ) {
	pcb_t *pcb;

	/*
	** BOILERPLATE CODE - taken from basic framework
	**
	** Initialize interrupt stuff.
	*/

	__init_interrupts();	// IDT and PIC initialization
	// Ignore the 0x2A interrupt which happens when removing or inserting a
	// flash drive.
	__install_isr( 0x2A,  _ignore_isr );

	/*
	** Console I/O system.
	*/

	c_io_init();
	c_clearscreen();
#ifdef ISR_DEBUGGING_CODE
	c_setscroll( 0, 7, 99, 99 );
	c_puts_at( 0, 6, "================================================================================" );
#endif

	/*
	** 20123-SPECIFIC CODE STARTS HERE
	*/

	/*
	** Initialize various OS modules
	**
	** Note:  the clock, SIO, and syscall modules also install
	** their ISRs.
	*/

	c_puts( "Module init: " );

	_q_init();		// must be first
	_pcb_init();
	_stack_init();
	_sio_init();
	_sys_init();
	_sched_init();
	_clock_init();
	_pci_init();
	_disk_init();
	_net_init();

	c_puts( "\n" );
	c_puts("Launching the shell. Please be patient\n");
	__delay(1000);
	c_clearscreen();

	/*
	** Create the initial system ESP
	**
	** This will be the address of the next-to-last
	** longword in the system stack.
	*/

	_system_esp = ((uint32_t *) ( (&_system_stack) + 1)) - 2;

	/*
	** Create the initial process
	**
	** Code mostly stolen from _sys_fork(); if that routine
	** changes, SO MUST THIS!!!
	*/

	// allocate a PCB and stack

	pcb = _create_process( NULL );
	if( pcb == NULL ) {
		_kpanic( "_init", "init() creation failed", FAILURE );
	}

	// initialize the stack with the standard context

	pcb->context = _create_stack( pcb->stack );
	if( pcb->context == NULL ) {
		_kpanic( "_init", "init() stack setup failed", FAILURE );
	}

	// define the entry point for init()

	pcb->context->eip = (uint32_t) init;

	// set up various PCB fields

	pcb->pid = pcb->ppid = PID_INIT;	// next PID is initially 1
	pcb->prio = PRIO_HIGH;
	pcb->children = 1000;

	// remember this PCB for use in reparenting orphan processes

	_init_pcb = pcb;

	// make it the first process

	_schedule( pcb );
	_dispatch();

	/*
	** Turn on the SIO receiver (the transmitter will be turned
	** on/off as characters are being sent)
	*/

	_sio_enable( SIO_RX );

	/*
	** END OF 20123-SPECIFIC CODE
	**
	** Finally, report that we're all done.
	*/

	c_puts( "System initialization complete.\n" );

}
コード例 #23
0
ファイル: testpru0.c プロジェクト: jadonk/testpru
static int prompt_thread(struct pt *pt)
{
	static char ch1;
	static char *pp;
	static char linebuf[80];
	char *p;
	static int linesz;
	u32 val;

	PT_BEGIN(pt);

	PWM_CMD->magic = PWM_REPLY_MAGIC;

	for (;;) {
again:
		c_puts("PRU> ");
		linesz = sizeof(linebuf);
		c_readline(linebuf, linesz);
		c_puts("\n");
		if (linesz == 0)
			goto again;

		ch1 = linebuf[0];

		if (ch1 == '?') {
			c_puts("Help\n"
				" h <us> set high in us\n"
				" l <us> set low in us\n");
		} else if (ch1 == 'e' || ch1 == 'd') {

			/* wait until the command is processed */
			PT_WAIT_UNTIL(pt, PWM_CMD->magic == PWM_REPLY_MAGIC);

			if (ch1 == 'e') 
				PWM_CMD->cmd = PWM_CMD_ENABLE;
			else
				PWM_CMD->cmd = PWM_CMD_DISABLE;

			p = parse_u32(linebuf + 1, &val);
			PWM_CMD->pwm_nr = val;

			PWM_CMD->magic = PWM_CMD_MAGIC;
			SIGNAL_EVENT(SYSEV_THIS_PRU_TO_OTHER_PRU);

		} else if (ch1 == 'm') {

			/* wait until the command is processed */
			PT_WAIT_UNTIL(pt, PWM_CMD->magic == PWM_REPLY_MAGIC);

			PWM_CMD->cmd = PWM_CMD_MODIFY;

			p = parse_u32(linebuf + 1, &val);
			PWM_CMD->pwm_nr = val;

			p = parse_u32(p, &val);
			PWM_CMD->u.hilo[0] = val;

			p = parse_u32(p, &val);
			PWM_CMD->u.hilo[1] = val;

			PWM_CMD->magic = PWM_CMD_MAGIC;
			SIGNAL_EVENT(SYSEV_THIS_PRU_TO_OTHER_PRU);

		} else {
			pp = "*BAD*\n";
		}

		c_puts(pp);
	}

	PT_YIELD(pt);

	PT_END(pt);
}
コード例 #24
0
ファイル: main.c プロジェクト: mindless728/Cumulonimbus
int main( void ) {
	c_puts( "Clearing screen\n");

	c_clearscreen();

	_interrupt_init();


	_pci_alloc_device_list(&pciDevices);

	status_t status = _pci_scan(pciDevices);

	if(status != E_SUCCESS){
		c_printf("PCI bus scan failed with error 0x%x\n", status);
		while(1);
	}


	c_printf("Detected %d PCI devices\n", pciDevices->size);


	//bcm_driver_init(pciDevices);
	status = i8255x_driver_init(pciDevices);

	c_io_init();	//HACK: To avoid updating c_io for the moment

	if(status != E_SUCCESS){
		c_printf("ERROR: Failed to initialize network card!\n");
	}
	else{
		c_printf("SUCCESS: Network card initialized\n");
	}

	pci_device_t* dev = pciDevices->first;

	struct ethframe frame;
	frame.header.proto = htons(0xcafe);
	int j=0;
	for(; j<ETH_ALEN; j++){
		frame.header.dest[j] = 0xff;
		frame.header.source[j] = j;
	}



	while(dev!=NULL){
		char scan = c_getchar();

		switch(scan){
			case 0x34:		//Left arrow
				if(dev->prev == NULL){
					dev=pciDevices->last;
				}
				else{
					dev = dev->prev;
				}
				c_clearscreen();
				c_moveto(0,1);
				_pci_print_config(dev);
				break;
			case 0x36:		//Right arrow
				if(dev->next == NULL){
					dev = pciDevices->first;
				}
				else{
					dev = dev->next;
				}
				c_clearscreen();
				c_moveto(0,1);
				_pci_print_config(dev);
				break;
			case 0x0A:		//Enter key
				//Mask device's interrupt
				//_pci_mask_inta(dev);
				c_clearscreen();
				//_pci_read_config(dev->address, &dev->config);
				c_moveto(0, 24);
				c_printf("> ");
				readline((char*)frame.data);

				c_moveto(0,24);
				c_printf("> Sending...                                                 ");
				c_moveto(0,24);
				i8255x_driver_transmit((uint8_t*)&frame, sizeof(struct ethframe), 0);
				c_moveto(0,1);
				c_moveto(0,24);
				c_printf(">                                                 ");

				//_pci_print_config(dev);
				//c_printf("MASKED");
				break;
			default:
				c_printf_at(78, 0, "%x", (int)scan);
				break;
		}
		//__delay(2);
	}



	return( 0 );
}
コード例 #25
0
ファイル: mouse.c プロジェクト: benrr101/sp2_derpos
/**
 * Source for init steps taken from the following forum.  
 * http://forum.osdev.org/viewtopic.php?t=10247
 */
void _ps2_mouse_init( void ){

	// Setup initial values
	_init = 0;
	_x_move = 0;
	_y_move = 0;
	_left_button = 0;
	_right_button = 0;
	_middle_button = 0;
	
	// vars
	Uint resp = 0;
	
	// Hook in our interrupt vector, we do this first because there are some
	// weird interrupt timing issues.
	__install_isr( PS2_M_VEC, _ps2_mouse_isr );

	// First, disable the mouse to avoid having it mess up initialization
	_ps2_mouse_clear();
	__outb( PS2_STAT, 0xAD );
	_ps2_mouse_clear();
	__outb( PS2_STAT, 0xA7 );

	// Clear the mouse's buffer
	__inb( 0x60 );

	// enable the PS/2 auxillary device
	_ps2_mouse_clear();
	__outb( PS2_STAT, 0xA8 );

	// Enable the interrupts
	_ps2_mouse_clear();
	__outb( PS2_STAT, 0x20 );
	_ps2_mouse_ready();
	resp = ( __inb(0x60) | 2 );
	_ps2_mouse_clear();
	__outb( PS2_STAT, 0x60 );
	_ps2_mouse_clear();
	__outb( 0x60, resp );

	// Tell the mouse to use default settings
	_ps2_write_mouse( 0xF6 );
	_ps2_read_mouse();  //Acknowledge

	/*
	// Override the Sample Rate to 200/s
	_ps2_write_mouse( PS2_M_SAMP );
	_ps2_read_mouse();
	c_puts( "ACK! Awaiting VALUE!\n" );
	_ps2_mouse_clear();
	__outb( PS2_STAT, 0xD4 );
	while( (__inb(PS2_STAT) & 2) != 0 )
		;
	__outb( PS2_PORT, 200 );
	//_ps2_read_mouse();
	
	// next, override the resolution to 8count/mm
	_ps2_write_mouse( PS2_M_SRES );
	_ps2_read_mouse();
	c_puts( "ACK! Awaiting VALUE!\n" );
	_ps2_mouse_clear();
	__outb( PS2_STAT, 0xD4 );
	while( (__inb(PS2_STAT) & 2) != 0 )
		;
	__outb( PS2_PORT, 0x03 );
	*/

	// Enable the mouse to begin data packet transfers
	_ps2_write_mouse( 0xF4 );
	_ps2_read_mouse();  //Acknowledge

	// Reset everything (settings)
	_ps2_mouse_clear();
	__outb( PS2_STAT, PS2_M_RST );
	
	// Done!
	c_puts( "Mouse driver successfully attached!\n" );
	c_clearscreen();
	_init = 1;

	// Draw mouse at center
	_x_pos = 0;
	_y_pos = 0;
}