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