Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial debug printing device #35

Closed
fmahnke opened this issue Feb 7, 2023 · 10 comments
Closed

Serial debug printing device #35

fmahnke opened this issue Feb 7, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@fmahnke
Copy link
Contributor

fmahnke commented Feb 7, 2023

The operating system I develop uses the COM1 serial port for debugging without a framebuffer. This is some code I use to transmit characters to the serial port:

%define COM1 0x3f8
.wait:
  ; Wait until COM1 is ready.
  mov dx,COM1+5
  cli
  in al,dx
  test al,0x20
  jz .wait
  ; Transmit character.
  mov al,bl
  mov dx,COM1
  out dx,al

QEMU and Bochs both have capabilities to print COM1 data to standard output or a file. I made a VxT peripheral to print data to stdout: https://github.com/fmahnke/virtualxt/tree/serial-dbg-pr

The device is very simple and is only tested for my use case. The in function always reports THRE set, so calling code may send data at any time. The out function echoes whatever data was transmitted to standard output using VXT_PRINT.

This patch adds the -Dserial-dbg build option. When enabled, it compiles serial_dbg.c into libvxt and defines the VXTP_SERIAL_DBG macro in libvxt, SDL, and web targets. When disabled, it compiles mouse.c into libvxt as normal. sdl/main.c and web/main.c use VXTP_SERIAL_DBG to choose which device to create.

It looks like the serial mouse is only supported in SDL and web frontends, so I added this there. I tried to build and run the web target, but I'm just getting a black screen when opening index.html. If there are some instructions on working with the web target, I can try again.

@andreas-jonsson are you interested in this feature? If not, I can just maintain this patch for my use case. Otherwise, let me know if you propose any changes to the approach. I could also enhance it if there are any other known use cases.

@andreas-jonsson andreas-jonsson self-assigned this Feb 8, 2023
@andreas-jonsson andreas-jonsson added the enhancement New feature or request label Feb 8, 2023
@andreas-jonsson
Copy link
Owner

I don't necessarily mind this feature. But I think there might be a bit of a duplication in functionality.
If you run VirtualXT with --debug you can print post codes to port 0x80 and just print characters to stdout on 0xE9 which I think is the same port Bochs are using for debug prints. There is also a separate post card device post.c if you compile with -Dat.

Do you need it to behave like a serial port specifically?

@andreas-jonsson
Copy link
Owner

@fmahnke , Regarding the Web frontend. Do you get any output from the JS console in your browser? Sounds like it fails to load the disk image perhaps?

Have a look at this project: https://github.com/realmode-games/realmode.games
It showcases a few options and how to run different images etc.

@fmahnke
Copy link
Contributor Author

fmahnke commented Feb 8, 2023

The Bochs 0xe9 feature has an advantage over the serial port driver for very early testing, when a serial port driver hasn't been written yet. It's helpful to minimize code for a boot loader. I started out with that. Real hardware doesn't support it. When I moved from BIOS video to a CGA driver, I wrote the serial driver.

Ultimately, I want as much of the same code as possible to run on all the targets instead of special-casing for certain ones. That's why my use case needs it to behave like a real serial port.

I've also started using the output to verify the results of automated tests, which I'd like to ultimately do on real hardware as well. So it's kind of the beginning of a "network" device above and beyond a debug device.

(No JS console output. I'll take a look at the realmode-games site and try again).

@andreas-jonsson
Copy link
Owner

I have a pass-through COM and LPT device on my TODO. I think that will serve double duty for what you want.
Let me add your device until that has been implemented. (I will make some tweaks so it is not hard coded to COM1.)

Let's open a new issue for the WASM/JS discussion and I can help you debug it. (To the best of my abilities... I'm not a very good "web" programmer.)

@andreas-jonsson
Copy link
Owner

You can now specify --serial-debug=<port>.
Note that the port number is converted with atoi so for COM1 that would be --serial-debug=1016.

@fmahnke
Copy link
Contributor Author

fmahnke commented Feb 9, 2023

Thanks!

@andreas-jonsson
Copy link
Owner

andreas-jonsson commented Mar 31, 2023

(No JS console output. I'll take a look at the realmode-games site and try again).

@fmahnke Did you ever get this going? If you have an image of your OS on a webserver (public) you should just be able to boot it from this URL: https://app.virtualxt.org/?img=http%3A//<url-to-your-os>.img.

You might also want to append &freq=16 to speed it up a bit. app.virtualxt.org gets updated with the latest build from the edge branch.

If you want to self host it you can download the web root from here.

@fmahnke
Copy link
Contributor Author

fmahnke commented Mar 31, 2023

Thanks for the follow up! I've spent the last several weeks on the Forth implementation that is the user shell for the OS. I'm getting fairly close to ready for a public demo. I plan to use virtualxt as part of that demo, so I'll keep you posted on this and the packaging story as well.

@andreas-jonsson
Copy link
Owner

Fyi:
Due to its simplicity the serial debug device has been moved to a Lua script. https://github.com/andreas-jonsson/virtualxt/blob/develop/modules/lua/serial_debug.lua

It can be used with the Lua module system and works just like before.

@fmahnke
Copy link
Contributor Author

fmahnke commented Aug 5, 2023

Thank you. Took me awhile to figure out how to use it, but I found the answer in serial_debug.lua. This is timely because I'm currently using COM2 in QEMU to send binary CPU profiling data to the host. That's probably a temporary measure, but it's a convenient one. I'll try adding a second serial port in vxt using the Lua script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants