Changeset 152 for trunk/hal/x86_64/core
- Timestamp:
- Jul 6, 2017, 3:47:20 PM (7 years ago)
- Location:
- trunk/hal/x86_64/core
- Files:
-
- 6 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 -
trunk/hal/x86_64/core/hal_apic.h
r146 r152 21 21 22 22 #ifndef x86_ASM 23 char hal_com_read(); 24 void hal_com_send(char c); 25 23 26 void hal_ioapic_disable_entry(uint8_t index); 24 27 void hal_ioapic_set_entry(uint8_t index, uint8_t vec, uint8_t dest); -
trunk/hal/x86_64/core/hal_init.c
r150 r152 296 296 hal_enable_irq(&dummy); 297 297 298 while (1); 299 298 300 kernel_init(&btinfo); 299 301 -
trunk/hal/x86_64/core/hal_interrupt.c
r142 r152 27 27 28 28 #include <hal_kentry.h> 29 #include <hal_apic.h> 29 30 #include <hal_internal.h> 30 31 … … 37 38 { 38 39 x86_printf("-> got timer: rip=%Z\n", tf->tf_rip); 40 hal_com_send('h'); 41 return; 42 } 43 44 /* -------------------------------------------------------------------------- */ 45 46 /* 47 * Serial Port (COM1) interrupt 48 */ 49 void hal_com1_intr(struct trapframe *tf) 50 { 51 char c = hal_com_read(); 52 53 x86_printf("-> got com '%c'\n", c); 39 54 return; 40 55 } -
trunk/hal/x86_64/core/hal_kentry.S
r146 r152 36 36 .globl hal_exception_entry 37 37 .globl hal_timer_intr 38 .globl hal_com1_intr 38 39 .globl hal_keyboard_intr 39 40 .type hal_exception_entry, @function 40 41 .type hal_timer_intr, @function 42 .type hal_com1_intr, @function 41 43 .type hal_keyboard_intr, @function 42 44 … … 133 135 movq %rsp,%rdi 134 136 call hal_timer_intr 137 138 movq lapic_va(%rip),%rax 139 movl $0,LAPIC_EOI(%rax) 140 141 INTR_RESTORE_REGS 142 addq $16,%rsp 143 iretq 144 145 ASM_ENTRY(x86_ioapic_com1) 146 pushq $0 147 pushq $T_ASTFLT 148 INTR_SAVE_REGS 149 150 movq %rsp,%rdi 151 call hal_com1_intr 135 152 136 153 movq lapic_va(%rip),%rax … … 247 264 248 265 .quad x86_lapic_timer 266 .quad x86_ioapic_com1 249 267 .quad x86_ioapic_keyboard 250 268 -
trunk/hal/x86_64/core/hal_segmentation.h
r143 r152 195 195 196 196 #define DYNVEC_MIN CPUVEC_MAX 197 #define DYNVEC_MAX (DYNVEC_MIN + 6)197 #define DYNVEC_MAX (DYNVEC_MIN + 7) 198 198 199 199 #define VECTOR_APIC_SPURIOU (DYNVEC_MIN + 0) … … 202 202 #define VECTOR_APIC_XCU_PTI (DYNVEC_MIN + 3) 203 203 204 /* debug only, will be removed soon */204 /* debug only, will be moved soon */ 205 205 #define LAPIC_TIMER_VECTOR (DYNVEC_MIN + 4) 206 #define IOAPIC_KEYBOARD_VECTOR (DYNVEC_MIN + 5) 206 #define IOAPIC_COM1_VECTOR (DYNVEC_MIN + 5) 207 #define IOAPIC_KEYBOARD_VECTOR (DYNVEC_MIN + 6) 207 208 208 209 #define NIDT 256 /* total number of IDT entries */ 209 210 211
Note: See TracChangeset
for help on using the changeset viewer.