3f8 Serial Port
On the other hand, if you do use the serial port, then this option should be set to 3F8/IRQ4. Onboard Serial Port 2: Same as above, if you do not use this. If you do use it.
I am trying to debug an hyper-visor I am writing, and I set up a serial port between two virtual machine in Vmware player(I am testing the hyper visor on a virtual machine with nested vt-x support). My question is how can I transfer data from the hyper visor to the serial port without the OS help(most of the software stack OS is not available when the hyper visor is on). I know I can see how other systems implement sending to a serial port and implement that way, but this beat the point of debugging because implementing a complete interface to serial port might take more time than finding the bugs manually. I only need to send one number, or a string so I am looking for the minimalist solution possible.
Until know I have been using netconsole in order to pass debugging information, but the bug I am facing right now, happens before the kernel get back the control, so netconsole is not able to send any data. If anyone have a better idea on how to pass the debugging information other than using serial port I would love to hear that.
Right now I have came into that Resource https://en.wikibooks.org/wiki/Serial_Programming/8250_UART_Programming , that might be relevant to my question, but I would love if someone can elaborate, sending data through using out, is working, but the data order is messed up and cant be used for debugging, so, so far it dosent help.
1 Answer
It is quite easy to set up and use a serial port for diagnostic output, and I predict that you will find it immensely useful. To start with, you can use it just for debug output, but since it can be bidirectional, you can extend it as needed to do such things as dump and modify memory and registers (both hypervisor state and guest state).
To set up a serial port, first you have to find the base address. If it is COM1, then it is 3f8, so I'll use that as an example. To initialize the port, write these values, using the OUT instruction:
Serial Port Cable
To send a character, read from 3fd (LSR) using the IN instruction and loop until bit 5 is set (THR empty). Then write the character to 3f8 (THR).
Of course, a serial port driver can be much more sophisticated than this, but this is enough to get it going.
prlprlNot the answer you're looking for? Browse other questions tagged clinux-kernelserial-portvmwarehypervisor or ask your own question.
I have a Coin Counter Machine(SC350/360) which connects to a computer via RS232C Interface. I've the technical documentation which describes the communication protocols and a working pascal program is also included for manipulating the machine. I copied the pascal code and tested it on Turbo Pascal, using DosBox, for windows 7 64 bit and the code compiles successfully. What I wanted to achieve now was to convert those pascal codes to C#.Net but I was having a hard time when converting few lines to C# as I don't have much experience on serial port programming.
3f8 Serial Port Charlotte
This was the code in Pascal to Initialize communication with the machine. (Set baudrate to 9600, 8 bits, no parity, 1 stop bit)
The corresponding C# for the above code I came up was; (Please correct me if I get it wrong)
But I couldn't understand how to convert the rest of the pascal procedures. Some of these procedures i had difficulty with are;
Could you guys please help me how to convert those pascal codes to the equivalent C#? I know I can write to a port using the 'port.Write' Method but that couldn't exactly fit the turbo pascal code with the port array.(e.g port[RXTX + 3] := $80;
) I don't know what the port array index 'RXTX+3' is referring relating to C#.
I would really appreciate it if you could give me a hand on this and I hope I'll learn to convert the rest of the pascal codes myself. :)
I have written the following equivalent C# code for the pascal program using the help I got from the good people here. Please correct me if i have made a mistake in my code.
By the way here is the protocol described in the device documentation.
And moreover i've here provided the rest of the code with an example of a command send to count the number of coins.
To send a command to count coins;
The protocol for reading count register is;
2 Answers
What's being done here is direct, PC hardware port (specifically COM1) access. For those curious what's going on, base port+5 is the line status register of a 8250 UART and its pincompatible successors like the 16450 and 16550. See here for more details concerning the inner workings of classic PC style serial ports.
Not sure if you'll even ever get this to work properly on Windows (and one thing is certain, it will never ever work with eg serial port dongles that are attached via USB), it's DOS code that partially relies on being quite close to the hardware, have perfect control over timing (DOS was single tasking) and perfectly knowing what hardware to expect. In most cases it should be possible to rely on the facilities that Windows (and in your case, the .Net framework) offer - The stuff you show above is for sending bytes (you can use the Write method for that). The checksum part should be quite trivial to reproduce.
.Net offers an API SerialPort, it should be possible to use that API and do away with this remnant of 'good' old DOS days.
fvufvuUgh. 8250 UART registers are documented here. Directly accessing the UART registers in Windows is not supported. Your SerialPort initialization is correct. Beware that it is fairly unlikely your machine has a COM1 port unless you have real hardware. USB emulators tend to pick higher port numbers. Use SerialPort.GetPortNames() to have a look-see.
Tx() waits for transmitter empty status bit. Simply replace with SerialPort.Write() to write one byte, it already blocks if the transmit buffer is full. It won't be.
RxWait() waits for the receiver ready status bit. Simply replace with SerialPort.ReadByte().
Tx2() is just a helper procedure to keep a simple checksum updated, just add the byte you send to a checksum variable.
Hans PassantHans Passant