Skip to content

serial_read does not work in VirtualBox #7

@mikijov

Description

@mikijov

This is likely not DOS-Serial-Library problem, but rather VirtualBox one; but I wanted to ask if anyone tried running the library in a virtual environment?

I have simple code:

#include "serial.h"

void test_dos_serial_library() {
   int err = serial_open(COM_1, 9600, 8, 'n', 1, SER_HANDSHAKING_NONE);
   if (err < 0) {
      fatal("ERROR: error opening serial port. (%d)", err);
   }

   while (true) {
      char ch;
      int err = serial_read(COM_1, &ch, 1);
      if (err < 0) {
         fatal("ERROR: error reading from serial port. (%d)", err);
      } else if (err > 0) {
         cprintf("%02X '%c'\n\r", ch, ch);
      }
      serial_debug();
      delay(100);
   }
}

and this code works fine on physical machine running FreeDOS 1.3. But when running in VirtualBox running DOS 6.22 it reads garbage.

To debug, I also used bios functions, and the code below actually works.

#include <bios.h>

void test_bios_serial() {
   uint16_t err = _bios_serialcom(_COM_INIT, 0, _COM_9600 | _COM_NOPARITY | _COM_CHR8 | _COM_STOP1);
   cprintf("%04X %016b\n\r", err, err);
   while (true) {
      err = _bios_serialcom(_COM_RECEIVE, 0, 0);
      if (err == 0x6000) {
         // do nothing
      } else if (err > 0xFF) {
         cprintf("%04X %016b\n\r", err, err);
      } else {
         cprintf("%02X '%c'\n\r", err, err);
      }
   }
}

I am using Watcom 2.0 and compiling for 8086:

CFLAGS=-bcl=dos -0 -d0 -wx -zc -q -ze @directives.lnk

serialhd.exe: serialhd.c serial.c
	wcl $^ -fe=$@ -fm=serialhd $(CFLAGS)

As much as I could debug the interrupt handler, it seems that inp() in line

data = UART_READ_DATA(com);
returns garbage. I replaced this with data='m' and I confirmed that I was reliably receiving 'm' from serial_read().

Long story short, just asking if there is anything that can be done to make this work in a virtual environment to ease my development?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions