Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
Arjay

21.03.2012, 01:17
(edited by Arjay, 21.03.2012, 08:01)
 

Using Fabrice Bellard's runcom to run COM files under Linux (Announce)

Last year when the very talented Fabrice Bellard released his PC emulator in Javascript: JSLinux I immediately noted with great interest Fabrice's basic DOS support via his runcom util which I started playing around with as soon as the project was first announced.

Anyway, firstly here is runcom:

[arjay@linuxbox jslinux]# runcom
runcom version 0.2 (c) 2003-2011 Fabrice Bellard
usage: runcom file.com [args...]
Run simple .com DOS executables (linux vm86 test mode)
[arjay@linuxbox jslinux]#


Before doing anything else I would recommend if you've never seen JSLinux to check it out: WARNING: JSLinux will attempt to run immediately after you click this link - so before you click that link I would *STRONGLY* suggest reading the JSLinux FAQ and JSLinux tech pages first - re browser compatibility etc!

Runcom is very powerful little Linux util as it stands but is far far from perfect, e.g. it does a very basic emulation of interrupt 21h. Just enough to run old versions of FreeDOS's debug NOTE that I said *OLD* not the latest.
In addition runcom doesn't emulate interrupt 10h or.... indeed... Well I'll just let this IVTUTIL decode of the save of interrupt vector table under runcom via debug speak for itself:
INT    VECTOR    POINTS TO
---    ------    ---------
$00   1000:3F84
$01   1000:3F8E
$02   0000:0000  NULL
$03   1000:3F98
$04   0000:0000  NULL
$05   0000:0000  NULL
.
.     0000:0000  NULL REPEATED ALL THE WAY UP TO:
.
$FF   0000:0000  NULL


Note: Int 00h, 01h, 03h were set by DEBUG! So Yup you've got it, runcom does a *VERY* basic emulation int 21h and...Int 20h and... oh wait that is basically pretty much most of it apart from a PSP (Program Segment Prefix) which runcom creates before the .COM file. Or to put it another way there is no interrupt vector table (prior to running anything default), no BDA (Bios Data Area), no BIOS even. Runcom is a fire up a basic .COM file and go...

However that aside IMHO runcom is still a very interesting and useful util to play with despite having limited DOS support - still I like a good challenge.... On a quick personal note I also have an interest in adding support for running a certain test project of mine under runcom, as various other places I have run my internal private builds. Still back to runcom, as I have been playing with runcom via JSLinux on and off for sometime I recently decided that I wanted to work with it locally to make it easier to test and dev for.... I also thought that others might be interested in doing the same. That way the good DOS community here can support the good work that Fabrice is doing and help JSLinux move forward with it's DOS support!


Downloading and compiling runcom
Below are the basic instructions below explain how to download Fabrice's runcom from his site, compile it on a Linux box to use with FreeDOS's v1.01 version of debug which is slightly newer than v0.98 that Fabrice uses with JSLinux but obviously not the latest which is currently v1.25.

1) download linuxstart-20120111.tar.gz from Fabrice's JSLinux">http://bellard.org/jslinux/tech.html]JSLinux tech page.

2) extract /tmp/linuxstart-20120111/runcom.c

3) compile runcom.c as follows
cc -o /usr/bin/runcom runcom.c

4)Download FreeDOS Debug v1.25 or v0.98 from:
http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/dos/debug/old/


5)extract/save debug.com as /usr/bin/debug.com

6) create a debug shell script as /usr/bin/debug as follows:

#!/bin/sh
# run DOS debug from Linux cmd-prompt
/usr/bin/runcom /usr/bin/debug.com $1 $2 $3 $4 $5 $6 $7 $8 $9


7) Set the Unix execute permissions appropriately.

8)Have fun, e.g:
[arjay@linuxbox jslinux]$ echo u | debug bttrdemo.com | write arjay


[arjay@linuxbox jslinux]$ echo u | debug bttrdemo.com | write arjay
------------------

Message from arjay@linuxbox on pts/0 at 16:02 ...
-u
1526:0100 B40F          MOV     AH,0F
1526:0102 CD10          INT     10
1526:0104 3C02          CMP     AL,02
1526:0106 7418          JZ      0120
1526:0108 3C03          CMP     AL,03
1526:010A 740D          JZ      0119
1526:010C 3C07          CMP     AL,07
1526:010E 7410          JZ      0120
1526:0110 BAFC03        MOV     DX,03FC
1526:0113 B409          MOV     AH,09
1526:0115 CD21          INT     21
1526:0117 CD20          INT     20
1526:0119 2EC706FC0200B8
                        MOV     WORD PTR CS:[02FC],B800
EOF



Patching runcom.c to resolve cosmetic issue with debug v1.01
FreeDOS's debug v1.01 using function 8h of interrupt 21h for a more prompt, e.g. if you type "?" for help. By default runcom doesn't support this function and typing "?" will produce the help screen but with an error message. Below is a very quick and dirty lazy patch to runcom.c to fix this.

Insert these 2 lines just before case 0x09 in runcom.c and recompile:


    case 0x08: /* input char without echo */
        break;

    case 0x09: /* write string */


All that code does is remove the error but without emulating the function.


Using other versions of FreeDOS debug under runcom
At this time I would recommend using v1.01 (slight issue see below) and avoiding everything else. Due to the following:

1.02 loads ok however CS=DS=0000 by default and reg values can't be changed
1.06 and later will fail, e.g. v1.25,v1.10 fail. Note; i started tested from both ends of the spectrum until I found other versions that worked.

Why do later versions fail? Lack of support for some of the calls that they make in runcom.c and use of unsupported interrupts. You could add your own interrupt handlers... ;)


How does runcom work?
In brief runcom works by using the Linux system call vm86() which provides a 16bit virtual machine however only on an Intel based (or emulated in the case of JSLinux machine) . vm86() is also used by DOSEmu:


#define __NR_vm86    166
#define __NR_vm86old 113


For more info see - http://unixhelp.ed.ac.uk/CGI/man-cgi?vm86+2


Help for runcom on BTTR forum
I don't really have much time at the moment to help others with runcom, however if you get stuck need some help let me know (via here) and I'll see if I can help as I am sure others will as well.

marcov

21.03.2012, 13:43

@ Arjay
 

Using Fabrice Bellard's runcom to run COM files under Linux

> How does runcom work?
> In brief runcom works by using the Linux system call vm86() which provides
> a 16bit virtual machine however only on an Intel based (or emulated in the
> case of JSLinux machine) . vm86() is also used by DOSEmu:

(note that with "intel" they mean 32-bit x86 class, not CPU's made by Intel only)

>
> #define __NR_vm86    166
> #define __NR_vm86old 113
>


IIRC most 32-bit OSes have such calls for interfacing with the bios, e.g. FreeBSD x86 has (machine/x86.h):

extern int vm86_emulate(struct vm86frame *);
extern int vm86_sysarch(struct thread *, char *);
extern void vm86_trap(struct vm86frame *);
extern int vm86_intcall(int, struct vm86frame *);
extern int vm86_datacall(int, struct vm86frame *, struct vm86context *);
extern void vm86_initialize(void);
extern vm_offset_t vm86_getpage(struct vm86context *, int);
extern vm_offset_t vm86_addpage(struct vm86context *, int, vm_offset_t);
extern int vm86_getptr(struct vm86context *, vm_offset_t, u_short *, u_short *)

extern vm_offset_t vm86_getaddr(struct vm86context *, u_short, u_short);

But the main problem of this technology, like all hardware VM based solutions, is that won't work under 64-bit OSes? Hence, investing in this kind of technology at this point doesn't really make sense, since for direct usage there are mature solutions like dosemu.

To properly support running 16-bit code, in time you need to move to technology that can emulate or JIT 16-bit code on any CPU.

Arjay

21.03.2012, 19:53

@ marcov
 

Using Fabrice Bellard's runcom to run COM files under Linux

> (note that with "intel" they mean 32-bit x86 class, not CPU's made by Intel
> only)
Correct. sorry for the tired typo. However obviously devices emulating such processors can also benefit. e.g. JSLinux. I should also mention for those interested that I noted that Fabrice created a related util called "qruncom" which was part of his "libqemu" package for QEMU - search for "qruncom.c"

> But the main problem of this technology, like all hardware VM based
> solutions, is that won't work under 64-bit OSes?
It will via an emulated CPU, e.g. as is the case of JSLinux via a browser.

> Hence, investing in this kind of technology at this point doesn't really
> make sense, since for direct usage there are mature solutions like dosemu.
For many people at this stage I would agree with you. However this is a personal choice and for those of us who are interested in working with lower level OS stuff and working to ensure flexibility for running DOS apps across platforms then runcom offers up interesting possibilities over DOSEMU etc.

Ibidem

30.03.2012, 01:00

@ Arjay
 

Using Fabrice Bellard's runcom to run COM files under Linux

> > But the main problem of this technology, like all hardware VM based
> > solutions, is that won't work under 64-bit OSes?
> It will via an emulated CPU, e.g. as is the case of JSLinux via a browser.
>
> > Hence, investing in this kind of technology at this point doesn't really
> > make sense, since for direct usage there are mature solutions like
> dosemu.

Look up libx86 sometime...;-)
Linux folks aren;t as unconcerned about realmode instructions as you might think.

Rugxulo

Homepage

Usono,
31.03.2012, 00:47

@ Ibidem
 

Using Fabrice Bellard's runcom to run COM files under Linux

> Look up libx86 sometime...;-)
> Linux folks aren;t as unconcerned about realmode instructions as you might
> think.

A quick search shows that libx86 is based upon lrmi by Josh Vanderhoof, who was the guy who wrote the "Cross ELF" mini toolset back in the day (1998?) for DJGPP, Win32, and Linux.

marcov

31.03.2012, 09:15

@ Ibidem
 

Using Fabrice Bellard's runcom to run COM files under Linux

> > > Hence, investing in this kind of technology at this point doesn't
> really
> > > make sense, since for direct usage there are mature solutions like
> > dosemu.
>
> Look up libx86 sometime...;-)
> Linux folks aren;t as unconcerned about realmode instructions as you might
> think.

For what? Doing a few "detection" calls during startup on a minimal emulator?

Because that is what it is mainly for, I used it when I still had a bunch of desktop powermacs. One would switch OF (the Apple firmware/bootloader) and kernel to serial, and then use a normal x86 videocard (and not some overpriced mac specific ATI card with an already old chipset), and then libx86 would initialize the videocard.

I'm not sure if it is still used much, since most bioses support the most basic functionality (init SATA, and I assume the video bios too) via 32-bit calls?

The fact that that page mentions alpha (which is essentially dead since before 2000) says enough.....

Rugxulo

Homepage

Usono,
10.04.2012, 00:26

@ marcov
 

libx86 / Alpha

> > Look up libx86 sometime... ;-)
> > Linux folks aren't as unconcerned about realmode instructions as you might think.
>
> For what? Doing a few "detection" calls during startup on a minimal
> emulator?
>
> I used it when I still had a bunch of desktop powermacs.
>
> I'm not sure if it is still used much.
>
> The fact that that page mentions alpha (which is essentially dead since
> before 2000) says enough....

LRMI's last release seems to have been in 2005 (though with a very tiny change in CVS in 2008). libx86 copyright says 2006. FreeBSD 6.4 (2008) was last to support Alpha, as you probably already know.

I've never used an Alpha, and supposedly they have a lot of minor variations in their models, so it's not super easy to support them all. And of course it's not mass-produced anymore, esp. since DEC long ago folded / sold it / got bought out. Circa 1992 until 2004 ain't too bad, though, for a 64-bit RISC processor topping out at approx. 1.3 Ghz (and thus surpassed in performance by latest x86 cpus). I don't even think GCC properly supports it anymore, or it doesn't look like it's a big priority for them, at least. (And of course Win2K RC1 was last to officially support it, I think, but Compaq wasn't too interested in paying for it.) There are a few Alpha emulators, but I've never tried them.

I dunno, though, FreeBSD has vm86() or such syscall, right? At least used to, though I guess nobody has ever tried to get DOSEMU working since a long time ago. Admittedly, BIOS isn't popular for various reasons (bugs, non-reentrant), though I don't see an easy replacement (at least nothing that will please most people, probably Linux + Windows is considered "good enough"). Coreboot still doesn't support a lot, and rumors of UEFI assimilating us all are always present, so who knows.

P.S. Honestly, I'm not sure the point you were trying to make. And I almost want to (barely) debate about how/why things aren't supported forever (though usually for inane reasons) instead of having decisions based upon end-user convenience or technical merit or whatever random virtue I can imagine, heh. I don't know, it's just weird to try to understand such a complex (tech) world.

Rugxulo

Homepage

Usono,
19.04.2012, 05:40

@ marcov
 

Using Fabrice Bellard's runcom to run COM files under Linux

> (note that with "intel" they mean 32-bit x86 class, not CPU's made by Intel
> only)

The x86 market is like 80% Intel and 20% AMD with very few others (VIA).

> IIRC most 32-bit OSes have such calls for interfacing with the bios, e.g.
> FreeBSD x86 has (machine/x86.h):

Oops, I missed where you explicitly said FreeBSD here.

> But the main problem of this technology, like all hardware VM based
> solutions, is that won't work under 64-bit OSes?

V86 (1986) was dropped with AMD64 (2003) but more or less VT-X (2006, 2010) brought back real mode support, if only you buy a cpu with such support. I've run FreeDOS under VirtualBox (with its own fake BIOS, IIRC) atop Win7 64-bit host, it's much much faster than without.

> Hence, investing in this
> kind of technology at this point doesn't really make sense, since for
> direct usage there are mature solutions like dosemu.

Mature, yes, works fairly well but is still dirt slow for emulating 16-bit stuff when under AMD64 (though 32-bit DJGPP stuff is native speed). But I don't know how much "JIT"'ing or VT-X or multi-core or threads they utilize (if any).

DOSBox is much easier to port and build due to SDL and C++, hence it's more widely available than DOSEMU (which doesn't support FreeBSD since a long time ago, AFAIK).

> To properly support running 16-bit code, in time you need to move to
> technology that can emulate or JIT 16-bit code on any CPU.

Java has a JIT yet things like JDOSBox and JPC are still fairly slow. Even QEMU and BOCHS, last I checked a few years ago, weren't great. And VirtualBox is a pain without VT-X. Sadly, all emulation is difficult to do with reasonable speed, and you often get 10x slowdown (or worse!).

Actually, I was reading Darek Mihocka's blog again recently. I know I've mentioned him here once or twice. Well, apparently he used to work for MS, Intel (even recently), etc. He is very savvy and has tons of experience in emulation, and he goes on and on about how this and that is difficult or messes things up (EFLAGS, too many branches). He has worked on tweaking BOCHS (C++) in recent years, so who knows, maybe it's reasonable speed now (though I doubt it, heh).

P.S. Read up on Loongson 3 (MIPS-based), it has some hardware helpers to speed up QEMU x86 emulation to within 70% (allegedly).

Arjay

16.04.2012, 21:14
(edited by Arjay, 16.04.2012, 21:43)

@ Arjay
 

Emu8080-Stefan Tramm's Intel 8080 CPU Emulator running CP/M

Old 2010 news. But Stefan Tramm's Emu8080 - an Intel 8080 CPU Emulator running CP/M might be of interest to others on here if not familiar with it already. However licensing issues? Note: I own legal copies of CP/M but it seems to me that there is still confusion re the licensing for CP/M?

Digital Research: CP/M is not in the public domain
vs
TheRegister: CP/M collection is back online with an Open Source licence / cpm.z80.de: Lineo, Inc. license granted in 2001.

On a related note love Grant Searle's CP/M on breadboard using 12 IC's = A: prompt! neat.

Rugxulo

Homepage

Usono,
17.04.2012, 00:03

@ Arjay
 

Emu8080-Stefan Tramm's Intel 8080 CPU Emulator running CP/M

> Old 2010 news. But Stefan Tramm's Emu8080 -
> an Intel 8080 CPU Emulator running
> CP/M might be of interest to others on here if not familiar with it
> already. However licensing issues? Note: I own legal copies of CP/M but
> it seems to me that there is still confusion re the licensing for CP/M?

Isn't that frustrating when licensing is unclear and there is no (obvious) person to ask?? Annoying, but nobody cares about "old" when new is all shiny (but patent encumbered, ugh).

Anyways, don't worry, I do actually have something useful to add to this thread (though I've never used CP/M):

http://nanochess.110mb.com/emulator.html

:-D :-D :-D

---
Know your limits.h

Ibidem

17.04.2012, 08:47

@ Arjay
 

Emu8080-Stefan Tramm's Intel 8080 CPU Emulator running CP/M

> it seems to me that there is still confusion re the licensing for CP/M?

> Digital Research: CP/M
> is not in the public domain
(From a 1998 FAQ)
> vs
> TheRegister:
> CP/M collection is back online with an Open Source licence /
> cpm.z80.de: Lineo, Inc. license
> granted in 2001.

