Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

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

posted by Arjay(R), 21.03.2012, 01:17
(edited by Arjay on 21.03.2012, 08:01)

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.

 

Complete thread:

Back to the forum
Board view  Mix view
15112 Postings in 1359 Threads, 247 registered users, 17 users online (0 registered, 17 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum