Esempio n. 1
0
/* Mask a specified interrupt. */
void __Set_Interrupt_Mask(unsigned char ucVector)
{
	uint16_t port;
	uint8_t value;

	BUG_ON(ucVector < INTERRUPT_VECTOR_BASE);
	ucVector -= INTERRUPT_VECTOR_BASE;
	if (!__INTERRUPT_IS_MASKABLE(ucVector))
	{
		return;
	}

	if (ucVector < 8)
	{
		port = PIC1_DATA;
	}
	else
	{
		port = PIC2_DATA;
		ucVector -= 8;
	}
	/* Combine the corresponding mask with old value. */
	value = __inb(port) | (1 << ucVector);
	__outb(value, port);
}
Esempio n. 2
0
void _sio_write( int ch ){

	//
	// Must do LF -> CRLF mapping
	//

	if( ch == '\n' ) {
		_sio_write( '\r' );
	}

	//
	// If we're currently transmitting, just add this to the buffer
	//

	if( g_sending ) {
		*g_outlast++ = ch;
		++g_outcount;
		return;
	}

	//
	// Not sending - must prime the pump
	//

	g_sending = 1;
	__outb( UA4_TXD, ch );

}
Esempio n. 3
0
/**
 * Normally, IRQs 0 to 7 are mapped to entries 8 to 15. This
 * is a problem in protected mode, because IDT entry 8 is a
 * Double Fault! Without remapping, every time IRQ0 fires,
 * you get a Double Fault Exception, which is NOT actually
 * what's happening. We send commands to the Programmable
 * Interrupt Controller (PICs - also called the 8259's) in
 * order to make IRQ0 to 15 be remapped to IDT entries 32 to 47
 */
