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