--- /dev/null
+#include "kvm/early_printk.h"
+
+#include "kvm/ioport.h"
+
+#include <stdio.h>
+
+static bool early_serial_txr_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
+{
+ char *p = data;
+
+ printf("%c", *p);
+
+ return true;
+}
+
+static struct ioport_operations early_serial_txr_ops = {
+ .io_out = early_serial_txr_out,
+};
+
+static bool early_serial_lsr_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
+{
+ uint8_t *p = data;
+
+ *p = 0x20; /* xmtrdy */
+
+ return true;
+}
+
+static struct ioport_operations early_serial_lsr_ops = {
+ .io_in = early_serial_lsr_in,
+};
+
+void early_printk__init(void)
+{
+ ioport__register(0x03F8, &early_serial_txr_ops);
+ ioport__register(0x03FD, &early_serial_lsr_ops);
+}
--- /dev/null
+#ifndef KVM__IOPORT_H
+#define KVM__IOPORT_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct kvm;
+
+struct ioport_operations {
+ bool (*io_in)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
+ bool (*io_out)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
+};
+
+void ioport__register(uint16_t port, struct ioport_operations *ops);
+
+#endif /* KVM__IOPORT_H */
+#include "kvm/ioport.h"
+
#include "kvm/kvm.h"
+#include <assert.h>
#include <limits.h>
#include <stdio.h>
-struct ioport_operations {
- bool (*io_in)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
- bool (*io_out)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
-};
-
static uint8_t ioport_to_uint8(void *data)
{
uint8_t *p = data;
[0x3D4] = &dummy_read_write_ioport_ops,
[0x3D5] = &dummy_write_only_ioport_ops,
+ /* PORT 03F8-03FF - Serial port (8250,8250A,8251,16450,16550,16550A,etc.) COM1 */
+ [0x03F9] = &dummy_read_write_ioport_ops,
+ [0x03FA] = &dummy_read_write_ioport_ops,
+ [0x03FB] = &dummy_read_write_ioport_ops,
+ [0x03FC] = &dummy_read_write_ioport_ops,
+
/* PORT 0CF8-0CFF - PCI Configuration Mechanism 1 - Configuration Registers */
[0x0CF8] = &dummy_write_only_ioport_ops,
[0x0CFC] = &dummy_read_write_ioport_ops,
[0x0CFE] = &dummy_read_write_ioport_ops,
};
+void ioport__register(uint16_t port, struct ioport_operations *ops)
+{
+ ioport_ops[port] = ops;
+}
+
static const char *to_direction(int direction)
{
if (direction == KVM_EXIT_IO_IN)