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 int i; 18 19 while (count--) { 20 for (i = 0; i < size; i++) 21 fprintf(stderr, "%c", *p++); 22 } 23 fflush(stderr); 24 25 return true; 26 } 27 28 static bool early_serial_rxr_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) 29 { 30 return true; 31 } 32 33 static struct ioport_operations early_serial_txr_rxr_ops = { 34 .io_out = early_serial_txr_out, 35 .io_in = early_serial_rxr_in, 36 }; 37 38 static bool early_serial_lsr_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) 39 { 40 uint8_t *p = data; 41 42 *p = XMTRDY; 43 44 return true; 45 } 46 47 static struct ioport_operations early_serial_lsr_ops = { 48 .io_in = early_serial_lsr_in, 49 }; 50 51 void early_printk__init(void) 52 { 53 ioport__register(early_serial_base + TXR, &early_serial_txr_rxr_ops); 54 ioport__register(early_serial_base + LSR, &early_serial_lsr_ops); 55 } 56