📄 hal_diag.c
字号:
static void KeyboardInit( void){ KBFlags = 0; } /* KeyboardInit *///-----------------------------------------------------------------------------static CYG_BYTE KeyboardAscii( CYG_BYTE scancode){ CYG_BYTE ascii = 0xFF; // Start by handling all shift/ctl keys: switch( scancode ) { case 0xe0: KBFlags |= KBExtend; return 0xFF; case 0xfa: KBFlags |= KBAck; return 0xFF; case 0xfe: KBFlags |= KBResend; return 0xFF; case LSHIFT: KBFlags |= KBShiftL; return 0xFF; case LSHIFT | BREAK: KBFlags &= ~KBShiftL; return 0xFF; case RSHIFT: KBFlags |= KBShiftR; return 0xFF; case RSHIFT | BREAK: KBFlags &= ~KBShiftR; return 0xFF; case CTRL: if( KBFlags & KBExtend ) { KBFlags |= KBCtrlR; KBFlags &= ~KBExtend; } else KBFlags |= KBCtrlL; return 0xFF; case CTRL | BREAK: if( KBFlags & KBExtend ) { KBFlags &= ~KBCtrlR; KBFlags &= ~KBExtend; } else KBFlags &= ~KBCtrlL; return 0xFF; case ALT: if( KBFlags & KBExtend ) { KBFlags |= KBAltR; KBFlags &= ~KBExtend; } else KBFlags |= KBAltL; return 0xFF; case ALT | BREAK: if( KBFlags & KBExtend ) { KBFlags &= ~KBAltR; KBFlags &= ~KBExtend; } else KBFlags &= ~KBAltL; return 0xFF; case CAPS: KBFlags ^= KBCapsLock; case CAPS | BREAK: return 0xFF; case NUMS: KBFlags ^= KBNumLock; case NUMS | BREAK: return 0xFF; } // Clear Extend flag if set KBFlags &= ~KBExtend; // Ignore all other BREAK codes if( scancode & 0x80 ) return 0xFF; // Here the scancode is for something we can turn // into an ASCII value ascii = KBScanTable[scancode & 0x7F][KBIndexTab[KBFlags & KBIndex]]; return ascii;} /* KeyboardAscii *///-----------------------------------------------------------------------------static int KeyboardTest( void){ // If there is a pending character, return True if( KBPending != 0xFF ) return true; // If there is something waiting at the port, get it while( pc_inb(KBSTATPORT) & 0x01 ) { CYG_BYTE code = pc_inb(KBDATAPORT); // Translate to ASCII CYG_BYTE c = KeyboardAscii(code); // if it is a real ASCII char, save it and // return True. if( c != 0xFF ) { KBPending = c; return true; } } // Otherwise return False return false; } /* KeyboardTest *///-----------------------------------------------------------------------------static CYG_BYTE KeyboardRead( void){ CYG_BYTE c; // Loop until a character is ready while( !KeyboardTest() ) continue; // get it c = KBPending; KBPending = 0xFF; // and return it return c; } /* KeyboardRead *///-----------------------------------------------------------------------------void hal_diag_init(void){ KeyboardInit(); XPos = 0; YPos = 0; ClearScreen(); MoveCursor();}//-----------------------------------------------------------------------------void hal_diag_write_char(char ch){ switch( ch ) { case '\n': NewLine(); return; case '\r': XPos = 0; MoveCursor(); return; case '\b': if( XPos == 0 ) return; XPos--; MoveCursor(); return; case '\t': do { DisplayChar(' '); } while( (XPos % 8) != 0 ); return; case 0x0c: ClearScreen(); XPos = YPos = 0; MoveCursor(); return; case 1: ScrollUp(1); XPos = 0; YPos = ScreenLength-1; return; case 2: ScrollDown(1); XPos = 0; YPos = 0; return; default: DisplayChar(ch); return; }}//-----------------------------------------------------------------------------void hal_diag_read_char(char *c){ *c = KeyboardRead();}#endif//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------# define SERIAL_COM1 (0x3F8)# define SERIAL_COM2 (0x2F8)#if defined(CYGSEM_HAL_I386_PC_DIAG_SERIAL1)# define SERIAL_COM SERIAL_COM1#define CYG_KERNEL_DIAG_GDB // turn on GDB debug packets#elif defined(CYGSEM_HAL_I386_PC_DIAG_SERIAL2)# define SERIAL_COM SERIAL_COM2#endif#ifdef SERIAL_COM# define TBR (0x00)# define RBR (0x00)# define IER (0x01)# define LCR (0x03)# define MCR (0x04)# define LSR (0x05)# define DLL (0x00)# define DLH (0x01)# define FCR (0x02)/* Configuration for 38400 baud, N81. */# define BAUD_LOW (3)#if 0/* Configuration for 19200 baud, N81. */# undef BAUD_LOW# define BAUD_LOW (6)/* Configuration for 9600 baud, N81. */# undef BAUD_LOW# define BAUD_LOW (12)#endif# define BAUD_HIGH (0)# define WM_N81 (3)//-----------------------------------------------------------------------------int com1 ;//-----------------------------------------------------------------------------void hal_diag_init(void){ com1 = SERIAL_COM ;/* Initialize the serial port: don't send interrupts; don't go into test mode. */ pc_outb(com1 + IER, 0); pc_outb(com1 + IER, 0); pc_outb(com1 + MCR, 0) ;/* Configure the baud rate & word mode. */ pc_outb(com1 + LCR, 0x80) ; pc_outb(com1 + DLL, BAUD_LOW); pc_outb(com1 + DLH, BAUD_HIGH); pc_outb(com1 + LCR, WM_N81) ;}//-----------------------------------------------------------------------------/* Send out a character via debugger output. */void hal_diag_write_char_serial(char __c){ int x; do { x = pc_inb(com1 + LSR) ; } while (!(x & 0x60)) ; pc_outb(com1 + TBR, __c) ;}//-----------------------------------------------------------------------------/* read and return a single char */void hal_diag_read_char_serial(char *c){ int x; do { x = pc_inb(com1 + LSR) ; } while (!(x & 0x01)) ; c[0] = pc_inb(com1 + RBR) ;}//-----------------------------------------------------------------------------void hal_diag_write_char(char c){#ifdef CYG_KERNEL_DIAG_GDB static char line[100]; static int pos = 0; // No need to send CRs if( c == '\r' ) return; line[pos++] = c; if( c == '\n' || pos == sizeof(line) ) { // Disable interrupts. This prevents GDB trying to interrupt us // while we are in the middle of sending a packet. The serial // receive interrupt will be seen when we re-enable interrupts // later. CYG_INTERRUPT_STATE oldstate; HAL_DISABLE_INTERRUPTS(oldstate); while(1) { static char hex[] = "0123456789ABCDEF"; cyg_uint8 csum = 0; int i; char c1; hal_diag_write_char_serial('$'); hal_diag_write_char_serial('O'); csum += 'O'; for( i = 0; i < pos; i++ ) { char ch = line[i]; char h = hex[(ch>>4)&0xF]; char l = hex[ch&0xF]; hal_diag_write_char_serial(h); hal_diag_write_char_serial(l); csum += h; csum += l; } hal_diag_write_char_serial('#'); hal_diag_write_char_serial(hex[(csum>>4)&0xF]); hal_diag_write_char_serial(hex[csum&0xF]); hal_diag_read_char_serial( &c1 ); if( c1 == '+' ) break;// if( cyg_hal_is_break( &c1 , 1 ) )// cyg_hal_user_break( NULL ); } pos = 0; // Wait for all data from serial line to drain // and clear ready-to-send indication.// hal_diag_drain_serial0(); // And re-enable interrupts HAL_RESTORE_INTERRUPTS( oldstate ); }#else hal_diag_write_char_serial(c);#endif }//-----------------------------------------------------------------------------void hal_diag_read_char(char *c){ hal_diag_read_char_serial(c);}#endif//-----------------------------------------------------------------------------// End of hal_diag.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -