copy / v86

x86 PC emulator and x86-to-wasm JIT, running in the browser
https://copy.sh/v86/
BSD 2-Clause "Simplified" License
19.69k stars 1.38k forks source link

Mechanism to communicate from emulated OS to API #993

Open cognitivegears opened 8 months ago

cognitivegears commented 8 months ago

I'm not sure if this is a question or a feature request - if it's a feature and straightforward I'd be happy at giving it a go at coding it too.

I'm trying to find a way for a emulated OS to notify the API of an event or to get information. For example, in DOSEMU you can use the "exitemu.com" to exit the emulator from the emulated OS, and "isemu.com" to return whether it is running in DOSEMU. For v86 I wouldn't want something so specific (since this can run in multiple OSes) but the ability to do something similar, like fire events in the js api or get info, etc.

One way I know of to do this is to use a serial port to send these communications. This works great, but I was wondering if a more "standardized interface" either exists or should exist?

The immediate reason I have for such a mechanism is with running BBS "doors" from node.js, so that after the door program exits (because the user quits the door) it can notify the API so it can clean up and close. For now I'll use the serial mechanism, but a) this uses up one of the serial ports which could be used for a multi-line door game :) and b) I'll have to make up my own comm mechanism for it. No big deal but just wanted to see what you all thought!

copy commented 8 months ago

virtio would be the "modern" option, we've received support for that recently, but it requires a driver in the guest OS: https://github.com/copy/v86/pull/949

Using the serial port is a reasonable option too.

I wouldn't be opposed to implementing vmcall, i.e. a specific instruction sequence that gets a callback in the api.

cognitivegears commented 7 months ago

virtio would be the "modern" option, we've received support for that recently, but it requires a driver in the guest OS: #949

Using the serial port is a reasonable option too.

I wouldn't be opposed to implementing vmcall, i.e. a specific instruction sequence that gets a callback in the api.

Thanks! Unfortunately I don't think virtio works in my case specifically because I can't find a DOS driver for it; the standard looks pretty straightforward I might be able to write one but hat would definitely be shaving yaks. For now I'll stick with the serial I suppose. I definitely wouldn't be opposed to trying my hand at implementing the vmcall, though I haven't messed with the webassembly side of v86 yet, I would appreciate any pointers you have would be appreciated at where to start looking.

I appreciate the response, and thanks for an amazing project!

giulioz commented 6 months ago

@cognitivegears I did something similar to communicate to/from Windows 98, so it should work fine with MS-DOS as well. It works with I/O ports and sharing memory. https://github.com/giulioz/react-95-fiber/blob/main/src/emulator95/RpcAdapter.ts

bit-lang commented 1 month ago

@cognitivegears

I did something similar to communicate to/from Windows 98, so it should work fine with MS-DOS as well.

It works with I/O ports and sharing memory.

https://github.com/giulioz/react-95-fiber/blob/main/src/emulator95/RpcAdapter.ts

I wonder if it is possible to build upon your solution to implement a host-guest shared clipboard. It would be great if that's a yes.

giulioz commented 1 month ago

@bit-lang on which guest OS?

bit-lang commented 1 month ago

@bit-lang on which guest OS?

Windows 9x

giulioz commented 1 month ago

Ah yes with windows 9x 100%. If you are ok with a simpler method, I wrote a blog post about it: https://giuliozausa.dev/posts/bm-1-clipboard/

bit-lang commented 1 month ago

Ah yes with windows 9x 100%.

If you are ok with a simpler method, I wrote a blog post about it: https://giuliozausa.dev/posts/bm-1-clipboard/

Thank you. I will take a look at it

bit-lang commented 1 month ago

Ah yes with windows 9x 100%.

If you are ok with a simpler method, I wrote a blog post about it: https://giuliozausa.dev/posts/bm-1-clipboard/

I found that your solution is very brilliant and implementation is almost complete.