Пример #1
0
/**
 * Just prepares the isr-callback and IO-request array.
 */
void _ps2_keyboard_init( void ){

	// temp vars
	Status status;

	// For simplicity, null-out the io-requests
	ps2_io_req *req;
	int i;
	for( i = 0; i < TOTAL_IO_REQS; i++){
		req = requests[i];
		req->pid = 0;
		req->buf = 0;
		req->size = -1;
		req->index = -1;
	}

	// Create the Buffered-Blocking Process Queue
	status = _q_alloc( &_buf_block, NULL );
	if( status != SUCCESS ) {
		prt_status( "keyboard, init: Unable to create buf_block queue for IO"
					" requests, keyboard input disabled!\n Error: %s\n", 
					status);
	}


	// install our ISR
	__install_isr( PS2_K_VEC, _ps2_keyboard_isr );
}
Пример #2
0
/**
 * Initializes the serial controller.
 */
void sio_init( void ) {
	/*
	** 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 Modem Control Register to send and receive
	** This is necessary to receive data from the ADDS terminals
	*/
	__outb( UA4_MCR, UA4_MCR_DTR | UA4_MCR_RTS |
	        UA4_MCR_ISEN );

	__install_isr(INT_VEC_SERIAL_PORT_1, io_interrupt_handler);

	__outb(UA4_IER, UA4_IER_RX_INT_ENABLE | UA4_IER_TX_INT_ENABLE);
}
Пример #3
0
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" );
}
Пример #4
0
/*
** Name:	init_idt
**
** Description: Initialize the Interrupt Descriptor Table (IDT).  This
**		makes each of the entries in the IDT point to the isr stub
**		for that entry, and installs a default handler in the
**		handler table.  Specific handlers are then installed for
**		those interrupts we may get before a real handler is set up.
*/
static void init_idt( void ){
	int i;
	extern	void	( *__isr_stub_table[ 256 ] )( void );

	/*
	** Make each IDT entry point to the stub for that vector.
	** Also make each entry in the ISR table point to the default handler.
	*/
	for ( i=0; i < 256; i++ ){
		set_idt_entry( i, __isr_stub_table[ i ] );
		__install_isr( i, __default_unexpected_handler );
	}

	/*
	** Install the handlers for interrupts that have a specific handler.
	*/
	__install_isr( INT_VEC_KEYBOARD, __default_expected_handler );
	__install_isr( INT_VEC_TIMER,    __default_expected_handler );
	__install_isr( INT_VEC_MYSTERY,  __default_mystery_handler );
}
Пример #5
0
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" );

}
Пример #6
0
void __vm8086_init(void)
{
	__install_isr(INT_VEC_GPF, _isr_gpf);
}
Пример #7
0
/**
 * 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;
}
Пример #8
0
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" );

}
Пример #9
0
/*
** _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" );

}