1 #include "kvm/early_printk.h" 2 3 #include "kvm/ioport.h" 4 5 #include <stdio.h> 6 7 static int early_serial_base = 0x3f8; /* ttyS0 */ 8 9 #define XMTRDY 0x20 10 11 #define TXR 0 /* Transmit register (WRITE) */ 12 #define LSR 5 /* Line Status */ 13 14 static bool early_serial_txr_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) 15 { 16 char *p = data; 17 18 printf("%c", *p); 19 20 return true; 21 } 22 23 static struct ioport_operations early_serial_txr_ops = { 24 .io_out = early_serial_txr_out, 25 }; 26 27 static bool early_serial_lsr_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) 28 { 29 uint8_t *p = data; 30 31 *p = XMTRDY; 32 33 return true; 34 } 35 36 static struct ioport_operations early_serial_lsr_ops = { 37 .io_in = early_serial_lsr_in, 38 }; 39 40 void early_printk__init(void) 41 { 42 ioport__register(early_serial_base + TXR, &early_serial_txr_ops); 43 ioport__register(early_serial_base + LSR, &early_serial_lsr_ops); 44 } 45