Note: Public domain means there is no license. Open source usually means there is a license, but it allows modification and redistribution.
This is an example of that. No conflict, and it's also 1998 vs 2001 information: it would have been quite possible for the first one to be out-of-date.

The license covers "CP/M technology", which includes everything related to CP/M in source or binary form, if it came from DRI.

Rugxulo

Homepage

Usono,
17.04.2012, 19:49

@ Ibidem
 

Emu8080-Stefan Tramm's Intel 8080 CPU Emulator running CP/M

> > CP/M collection is back online with an Open Source licence[/link] /
> > cpm.z80.de: Lineo, Inc. license
> > granted in 2001.

"Subject: Re: Unofficial CP/M Website/licensing of CP/M material
To: gaby_UT_gaby_DUT_de
Date sent: Fri, 19 Oct 2001 10:36:31 -0600

Bryan Sparks
CEO Lineo, Inc."

Does Lineo even exist anymore? Weren't they a spin-off of Caldera? Digital Research, do they still exist?? I thought (last I checked) that Bryan Sparks worked for DR-DOS, Inc. [sic], which still sells DR-DOS 7.03.

http://drdos.com/company/namagement/ [sic!]

"Bryan W. Sparks -- (bryan_UT_drdos_DUT_com) is a seasoned software engineer and entrepreneur."

Or you could email them at info_UT_drdos_DUT_com . If you're really worried, I mean, this is a decent lead, no? (naive) I wouldn't know of a better person to ask, would you?

Arjay

22.04.2012, 18:57

@ Arjay
 

Grant Searle's CP/M on breadboard - updated 21st April 2012

> Grant Searle's
> CP/M on breadboard using 12 IC's = A: prompt! neat.

I have now had the pleasure of swapping a few emails with Grant and understand that he succcesfully got his CP/M machine up and running again. He has also now updated his page to say the following: UPDATE - due to several requests, I have restarted work on this page - will update with code and HEX files etc. as soon as possible.

Excellent news! So keep an eye on his page.

Arjay

04.05.2012, 22:54

@ Arjay
 

Grant Searle's CP/M on breadboard - updated 26th April 2012

> keep an eye on his page.

Grant has kindly further updated his CP/M on breadboard project page on the 26th April with a LOT of extra information meaning others will now be able to construct his project.

The rest of Grant's website is also worth checking out:
http://home.micros.users.btopenworld.com/

Thanks for sharing all of your hard work, Grant!

Arjay

02.08.2012, 00:37

@ Arjay
 

Grant Searle's CP/M on breadboard - updated 26th April 2012

> > keep an eye on his page.

BT is shutting down its free web hosting, so the pages that were on this site have been moved to another hosting service. The all remain exactly the same, and 100% of them are still alive and are being maintained. Please update your bookmarks or links. This page will disappear soon.

New link: http://searle.hostei.com/grant/cpm/index.html


> The rest of Grant's website is also worth checking out:
The new address of my main page is http://searle.hostei.com/grant/


On a semi-related note the C64 is 30 years old today (01/August/2012): Commodore 64 turns 30: What do today's kids make of it?

It's articles like the above that start to make me feel old. Probably not helped by reading a DOS book last night that said "this was introduced in the new version of DOS"... 2.0 !! The particular book was published in 1984 mind.

Arjay

05.08.2013, 19:05

@ Arjay
 

Grant Searle's CP/M on breadboard - updated 23th July 2013

> [b]New link:
> http://searle.hostei.com/grant/cpm/index.html

I received an important update direct from Grant via email (23 July, 2013):

> Someone has just spotted an omission from the schematic. The DCDA
> and DCDB pins should be connected to ground, otherwise the interface
> is intermittent. They are connected on my machine (you can see it on the
> pics) but I missed it on the schematic. Strange, several others have
> built it with no issue, maybe these pins normally float to ground if not
> connected? Anyway, to be safe, please make sure the DCDA and DCDB pins on > the SIO are connected to ground.
>
> Apologies for this, but I thought I?d better let you
> know as soon as I was told.
>
> I have updated the schematics on the page, but you will
> need to refresh the
> browser page to see it.


A project I would love to build entirely from scratch if I had more time :-(

Back to index page
Thread view  Board view
22049 Postings in 2034 Threads, 396 registered users, 272 users online (0 registered, 272 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum