Skip to contentSkip to conversation

How can i redirect the writes to the console from the HVM (port 0xe9) to Qemu?

DISCUSSION Tom Rotenberg 2 participants 3 messages Aug 4, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

I would like to write all the logs of the HVM console (like the hvmloader prints, hvm bios prints, etc.), which are actually written to port 0xe9, to *also* be written to the qemu log file. So, basically, i should just do the following in qemu:

static void ioportE9_write(void *opaque, uint32_t addr, uint32_t data)

{
    fprintf(logfile, "%c", (char)data);
}

...
<somewhere in the qemu init>
...

    /* Log all the UART's to the qemu log file */
    register_ioport_write(0xe9, 1, 1, ioportE9_write, NULL);

...

Well, it turns out that this doesn't work. After i checked it, it seems that this doesn't work, because Xen registers it's own handler for the ioport 0xe9, which prevents me from getting the HVM accesses to this port. Xen performs the registeration in the following place:

file:               xen/arch/x86/hvm/hvm.c
function:       hvm_domain_initialise()

The line looks like this:
...

    register_portio_handler(d, 0xe9, 1, hvm_print_line);

...

In previous versions of Xen, Xen hooked this 0xe9 port, by direct code in the vmx part, which made it possible to register your own handler for this port, but in the current Xen, this is changed.

Does anyone know how can i register my own "hook" function on this port, without modifying the code in hvm.c? Is there a chain of writes?

Tom

#1 lore raw
Quoted 2 lines · Tom Rotenberg

Does anyone know how can i register my own "hook" function on this port, without modifying the code in hvm.c? Is there a chain of writes?

You need to modify hvm_print_line() in hvm.c to return X86EMUL_UNHANDLEABLE rather than X86EMUL_OKAY. This will cause Xen to think that the handler could not handle the port access and so fall back to sending the port access to qemu, which is what you want.

-- Keir

#2 lore raw

Great, thanks!

Quoted 14 lines · Keir Fraser
Quoted 2 lines · Tom Rotenberg

Does anyone know how can i register my own "hook" function on this port, without modifying the code in hvm.c? Is there a chain of writes?

You need to modify hvm_print_line() in hvm.c to return X86EMUL_UNHANDLEABLE rather than X86EMUL_OKAY. This will cause Xen to think that the handler could not handle the port access and so fall back to sending the port access to qemu, which is what you want.

 -- Keir