Page 1 of 1

Serial port debugging and VM file redirect

Posted: Thu Apr 06, 2017 11:15 am
by kurmasz
I am trying to use the sample code on the Serial Ports page (http://wiki.osdev.org/Serial_Ports) for debugging. I configure the VM to simply dump incoming serial port data to a file.

* When I do this using VirtualBox on my Mac, the file is created, but never gets filled.
* When I do this using VMWare on Linux, the upper bits of each byte are 0.

For example, when I send "AAAAAAAHello, World" to the serial port, the resulting file looks like this:

0000000 0101 0101 0101 0801 0c05 0f0c 000c 0f17
0000010 0c12 0104 0201 0403 0605 0807 0a09 0c0b
0000020 0e0d 100f 0a0a 010a 0101 0101 0101 0100
0000030 0302 0504 0706 0908 0b0a 0d0c 0f0e 0110
0000040 0101 0101 0101 0100 0302 0504 0706 0908
0000050 0b0a 0d0c 0f0e 0110 0101 0101 0101 0100
0000060 0302 0504 0706 0908 0b0a 0d0c 0f0e 0110
0000070 0101 0101 0101 0100 0302 0504 0706 0908
0000080 0b0a 0d0c 0f0e 0110 0101 0101 0101 0100
0000090 0302 0504 0706 0908 0b0a 0d0c 0f0e 0110

(i.e., 'A' which is 0x41 appears as 0x01. 'H' appears as 0x08 instead of 0x48, 'e' appears as 0x05 instead 0x65, etc.)

Is there a special way I need to configure the port on the VM side (I don't see any settings other than port and IRQ)? Or, is there something special/additional I need to do on the OS side?

For completeness, I've included the code I copied from http://wiki.osdev.org/Serial_Ports below

int PORT = 0x3f8;
int is_transmit_empty() {
return inb(PORT + 5) & 0x20;
}

void serial_write_char(char a) {
while (is_transmit_empty() == 0);

outb(PORT,a);
}


int serial_init()
{
outb(PORT + 1, 0x00);// Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(PORT + 0, 0x0C); // Set divisor to 12 (lo byte) 9600 baud
outb(PORT + 1, 0x00); // (hi byte)
outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
}

int serial_write(char output[]) {
char* p = output;
int count = 0;
while (*p != '\0') {
serial_write_char(*p);
++p;
++count;
}
return count;
}

Re: Serial port debugging and VM file redirect

Posted: Fri Apr 07, 2017 2:03 pm
by MajickTek
Here is the reason of the error: you copied code word-for-word. Modify the code to make sure it works with your OS, such as having a standard library, the outb function, etc.

Re: Serial port debugging and VM file redirect

Posted: Mon Apr 10, 2017 7:09 am
by kurmasz
I just began writing the OS. All I have is the "Bare Bones" setup (http://wiki.osdev.org/Bare_Bones) and simple character output. My understanding was that the next step is to set up some very simple serial port output so I can dump debug information while I work on the more complex tasks.

I don't need full, complex serial I/O: I just need to be able to dump characters out and have them show up in a file on the host machine.