OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 2:29 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Serial port debugging and VM file redirect
PostPosted: Thu Apr 06, 2017 11:15 am 
Offline

Joined: Tue Apr 04, 2017 2:37 pm
Posts: 19
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;
}


Top
 Profile  
 
 Post subject: Re: Serial port debugging and VM file redirect
PostPosted: Fri Apr 07, 2017 2:03 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 17, 2016 6:58 am
Posts: 101
Location: The Internet
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.

_________________
Everyone should know how to program a computer, because it teaches you how to think! -Steve Jobs
Code:
while ( ! ( succeed = try() ) );


Top
 Profile  
 
 Post subject: Re: Serial port debugging and VM file redirect
PostPosted: Mon Apr 10, 2017 7:09 am 
Offline

Joined: Tue Apr 04, 2017 2:37 pm
Posts: 19
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 231 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group