1 ;------------------------------------------------------------------------------ 2 ; @file 3 ; Serial port debug support macros 4 ; 5 ; Copyright (c) 2008 - 2009, Intel Corporation. All rights reserved.<BR> 6 ; This program and the accompanying materials 7 ; are licensed and made available under the terms and conditions of the BSD License 8 ; which accompanies this distribution. The full text of the license may be found at 9 ; http://opensource.org/licenses/bsd-license.php 10 ; 11 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 ; 14 ;------------------------------------------------------------------------------ 15 16 ;//--------------------------------------------- 17 ;// UART Register Offsets 18 ;//--------------------------------------------- 19 %define BAUD_LOW_OFFSET 0x00 20 %define BAUD_HIGH_OFFSET 0x01 21 %define IER_OFFSET 0x01 22 %define LCR_SHADOW_OFFSET 0x01 23 %define FCR_SHADOW_OFFSET 0x02 24 %define IR_CONTROL_OFFSET 0x02 25 %define FCR_OFFSET 0x02 26 %define EIR_OFFSET 0x02 27 %define BSR_OFFSET 0x03 28 %define LCR_OFFSET 0x03 29 %define MCR_OFFSET 0x04 30 %define LSR_OFFSET 0x05 31 %define MSR_OFFSET 0x06 32 33 ;//--------------------------------------------- 34 ;// UART Register Bit Defines 35 ;//--------------------------------------------- 36 %define LSR_TXRDY 0x20 37 %define LSR_RXDA 0x01 38 %define DLAB 0x01 39 40 ; UINT16 gComBase = 0x3f8; 41 ; UINTN gBps = 115200; 42 ; UINT8 gData = 8; 43 ; UINT8 gStop = 1; 44 ; UINT8 gParity = 0; 45 ; UINT8 gBreakSet = 0; 46 47 %define DEFAULT_COM_BASE 0x3f8 48 %define DEFAULT_BPS 115200 49 %define DEFAULT_DATA 8 50 %define DEFAULT_STOP 1 51 %define DEFAULT_PARITY 0 52 %define DEFAULT_BREAK_SET 0 53 54 %define SERIAL_DEFAULT_LCR ( \ 55 (DEFAULT_BREAK_SET << 6) | \ 56 (DEFAULT_PARITY << 3) | \ 57 (DEFAULT_STOP << 2) | \ 58 (DEFAULT_DATA - 5) \ 59 ) 60 61 %define SERIAL_PORT_IO_BASE_ADDRESS DEFAULT_COM_BASE 62 63 %macro inFromSerialPort 1 64 mov dx, (SERIAL_PORT_IO_BASE_ADDRESS + %1) 65 in al, dx 66 %endmacro 67 68 %macro waitForSerialTxReady 0 69 70 %%waitingForTx: 71 inFromSerialPort LSR_OFFSET 72 test al, LSR_TXRDY 73 jz %%waitingForTx 74 75 %endmacro 76 77 %macro outToSerialPort 2 78 mov dx, (SERIAL_PORT_IO_BASE_ADDRESS + %1) 79 mov al, %2 80 out dx, al 81 %endmacro 82 83 %macro debugShowCharacter 1 84 waitForSerialTxReady 85 outToSerialPort 0, %1 86 %endmacro 87 88 %macro debugShowHexDigit 1 89 %if (%1 < 0xa) 90 debugShowCharacter BYTE ('0' + (%1)) 91 %else 92 debugShowCharacter BYTE ('a' + ((%1) - 0xa)) 93 %endif 94 %endmacro 95 96 %macro debugNewline 0 97 debugShowCharacter `\r` 98 debugShowCharacter `\n` 99 %endmacro 100 101 %macro debugShowPostCode 1 102 debugShowHexDigit (((%1) >> 4) & 0xf) 103 debugShowHexDigit ((%1) & 0xf) 104 debugNewline 105 %endmacro 106 107 BITS 16 108 109 %macro debugInitialize 0 110 jmp real16InitDebug 111 real16InitDebugReturn: 112 %endmacro 113 114 real16InitDebug: 115 ; 116 ; Set communications format 117 ; 118 outToSerialPort LCR_OFFSET, ((DLAB << 7) | SERIAL_DEFAULT_LCR) 119 120 ; 121 ; Configure baud rate 122 ; 123 outToSerialPort BAUD_HIGH_OFFSET, ((115200 / DEFAULT_BPS) >> 8) 124 outToSerialPort BAUD_LOW_OFFSET, ((115200 / DEFAULT_BPS) & 0xff) 125 126 ; 127 ; Switch back to bank 0 128 ; 129 outToSerialPort LCR_OFFSET, SERIAL_DEFAULT_LCR 130 131 jmp real16InitDebugReturn 132 133