void ArchController::irq_remap(void)
{
    __outb(0x11,PIC_MA);
    __outb(0x20,PIC_MA + 1);
    __outb(0x04,PIC_MA + 1);
    __outb(0x01,PIC_MA + 1);
    __outb(0x0, PIC_MA + 1);

    __outb(0x11,PIC_SL);
    __outb(0x28,PIC_SL + 1);
    __outb(0x02,PIC_SL + 1);
    __outb(0x01,PIC_SL + 1);
    __outb(0x0, PIC_SL + 1);

    return;
}
Esempio n. 4
0
/*
** Name:	__default_expected_handler
**
** Arguments:	The usual ISR arguments
**
** Returns:	The usual ISR return value
**
** Description: Default handler for interrupts we expect may occur but
**		are not handling (yet).  Just reset the PIC and return.
*/
static void __default_expected_handler( int vector, int code ){
	if( vector >= 0x20 && vector < 0x30 ){
		__outb( PIC_MASTER_CMD_PORT, PIC_EOI );
		if( vector > 0x28 ){
			__outb( PIC_SLAVE_CMD_PORT, PIC_EOI );
		}
	}
	else {
		/*
		** All the "expected" interrupts will be handled by the
		** code above.  If we get down here, the isr table may
		** have been corrupted.  Print message and don't return.
		*/
		__panic( "Unexpected \"expected\" interrupt!" );
	}
}
Esempio n. 5
0
void _ps2_write_mouse(char b){

	// vars
	//Uint resp;

	_ps2_mouse_clear();

	// let the PS2 controller know we want to send a command to the mouse
	//c_printf("Letting Mouse know we are sending a command...\n");
	__outb(PS2_STAT, PS2_M_SCOM);
	_ps2_mouse_clear();

	// Now, send the mouse our command
	//c_printf("Sending Command: 0x%x...\n", ( b & 0xFF) );
	__outb(PS2_PORT, b);
}
Esempio n. 6
0
void fn0C00_0100(word16 cx, Eq_13 Eq_14::*bx, byte Eq_21::*di, Eq_14 * ds)
{
    bios_video_set_mode(0x13);
    __outw(0x03D4, DPB(ax, 0x20, 8, 8));
    ptr32 es_ax_12 = Mem0[ds:bx + 0x0000:segptr32];
    Eq_19 al_13 = (byte) es_ax_12;
    Eq_21 * es_15 = SLICE(es_ax_12, selector, 16);
    do
    {
        __outb(0x03C9, al_13);
        al_13 = al_13 + 0x95 + C;
        C = cond(al_13);
        if (al_13 != 0x00)
            continue;
        do
        {
            es_15->*di = (byte) cx_57 ^ SLICE(cx_57, byte, 8);
            C = false;
            di = di + 1;
            cx = cx_57 - 0x0001;
            word16 cx_57 = cx;
        } while (cx != 0x0000);
        word16 ax_50 = DPB(cx_57, __inb(0x60), 0, 8);
        al_13 = (byte) (ax_50 - 0x0001);
    } while (ax_50 != 0x0001);
    return;
}
Esempio n. 7
0
static DWORD outputb(__CMD_PARA_OBJ* lpCmdObj)
{
	UCHAR            bt         = 0;
	WORD             wPort      = 0;
	DWORD            dwPort     = 0;

	if(NULL == lpCmdObj)  //Parameter check.
		return IOCTRL_TERMINAL;

	if(lpCmdObj->byParameterNum < 3)  //Not enough parameters.
	{
		PrintLine("Please input the port and value.");
		return IOCTRL_NORMAL;
	}
	if(!Str2Hex(lpCmdObj->Parameter[1],&dwPort))
	{
		PrintLine("Please input port number correctly.");
		return IOCTRL_NORMAL;
	}
	wPort = (WORD)(dwPort);    //Now,wPort contains the port where to output.
	if(!Str2Hex(lpCmdObj->Parameter[2],&dwPort))
	{
		PrintLine("Please input the value to output correctly.");
		return IOCTRL_NORMAL;
	}
	bt = (BYTE)(dwPort);

	//WriteByteToPort(bt,wPort);    //Write the byte to port.
	__outb(bt,wPort);
	return IOCTRL_NORMAL;
}
Esempio n. 8
0
/* Unmask a specified interrupt. */
void __Clear_Interrupt_Mask(unsigned char ucVector)
{
#if 1
	uint16_t port;
	uint8_t value;

	BUG_ON(ucVector < INTERRUPT_VECTOR_BASE);
	ucVector -= INTERRUPT_VECTOR_BASE;
	if (!__INTERRUPT_IS_MASKABLE(ucVector))
	{
		return;
	}

	if (ucVector < 8)
	{
		port = PIC1_DATA;
	}
	else
	{
		port = PIC2_DATA;
		ucVector -= 8;
	}
	/* Clear the corresponding mask from the old value. */
	value = __inb(port) & ~(1 << ucVector);
	__outb(value, port);
#endif
}
Esempio n. 9
0
//Initialization routine for IDE controller 0.
//In current implementation,this routine only disabled the interrupt of 
//IDE controller,so only polling scheme is used now.
BOOL IdeInitialize()
{
	WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	__outb(0x0E,IDE_CTRL0_PORT_CTRL);    //Reset controller,disable interrupt.
	WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	return TRUE;
}
Esempio n. 10
0
//Low level output routine,which is used in interrupt context or OS initialization
//phase.
static void __LL_Output(UCHAR bt)
{
#ifdef __I386__
	DWORD dwCount1 = 1024;
	DWORD dwCount2 = 3;
	UCHAR ctrlReg  = 0;    //Used to save and restore temporary control register of COM interface.
#endif //__I386__

	//Check if the low level output function is initialized,initialize it if not.
	if(!Console.bLLInitialized)
	{
#ifdef __I386__
		 __outb(0x80,CON_DEF_COMBASE + 3);  //Set DLAB bit to 1,thus the baud rate divisor can be set.
         __outb(0x0C,CON_DEF_COMBASE);      //Set low byte of baud rate divisor.
         __outb(0x00,CON_DEF_COMBASE + 1);  //Set high byte of baud rate divisor.
         __outb(0x07,CON_DEF_COMBASE + 3);  //Reset DLAB bit,and set data bit to 8,one stop bit,without parity check.
         __outb(0x00,CON_DEF_COMBASE + 1);  //Disable all interrupts.
#elif defined(__STM32__)
		 //Initialize STM32's default USART port,which is defined in console.h file,default is USART1.
		 __Init_Default_Usart();
#endif  //__I386__
		 Console.bLLInitialized = TRUE;      //Indicate low level function is initialized.
	}

#ifdef __I386__
	//Try to output one byte.Please note that the output operation may fail,if the hardware is not ready for
	//sending for too long time.Control register of COM interface should be saved before sending,and restore
	//it after sending.
	ctrlReg = __inb(CON_DEF_COMBASE + 1);
	__outb(0x00,CON_DEF_COMBASE + 1);     //Disable all interrupts.
	while((dwCount2 --) > 0)
	{
		while((dwCount1 --) > 0)
		{
			if(__inb(CON_DEF_COMBASE + 5) & 32)  //Send register empty.
			{
				__outb(bt,CON_DEF_COMBASE);
				__outb(ctrlReg,CON_DEF_COMBASE + 1);
				return;
			}
		}
		dwCount1 = 1024;
	}
	__outb(ctrlReg,CON_DEF_COMBASE + 1);  //Restore previous control register.
#elif defined(__STM32__)
	//Call USART's low level output function.
	__SER_PutChar(bt);
#endif  //__I386__
}
Esempio n. 11
0
unsigned char ich5_smb_read_byte(unsigned char adr, unsigned char cmd)
{
    int l1, h1, l2, h2;
    unsigned long long t;
    __outb(0x1f, SMBHSTSTS);			// reset SMBus Controller
    __outb(0xff, SMBHSTDAT);
    while(__inb(SMBHSTSTS) & 0x01);		// wait until ready
    __outb(cmd, SMBHSTCMD);
    __outb((adr << 1) | 0x01, SMBHSTADD);
    __outb(0x48, SMBHSTCNT);
    rdtsc(l1, h1);
    cprint(POP2_Y, POP2_X + 16, s + cmd % 8);	// progress bar
    while (!(__inb(SMBHSTSTS) & 0x02)) {	// wait til command finished
	rdtsc(l2, h2);
	t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / v->clks_msec;
	if (t > 10) break;			// break after 10ms
    }
    return __inb(SMBHSTDAT);
}
Esempio n. 12
0
/**
 * FIXME not just timer must be cleared!!!
 * TODO Create correct IRQ translator
 */
void ArchController::irq_received(unsigned int ivecno)
{
    /*
     * TODO : Do correct check of the vector number
     *
     * FIXME!!
     * If the IDT entry that was invoked was greater than 8
     * (meaning IRQ8 - 15), then we need to send an EOI to
     * the slave controller
     */
    if (ivecno >= 8)
    {
        __outb(0x20,PIC_SL);
    }

    /* In either case, we need to send an EOI to the master
    *  interrupt controller too */
    __outb(0x20, PIC_MA);

}
Esempio n. 13
0
//Initialization routine of all COM interface devices.
static BOOL InitializeCOM(WORD base)
{
         BOOL    bResult       = FALSE;

#ifdef __I386__
         if((base != 0x3F8) && (base != 0x2F8))
         {
			 goto __TERMINAL;;
         }
         __outb(0x80,base + 3);  //Set DLAB bit to 1,thus the baud rate divisor can be set.
         __outb(0x0C,base);  //Set low byte of baud rate divisor.
         __outb(0x0,base + 1);  //Set high byte of baud rate divisor.
         __outb(0x07,base + 3); //Reset DLAB bit,and set data bit to 8,one stop bit,without parity check.
         __outb(0x0F,base + 1); //Set all interrupts include write buffer empty interrupt.
         //__inb(base);  //Clear data buffer to avoide interrupt raising.
         //__outb(0x01,base + 1);  //Enable data available interrupt.
         __outb(0x0B,base + 4); //Enable DTR,RTS and Interrupt.
         __inb(base);  //Reset data register.

		 //Try to check if the COM interface is exist.
		 if(0xFF == __inb(base + 1))  //Port is not exist.
		 {
			 goto __TERMINAL;
		 }
         bResult = TRUE;
#else
#endif

__TERMINAL:
         return bResult;
}
Esempio n. 14
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);
}
Esempio n. 15
0
//Write one or several sector(s) from a specified hard disk.
//Please make sure the pBuffer is long enough to contain the sectors write.
BOOL WriteSector(int nHdNum,DWORD dwStartSector,DWORD dwSectorNum,BYTE* pBuffer)
{
	BYTE        DrvHdr  = (BYTE)IDE_DRV0_LBA;
	BYTE        LbaLow;
	BYTE        LbaMid;
	BYTE        LbaHigh;
	UCHAR       tmp;
	
	if((nHdNum > 1) || (NULL == pBuffer) || (0 == dwSectorNum))
	{
		return FALSE;
	}
	//Form the access mode and driver.
	if(1 == nHdNum)
	{
		DrvHdr = (BYTE)IDE_DRV1_LBA;
	}
	tmp = (UCHAR)(dwStartSector >> 24);  //Get the high byte.
	tmp &= 0x0F;                         //Only keep the last 4 bits.
	DrvHdr += tmp;                       //Driver and access mode(LBA).
	tmp = (UCHAR)dwStartSector;
	LbaLow = tmp;
	tmp = (UCHAR)(dwStartSector >> 8);
	LbaMid = tmp;
	tmp = (UCHAR)(dwStartSector >> 16);
	LbaHigh = tmp;
	tmp = (UCHAR)dwSectorNum;
	//Issue the read sector command.
	WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	//WriteByteToPort(0x4b,IDE_CTRL0_PORT_PRECOMP);
	__outb(0x4B,IDE_CTRL0_PORT_PRECOMP);
	//WriteByteToPort(0x01,IDE_CTRL0_PORT_SECTORNUM);
	__outb(tmp,IDE_CTRL0_PORT_SECTORNUM);
	//WriteByteToPort(byStartSector,IDE_CTRL0_PORT_STARTSECTOR);
	__outb(LbaLow,IDE_CTRL0_PORT_STARTSECTOR);
	//WriteByteToPort(byCylinderLo,IDE_CTRL0_PORT_CYLINDLO);
	__outb(LbaMid,IDE_CTRL0_PORT_CYLINDLO);
	//WriteByteToPort(byCylinderHi,IDE_CTRL0_PORT_CYLINDHI);
	__outb(LbaHigh,IDE_CTRL0_PORT_CYLINDHI);
	//WriteByteToPort(byDrvHdr,IDE_CTRL0_PORT_HEADER);
	__outb(DrvHdr,IDE_CTRL0_PORT_HEADER);
	//WriteByteToPort(IDE_CMD_READ,IDE_CTRL0_PORT_CMD);
	__outb(IDE_CMD_WRITE,IDE_CTRL0_PORT_CMD);
	//Write data from port.
	WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	WaitForRdy(IDE_CTRL0_PORT_STATUS,0);    //Should wait the driver to ready,an complicated problem has been caused
	                                        //by this issue(did not wait before).
	__outws(pBuffer,tmp * 512,IDE_CTRL0_PORT_DATA);
	//Wait for completion.
	WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	return TRUE;
}
Esempio n. 16
0
void fn0C00_0100(word16 si, byte bl)
{
	bios_video_set_mode(0x13);
	byte Eq_18::*di_16 = &Eq_18::b0000;
	word16 wLoc02_19 = 0x0000;
	int16 si_21 = si + 0x0001;
	while (true)
	{
		__outb(0x03C8, (byte) bx);
		do
		{
			__outb(0x03C9, 0x00);
			__outb(0x03C9, 0x00);
			bx = bx + 0x0001;
			byte al_53 = (byte) bx;
			__outb(0x03C9, al_53);
			word16 cx_54 = 0x0780;
			while (cx_54 != 0x0000)
			{
				0xA000->*di_16 = al_53;
				di_16 = di_16 + 1;
				cx_54 = cx_54 - 0x0001;
			}
		} while (di_16 != &Eq_18::bFFFFE880);
		bx = wLoc02_19 + si_21;
		di_16 = &Eq_18::b0000;
		byte bl_66 = (byte) bx;
		wLoc02_19 = bx;
		if (bl_66 != 0x20)
		{
			bx = DPB(bx, bl_66, 0, 8);
			if (bl_66 != 0x00)
				continue;
		}
l0C00_013C:
		si_21 = -si_21;
	}
}
Esempio n. 17
0
unsigned char us15w_smb_read_byte(unsigned char adr, unsigned char cmd)
{
    int l1, h1, l2, h2;
    unsigned long long t;
    //__outb(0x00, smbusbase + 1);			// reset SMBus Controller
    //__outb(0x00, smbusbase + 6);
    //while((__inb(smbusbase + 1) & 0x08) != 0);		// wait until ready
    __outb(0x02, smbusbase + 0);    // Byte read
    __outb(cmd, smbusbase + 5);     // Command
    __outb(0x07, smbusbase + 1);    // Clear status
    __outb((adr << 1) | 0x01, smbusbase + 4);   // DIMM address
    __outb(0x12, smbusbase + 0);    // Start
    //while (((__inb(smbusbase + 1) & 0x08) == 0)) {}	// wait til busy
    rdtsc(l1, h1);
    cprint(POP2_Y, POP2_X + 16, s + cmd % 8);	// progress bar
    while (((__inb(smbusbase + 1) & 0x01) == 0) ||
		((__inb(smbusbase + 1) & 0x08) != 0)) {	// wait til command finished
	rdtsc(l2, h2);
	t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / v->clks_msec;
	if (t > 10) break;			// break after 10ms
    }
    return __inb(smbusbase + 6);
}
Esempio n. 18
0
// do it like linux, use int32_t 80h
void syscall_isr(int32_t vector, int32_t code)
{
  // from here call the actual system call
  int32_t call_num = current_proc->context->eax;

  uint32_t *args = ((uint32_t *)(current_proc->context + 1)) + 1;
  
  // Invoke the handler.  The first argument is the process
  // context; the second is the address of the first user
  // syscall argument, which is  the second longword following
  // the context save area on the stack.
  (*syscall_table[call_num])(current_proc->context, args); 

  __outb( PIC_MASTER_CMD_PORT, PIC_EOI );
}
Esempio n. 19
0
void fn0C00_0100(byte cl, byte ah, byte ch)
{
	__cli();
	do
	{
		do
		{
			byte al_26 = __inb(0x03DA);
			ax = DPB(ax, al_26 & 0x08, 0, 8);
		} while ((al_26 & 0x08) == 0x00);
		cl = cl + 0x01;
		word16 bx_34 = 0x018F;
		uint8 bl_35 = 0x8F;
		do
		{
			do
			{
				byte al_47 = __inb(0x03DA);
				ax = DPB(ax, al_47 & 0x01, 0, 8);
			} while ((al_47 & 0x01) != 0x00);
			do
			{
				byte al_54 = __inb(0x03DA);
				ax = DPB(ax_84, al_54 & 0x01, 0, 8);
				word16 ax_84 = ax;
			} while ((al_54 & 0x01) == 0x00);
			__outb(0x03C8, 0x00);
			__outb(0x03C9, cl);
			Eq_50 al_65 = bl_35 >>u 0x01;
			__outb(0x03C9, al_65);
			ch = ch + al_65;
			__outb(0x03C9, ch);
			bx_34 = bx_34 - 0x0001;
			ax = DPB(ax_84, ch, 0, 8);
			bl_35 = (byte) bx_34;
		} while (bx_34 != 0x0000);
		word16 ax_75 = DPB(ax_84, __inb(0x60), 0, 8);
		ax = ax_75 - 0x0001;
		byte al_77 = (byte) (ax_75 - 0x0001);
	} while (ax_75 != 0x0001);
	__outb(0x03C8, al_77);
	__outb(0x03C9, al_77);
	__outb(0x03C9, al_77);
	__outb(0x03C9, al_77);
	return;
}
Esempio n. 20
0
void cmain (void)
{
    /*
     * init variable sections
     */
    __memcpy (__sdata2_start, __sdata2_load, __sdata2_end - __sdata2_start);
    __memcpy (__sdata_start , __sdata_load , __sdata_end  - __sdata_start);
    __memcpy (__data_start  , __data_load  , __data_end   - __data_start);
    __bzero (__sbss2_start  , __sbss2_end - __sbss2_start);
    __bzero (__sbss_start   , __sbss_end  - __sbss_start);
    __bzero (__bss_start    , __bss_end   - __bss_start);
    /* printk( "start of BSP\n"); */
    boot_card(0);
    /* printk( "end of BSP\n"); */
    __outb (0x92, 0x01);
    while (1)
        ;
}
Esempio n. 21
0
//Write configuration to PCI bus.
static BOOL PciWriteConfig(__SYSTEM_BUS* bus, DWORD dwConfigReg, DWORD dwVal,int size)
{
	DWORD dwTmp = 0;
	DWORD _cfg = 0x80000000;
	DWORD result;

	//Combine the bus number,dev number,function number and offset together.
	dwTmp = bus->dwBusNum;
	dwTmp &= 0x000000FF;
	_cfg += (dwTmp << 16);
	_cfg += (dwConfigReg & 0x0000FFFF);

	//Issue writting.
	__outd(CONFIG_REGISTER, _cfg);
	switch (size)
	{
	case 4:
		__outd(DATA_REGISTER, dwVal);
		result = __ind(DATA_REGISTER);
		break;
	case 2:
		__outw((WORD)dwVal, DATA_REGISTER);
		result = __inw(DATA_REGISTER);
		dwVal &= 0xFFFF;
		break;
	case 1:
		__outb((UCHAR)dwVal, DATA_REGISTER);
		result = __inb(DATA_REGISTER);
		dwVal &= 0xFF;
		break;
	default:
		return FALSE;
	}

	//Check if writting is successful.
	if (dwVal == result)
	{
		return TRUE;
	}
	//For debugging.
	_hx_printf("PCI_DRV: Write data to PCI space failed,val = %d,result = %d.\r\n",dwVal,result);
	return FALSE;
}
Esempio n. 22
0
/**
 * Writes a byte of the buffer to the serial console.
 * NOTE: CPU interrups must be disabled when this routine is called.
 */
static void write_one_byte(void) {
	static int extra_cr_done = 0;
	//ensure write_buf_end is consistent.
	write_buf_end %= WRITE_BUF_LEN;

	if (write_buf_start == write_buf_end) return;

	char ch = write_buf[write_buf_start];

	/* If this character is a newline, send out a return first */
	if( ch == '\n') {
		if (extra_cr_done) {
			extra_cr_done = 0;
		}
		else {
			ch = '\r';
			extra_cr_done = 1;
			write_buf_start--;
		}
	}
	__outb( UA4_TXD, ch );
	write_buf_start = (write_buf_start + 1)%WRITE_BUF_LEN;
}
Esempio n. 23
0
/**
 * Handles processing of interrupts from the PS/2 controller.
 *
 * @param	vec			The number of the interrupt code that triggered this
 *						call.
 */
void _ps2_keyboard_isr( int vec, int code ){
	
	// temp vars
	Uint quad;

	Uint key = __inb( PS2_PORT );

	// Handle extended keys first
	if( await_next ){
		if( key == 0xFE ){
			_ps2_ack_int();
			return;
		}
		else{

			// Check if we are going to perform an active window switch
			if( win_pressed ){
				quad = get_active();

				// Determine offset arrow-keys to change active window
				switch( key ){
					case PS2_KEY_UP_P:
						if( quad > 1 )
							quad -= 2;
						break;
					case PS2_KEY_DOWN_P:
						if( quad < 2 )
							quad += 2;
						break;
					case PS2_KEY_LEFT_P:
						if( quad % 2 == 1 )
							quad -= 1;
						break;
					case PS2_KEY_RIGHT_P:
						if( quad % 2 == 0 )
							quad += 1;
				}
				switch_active( quad );
			}

			// resolve the extended key
			switch( key ){
				case PS2_KEY_LWIN_P:
				case PS2_KEY_RWIN_P:
					win_pressed = 1;
					break;
				case PS2_KEY_CTRL_P:
					ctrl_pressed = 1;
					break;
				case PS2_KEY_CTRL_R:
					ctrl_pressed = 0;
					break;
				case PS2_KEY_ALT_P:
					alt_pressed = 1;
					break;
				case PS2_KEY_ALT_R:
					alt_pressed = 0;
					break;
			}
			await_next = 0;
		}
	}

	// Next, handle special keys
	switch( key ){
		case PS2_KEY_LSHIFT_P:
		case PS2_KEY_RSHIFT_P:
			shift_pressed = 1;
			return;
		case PS2_KEY_LSHIFT_R:
		case PS2_KEY_RSHIFT_R:
			shift_pressed = 0;
			return;
		case PS2_KEY_CAPLCK_P:
			caps_lock = 1;
			return;
		case PS2_KEY_CAPLCK_R:
			caps_lock = 0;
			return;
		case PS2_KEY_CTRL_P:
			ctrl_pressed = 1;
			return;
		case PS2_KEY_ALT_P:
			alt_pressed = 1;
			return;
		case PS2_KEY_ALT_R:
			alt_pressed = 0;
			return;
	}

	// normal ASCII characters
	if( key < 0x80 ){

		// check if function-key
		if( key >= PS2_KEY_F1_P && key <= PS2_KEY_F10_P ){
			replace_active( key - PS2_KEY_F1_P );
		}
		else if( key == PS2_KEY_F11_P || key == PS2_KEY_F12_P ){
			replace_active( key - PS2_KEY_F11_P + 10 );
		}
		else{

			// otherwise give the character to the waiting focused process
			char letter = _ps2_scan_code[ shift_pressed ][ key ];
			if( letter != '\377' && letter != '\033' && letter != '\b'
					&& letter != '\t'){
				_ps2_write_to_active( letter );
			}
		}
	}

	// Just the ASCII characters being released
	else if( key >= 0x80 && key <= 0xD8){
		// key released!
	}
	else{
		
		// If we get this byte then that means we should expect an extended key
		if( key == 0xE0 ){
			await_next = 1;
			__outb( PS2_PORT, 0x0 );
		}
	}
	
	_ps2_ack_int();
}
Esempio n. 24
0
/*
** Name:	__default_mystery_handler
**
** Arguments:	The usual ISR arguments
**
** Returns:	The usual ISR return value
**
** Description: Default handler for the "mystery" interrupt that 
**		comes through vector 0x27.  This is a non-repeatable
**		interrupt whose source has not been identified.
*/
static void __default_mystery_handler( int vector, int code ){
	//c_printf( "\nMystery interrupt!\nVector=0x%02x, code=%d\n",
		  //vector, code );
	__outb( PIC_MASTER_CMD_PORT, PIC_EOI );
}
Esempio n. 25
0
File: io.c Progetto: berkus/nemesis
void _outb(unsigned char b, unsigned long addr)
{
	__outb(b, addr);
}
Esempio n. 26
0
//Read one or several sector(s) from a specified hard disk.
//Please make sure the pBuffer is long enough to contain the sectors read.
BOOL ReadSector(int nHdNum,DWORD dwStartSector,DWORD dwSectorNum,BYTE* pBuffer)
{
	BYTE        DrvHdr  = (BYTE)IDE_DRV0_LBA;
	BYTE        LbaLow;
	BYTE        LbaMid;
	BYTE        LbaHigh;
	UCHAR       tmp;
	CHAR        Buffer[64];  //For debug.
	BOOL        bResult = FALSE;

	//----------------------------------------------------------------------
	// Use BIOS service to query hard disk sector since we can not read HD
	// directly sometimes.
	//----------------------------------------------------------------------
	/*while(dwSectorNum > 4)
	{
		bResult = BIOSReadSector(nHdNum,dwStartSector,4,pBuffer);  //Read 4 sectors because of the BIOS buffer's limitation.
		if(!bResult)
		{
			return FALSE;
		}
		dwStartSector += 4;
		dwSectorNum -= 4;
		pBuffer += 512 * 4;
	}*/
#ifdef __I386__
	return BIOSReadSector(nHdNum,dwStartSector,dwSectorNum,pBuffer);
#else
	return FALSE;
#endif

	if((nHdNum > 1) || (NULL == pBuffer) || (0 == dwSectorNum))
	{
		return FALSE;
	}
	//Form the access mode and driver.
	if(1 == nHdNum)
	{
		DrvHdr = (BYTE)IDE_DRV1_LBA;
	}
	tmp = (UCHAR)(dwStartSector >> 24);  //Get the high byte.
	tmp &= 0x0F;                         //Only keep the last 4 bits.
	DrvHdr += tmp;                       //Driver and access mode(LBA).
	tmp = (UCHAR)dwStartSector;
	LbaLow = tmp;
	tmp = (UCHAR)(dwStartSector >> 8);
	LbaMid = tmp;
	tmp = (UCHAR)(dwStartSector >> 16);
	LbaHigh = tmp;
	tmp = (UCHAR)dwSectorNum;
	//Issue the read sector command.
	WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	//WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	//WriteByteToPort(0x4b,IDE_CTRL0_PORT_PRECOMP);
	__outb(0x4B,IDE_CTRL0_PORT_PRECOMP);
	//WriteByteToPort(0x01,IDE_CTRL0_PORT_SECTORNUM);
	__outb(tmp,IDE_CTRL0_PORT_SECTORNUM);
	//WriteByteToPort(byStartSector,IDE_CTRL0_PORT_STARTSECTOR);
	__outb(LbaLow,IDE_CTRL0_PORT_STARTSECTOR);
	//WriteByteToPort(byCylinderLo,IDE_CTRL0_PORT_CYLINDLO);
	__outb(LbaMid,IDE_CTRL0_PORT_CYLINDLO);
	//WriteByteToPort(byCylinderHi,IDE_CTRL0_PORT_CYLINDHI);
	__outb(LbaHigh,IDE_CTRL0_PORT_CYLINDHI);
	//WriteByteToPort(byDrvHdr,IDE_CTRL0_PORT_HEADER);
	__outb(DrvHdr,IDE_CTRL0_PORT_HEADER);
	//WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	//WriteByteToPort(IDE_CMD_READ,IDE_CTRL0_PORT_CMD);
	__outb(IDE_CMD_READ,IDE_CTRL0_PORT_CMD);
	//Wait for completion.
	//WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	WaitForDrq(IDE_CTRL0_PORT_STATUS,0);
	//WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	//Read data from port.
	__inws(pBuffer,tmp * 512,IDE_CTRL0_PORT_DATA);
	//WaitForBsy(IDE_CTRL0_PORT_STATUS,0);
	//WaitForRdy(IDE_CTRL0_PORT_STATUS,0);
	//Appended by Garry in 2011.05.30
	if(CmdSucc(IDE_CTRL0_PORT_STATUS))
	{
		return TRUE;
	}
	tmp = __inb(0x1f2);
	_hx_sprintf(Buffer,"The error number is : %d",tmp);
	PrintLine(Buffer);
	return FALSE;
}
Esempio n. 27
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;
}
Esempio n. 28
0
/**
 * A conveinence function for telling the PIC_SLAVE and PIC_MASTER that we have
 * serviced the interrupt.
 */
