Changeset 152 for trunk/hal/x86_64/core/hal_apic.c
- Timestamp:
- Jul 6, 2017, 3:47:20 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/core/hal_apic.c
r145 r152 114 114 /* -------------------------------------------------------------------------- */ 115 115 116 #define BAUDRATE 19200 117 #define BAUDRATE_DIV (115200 / BAUDRATE) 118 119 #define RS232_COM1_BASE 0x3F8 120 121 #define RS232_DATA 0x00 122 #define RS232_IER 0x01 123 # define IER_RD 0x01 124 # define IER_TBE 0x02 125 # define IER_ER_BRK 0x04 126 # define IER_RS232IN 0x08 127 #define RS232_DIVLO 0x00 /* when DLAB = 1 */ 128 #define RS232_DIVHI 0x01 /* when DLAB = 1 */ 129 #define RS232_IIR 0x02 130 #define RS232_LCR 0x03 131 # define LCR_DATA5 0x00 132 # define LCR_DATA6 0x01 133 # define LCR_DATA7 0x02 134 # define LCR_DATA8 0x03 135 # define LCR_TWOSTOP 0x04 136 # define LCR_PARITY 0x08 137 # define LCR_EVEN 0x10 138 # define LCR_STICK 0x20 139 # define LCR_DLAB 0x80 140 #define RS232_MCR 0x04 141 # define MCR_DTR 0x01 142 # define MCR_RTS 0x02 143 # define MCR_ELL 0x04 144 # define MCR_IR 0x40 145 #define RS232_LSR 0x05 146 # define LSR_DR 0x01 147 # define LSR_OVR 0x02 148 # define LSR_PE 0x04 149 # define LSR_FE 0x08 150 # define LSR_BRK 0x10 151 # define LSR_TBE 0x20 152 # define LSR_TE 0x40 153 #define RS232_MSR 0x06 154 # define MSR_DCTS 0x01 155 # define MSR_DDSR 0x02 156 # define MSR_DRI 0x04 157 # define MSR_DDCD 0x08 158 # define MSR_CTS 0x10 159 # define MSR_DSR 0x20 160 # define MSR_RI 0x40 161 # define MSR_DCD 0x80 162 163 #define RS232_SCRATCH 0x07 164 165 static bool_t hal_com_received() 166 { 167 return (in8(RS232_COM1_BASE + RS232_LSR) & LSR_DR) != 0; 168 } 169 170 static bool_t hal_com_transmit_empty() 171 { 172 return (in8(RS232_COM1_BASE + RS232_LSR) & LSR_TBE) != 0; 173 } 174 175 char hal_com_read() 176 { 177 while (!hal_com_received()); 178 return in8(RS232_COM1_BASE + RS232_DATA); 179 } 180 181 void hal_com_send(char c) 182 { 183 uint8_t mcr = in8(RS232_COM1_BASE + RS232_MCR); 184 out8(RS232_COM1_BASE + RS232_MCR, mcr | MCR_RTS); 185 186 while (!hal_com_transmit_empty()); 187 out8(RS232_COM1_BASE + RS232_DATA, c); 188 189 out8(RS232_COM1_BASE + RS232_MCR, mcr); 190 } 191 192 static void hal_com_init() 193 { 194 /* Disable all interrupts */ 195 out8(RS232_COM1_BASE + RS232_IER, 0x00); 196 197 /* Set baudrate */ 198 out8(RS232_COM1_BASE + RS232_LCR, LCR_DLAB); 199 out8(RS232_COM1_BASE + RS232_DIVLO, BAUDRATE_DIV); 200 out8(RS232_COM1_BASE + RS232_DIVHI, 0); 201 202 /* 8bits, no parity, one stop bit */ 203 out8(RS232_COM1_BASE + RS232_LCR, LCR_DATA8); 204 205 /* Enable IRQs, DTR set, and also DSR */ 206 out8(RS232_COM1_BASE + RS232_IER, IER_RD|IER_RS232IN); 207 out8(RS232_COM1_BASE + RS232_MCR, MCR_DTR|MCR_IR); 208 out8(RS232_COM1_BASE + RS232_MSR, MSR_DSR); 209 } 210 211 /* -------------------------------------------------------------------------- */ 212 116 213 size_t ioapic_pins __in_kdata = 0; 117 214 paddr_t ioapic_pa __in_kdata = 0; … … 193 290 x86_printf("IOAPICPINS: #%z\n", ioapic_pins); 194 291 195 /* Now, enable the keyboard */ 292 /* Now, enable the com1 port and the keyboard */ 293 hal_ioapic_set_entry(IRQ_COM1, IOAPIC_COM1_VECTOR, 0); 196 294 hal_ioapic_set_entry(IRQ_KEYBOARD, IOAPIC_KEYBOARD_VECTOR, 0); 197 295 } … … 309 407 /* Enable the IOAPIC */ 310 408 hal_ioapic_init(); 311 } 312 409 410 /* Enable the Serial Port */ 411 hal_com_init(); 412 413 hal_com_send('p'); 414 hal_com_send('d'); 415 hal_com_send('\n'); 416 } 417
Note: See TracChangeset
for help on using the changeset viewer.