void _ps2_ack_int( void ){
	__outb( 0xA0, 0x20 );
	__outb( 0x20, 0x20 );
}
Esempio n. 29
0
static DWORD beep(__CMD_PARA_OBJ* lpCmdObj)
{
	__KERNEL_THREAD_MESSAGE       Msg;
	DWORD                         dwTimerID      = 00100000;
	DWORD                         dwTimeSpan     = 0;
	__COMMON_OBJECT*              lpTimerObject  = NULL;
	UCHAR                         ucCtrlByte;

	if((NULL == lpCmdObj) || (lpCmdObj->byParameterNum < 2))  //Parameter check.
	{
		PrintLine("  Please input the beep time,in millionsecond.");
		return SYS_DIAG_CMD_PARSER_INVALID;
	}

	if(!Str2Hex(lpCmdObj->Parameter[1],&dwTimeSpan))  //Get the time span to beep.
	{
		PrintLine("  Invalid time parameter.");
		return SYS_DIAG_CMD_PARSER_INVALID;
	}

	//
	//Now,the variable dwTimeSpan countains the time to beep.
	//
	lpTimerObject = System.SetTimer((__COMMON_OBJECT*)&System,
		KernelThreadManager.lpCurrentKernelThread,
		dwTimerID,
		dwTimeSpan,
		NULL,
		NULL,
		TIMER_FLAGS_ONCE);
	if(NULL == lpTimerObject)    //Failed to set timer.
	{
		PrintLine("  Can not set timer,please try again.");
		return SYS_DIAG_CMD_PARSER_FAILED;
	}

	//
	//Begin to beep.
	//
	//ReadByteFromPort(&ucCtrlByte,0x61);
	ucCtrlByte = __inb(0x61);
	ucCtrlByte |= 0x03;
	//WriteByteToPort(ucCtrlByte,0x61);
	__outb(ucCtrlByte,0x61);
	
	while(TRUE)
	{
		if(KernelThreadManager.GetMessage((__COMMON_OBJECT*)KernelThreadManager.lpCurrentKernelThread,&Msg))
		{
			if((Msg.wCommand == KERNEL_MESSAGE_TIMER) &&   //Beep time is over.
			   (Msg.dwParam  == dwTimerID))
			{
				ucCtrlByte &= ~0x03;
				//WriteByteToPort(ucCtrlByte,0x61);  //Stop the beep.
				__outb(ucCtrlByte,0x61);
				PrintLine("  Beep over");
				goto __TERMINAL;
			}
		}
	}

__TERMINAL:
	return SYS_DIAG_CMD_PARSER_SUCCESS;
}
Esempio n. 30
0
void fn0C00_0100(byte bh, Eq_10 * ds)
{
	bios_video_set_mode(0x13);
	Eq_9 Eq_10::*si_18 = &Eq_10::t01BC;
	do
	{
		word16 ax_17 = Mem0[ds:si_18 + 0x0000:word16];
		byte dh_22 = SLICE(ax_17, byte, 8);
		bios_video_set_cursor_position(bh, dh_22, (byte) ax_17);
		si_18 = si_18 + 0x0002 + 0x0001;
		dx = ax_17;
		word16 ax_25 = DPB(dx, 0x02, 8, 8);
		do
		{
			byte al_30 = Mem0[ds:si_18 + 0x0000:byte];
			msdos_write_console_char(al_30);
			ax_25 = DPB(ax_25, al_30, 0, 8);
			si_18 = si_18;
			dx = DPB(dx, al_30, 0, 8);
		} while (al_30 != 0x00);
	} while (dh_22 != 0x00);
	do
	{
		__outb(0x03C9, al_30);
		word16 ax_50 = __rol(DPB(ax_25, ~al_30, 0, 8), 0x01);
		__outb(0x03C9, (byte) ax_50);
		word16 ax_53 = __ror(ax_50, 0x01);
		byte al_54 = (byte) ax_53;
		__outb(0x03C9, al_54);
		word16 ax_57 = DPB(ax_53, ~al_54, 0, 8);
		ax_25 = ax_57 + 0x0001;
		al_30 = (byte) (ax_57 + 0x0001);
	} while (ax_57 != 0x0001);
	Eq_79 Eq_104::*di_111 = Eq_104::a0000;
	byte bl_116 = 0xCC;
	word16 bx_114 = DPB(bx, 0xCC, 0, 8);
	do
	{
		word16 cx_112 = 0x0140;
		byte cl_113 = 0x40;
		do
		{
			Eq_93 al_107;
			if ((0xA000->*di_111).t0000 == 0x00)
			{
				word16 ax_160 = __aam(cl_113 | bl_116);
				al_107 = ((byte) ax_160 | SLICE(ax_160, byte, 8)) & 0x3F;
			}
			else
			{
				Eq_87 al_168 = cl_113 - bl_116;
				al_107 = al_168 - cl_113 - (al_168 <u 0x00);
			}
			(0xA000->*di_111).t0000 = al_107;
			cx_112 = cx_112 - 0x0001;
			di_111 = di_111 + 1;
			cl_113 = (byte) cx_112;
		} while (cx_112 != 0x0000);
		bx_114 = bx_114 - 0x0001;
		bl_116 = (byte) bx_114;
	} while (bx_114 != 0x0000);
	__outb(0x0331, 0x3F);
	Mem129[ss:fp - 0x0002:word16] = 0xFA00;
	byte Eq_104::*si_122 = Eq_104::a0000;
	byte Eq_104::*di_125 = Eq_104::aFFFFFA00;
	word16 cx_126 = 0x0140;
	do
	{
		0xA000->*di_125 = 0xA000->*si_122;
		si_122 = si_122 + 1;
		di_125 = di_125 + 1;
		cx_126 = cx_126 - 0x0001;
	} while (cx_126 != 0x0000);
	Mem151[ss:fp - 0x0002:word16] = 0x0177;
	do
		;
	while (((byte) __inw(0x03DA) & 0x08) == 0x00);
	return;
}