Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"From there to here, from here to there, funny things are everywhere." -- Dr. Seuss


devel / comp.os.msdos.programmer / Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

SubjectAuthor
* [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
+* [OpenWatcom] building a COM file without pulling in the Watcom standard libraryJJ
|`* [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
| `- [OpenWatcom] building a COM file without pulling in the Watcom standard libraryT. Ment
+* [OpenWatcom] building a COM file without pulling in the WatcomAlexei A. Frounze
|`* [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
| `* [OpenWatcom] building a COM file without pulling in the WatcomAlexei A. Frounze
|  `- [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
+* [OpenWatcom] building a COM file without pulling in the Watcom standard libraryR.Wieser
|`* [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
| +- [OpenWatcom] building a COM file without pulling in the Watcom standard libraryR.Wieser
| `* [OpenWatcom] building a COM file without pulling in the Watcom standard libraryR.Wieser
|  `* [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
|   `* [OpenWatcom] building a COM file without pulling in the Watcom standard libraryR.Wieser
|    `* [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
|     `* [OpenWatcom] building a COM file without pulling in the Watcom standard libraryR.Wieser
|      `- [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste
`- [OpenWatcom] building a COM file without pulling in the WatcomMateusz Viste

1
[OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230731172858.11ce54d9@mateusz>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=350&group=comp.os.msdos.programmer#350

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Mon, 31 Jul 2023 17:28:58 +0200
Organization: ...
Lines: 64
Message-ID: <20230731172858.11ce54d9@mateusz>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="da1483b069615d99ce7ff97b71fb2c69";
logging-data="3480092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/x97kEQRot8rPD+yCYaXZB"
Cancel-Lock: sha1:w0AtzfiJumz0n6/Noy+rFTz4B1Y=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Mon, 31 Jul 2023 15:28 UTC

Hello all,

I am experimenting with OpenWatcom, trying to compile a simple C
file into a COM executable. The tricky part is that I'd like to avoid
pulling in watcom's standard library and startup code in the process.

I have such TEST.C file:

void main(void) {
static char *hello = "Hello$";
_asm {
mov ah, 9
mov dx, hello
int 0x21
}
}

I compile it into an object and pass to wlink using these commands:

wcc -0 -ms -od -s -d0 -zl -zls test.c
wlink @TEST.LNK

I filled TEST.LNK with the following directives:

FORMAT DOS COM
FILE test.obj
OPTION NODEFAULTLIBS
NAME TEST.COM
OPTION START=main_

I do get "something" out of this, but the binary file does not work
properly. The disassembled COM looks like that:

00000000 53 push bx
00000001 51 push cx
00000002 52 push dx
00000003 56 push si
00000004 57 push di
00000005 B409 mov ah,0x9
00000007 8B160C00 mov dx,[0xc] <-- this should be 0x11C
0000000B CD21 int 0x21
0000000D 5F pop di
0000000E 5E pop si
0000000F 5A pop dx
00000010 59 pop cx
00000011 5B pop bx
00000012 C3 ret
00000013 004865 add [bx+si+0x65],cl
00000016 6C insb
00000017 6C insb
00000018 6F outsw
00000019 2400 and al,0x0
0000001B 0004 add [si],al <-- this should be 0x114
0000001D 00 db 0x00

It appears that the COM file is not being originated at offset 0x100,
despite the "FORMAT DOS COM" wlink directive. It's also not
0-originated, so I am not sure how the offsets are calculated exactly.
Once I fix them with a hex editor, the executable works.

What am I missing here?

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<1ag0mcoyxi8ep$.1fnwa248funqd$.dlg@40tude.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=351&group=comp.os.msdos.programmer#351

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jj4public@outlook.com (JJ)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library
Date: Tue, 1 Aug 2023 18:38:45 +0700
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <1ag0mcoyxi8ep$.1fnwa248funqd$.dlg@40tude.net>
References: <20230731172858.11ce54d9@mateusz>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="c6658fdce18cae15d9de900c48b7f3ec";
logging-data="3841962"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8AIBkE3PUf5Gvl0wWfBQslrtsXNlOBQM="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:19RjNdvoDIA8xGXc+NIS32/ixkk=
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
 by: JJ - Tue, 1 Aug 2023 11:38 UTC

On Mon, 31 Jul 2023 17:28:58 +0200, Mateusz Viste wrote:
> Hello all,
>
> I am experimenting with OpenWatcom, trying to compile a simple C
> file into a COM executable. The tricky part is that I'd like to avoid
> pulling in watcom's standard library and startup code in the process.
>
> I have such TEST.C file:
>
> void main(void) {
> static char *hello = "Hello$";
> _asm {
> mov ah, 9
> mov dx, hello
> int 0x21
> }
> }

The `hello` from `mov dx, hello` in assembly's perspective, means the
content of the variable. Not its address. You'll need to use the `offset`
operator. i.e.

mov dx, offset hello

> I filled TEST.LNK with the following directives:
>
> FORMAT DOS COM
> FILE test.obj
> OPTION NODEFAULTLIBS
> NAME TEST.COM
> OPTION START=main_

I'm not familiar with Watcom linker, but the linker user's guide says to use
these:

system com
option map
name app_name
file obj1, obj2, ...
library lib1, lib2, ...

https://open-watcom.github.io/open-watcom-v2-wikidocs/lguide.pdf

Section "2.2.2 Linking 16-bit x86 DOS .COM Executable Files". Page 8.

> I do get "something" out of this, but the binary file does not work
> properly. The disassembled COM looks like that:
>
> 00000000 53 push bx
> 00000001 51 push cx
> 00000002 52 push dx
> 00000003 56 push si
> 00000004 57 push di
> 00000005 B409 mov ah,0x9
> 00000007 8B160C00 mov dx,[0xc] <-- this should be 0x11C
> 0000000B CD21 int 0x21
> 0000000D 5F pop di
> 0000000E 5E pop si
> 0000000F 5A pop dx
> 00000010 59 pop cx
> 00000011 5B pop bx
> 00000012 C3 ret
> 00000013 004865 add [bx+si+0x65],cl
> 00000016 6C insb
> 00000017 6C insb
> 00000018 6F outsw
> 00000019 2400 and al,0x0
> 0000001B 0004 add [si],al <-- this should be 0x114
> 0000001D 00 db 0x00
>
> It appears that the COM file is not being originated at offset 0x100,
> despite the "FORMAT DOS COM" wlink directive. It's also not
> 0-originated, so I am not sure how the offsets are calculated exactly.
> Once I fix them with a hex editor, the executable works.

If you disassembed a binary using a blind disassembler (which don't know
binary file format, and platform), all file bytes will be treated as code,
and will start at zero or at disassembler application's predefined address.

Also check the compiled binary. Make sure it doesn't start with "MZ", which
is an EXE binary. IOTW, you have an EXE binary named as a COM file. In this
case, if the code, the data, and the stack segments are all the same
(usually a Tiny memory model module), try using a tool like EXE2BIN to
extract only the EXE body (excluding header).

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230801145039.04a32a34@mateusz.lan>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=352&group=comp.os.msdos.programmer#352

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Tue, 1 Aug 2023 14:50:39 +0200
Organization: ...
Lines: 68
Message-ID: <20230801145039.04a32a34@mateusz.lan>
References: <20230731172858.11ce54d9@mateusz>
<1ag0mcoyxi8ep$.1fnwa248funqd$.dlg@40tude.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="b35ef12d1b780f2f34359248a4e27839";
logging-data="3832313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tQb9RgdXc1weYGHqD7dxB"
Cancel-Lock: sha1:48O6VaN2mpjHAUBw7J4QfkyDXDo=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Tue, 1 Aug 2023 12:50 UTC

dn. Tue, 1 Aug 2023 18:38:45 +0700, JJ napisał:
> > void main(void) {
> > static char *hello = "Hello$";
> > _asm {
> > mov ah, 9
> > mov dx, hello
> > int 0x21
> > }
> > }
>
> The `hello` from `mov dx, hello` in assembly's perspective, means the
> content of the variable. Not its address.

Sure, but the variable at hand is a pointer, so what I am effectively
interested in is where it points to (ie. its content). The variable
itself acts only as a convenient label.

> > FORMAT DOS COM
> > FILE test.obj
> > OPTION NODEFAULTLIBS
> > NAME TEST.COM
> > OPTION START=main_
>
> I'm not familiar with Watcom linker, but the linker user's guide says
> to use these:
>
> system com

Yes, and the program I posted does work all right when linked as
"system com", but a side effect of "system com" is that it forces the
import of watcom's startup code and symbols. "format dos com" does not
(but yields a non-working binary where I have to fix addresses by hand
with a hex editor).

> If you disassembed a binary using a blind disassembler (which don't
> know binary file format, and platform), all file bytes will be
> treated as code, and will start at zero or at disassembler
> application's predefined address.

This is a COM file, so it's raw code. The only data here is the "hello"
string, but it's placed at the end of the binary so it's easy to spot.

> Also check the compiled binary. Make sure it doesn't start with "MZ",

I posted the exact, full content of the binary. It's a COM file, no MZ.

Earlier today I stumbled upon an interesting stackoverflow discussion,
where Peter Szabo was trying to achieve something very similar to what
I am doing now, and Michael Petch provided some deep insight into the
matter:
https://stackoverflow.com/questions/62473231/small-model-dos-exe-compiled-and-linked-by-openwatcom-crashes

My understanding is that wlink needs the startup code to figure out how
to lay out the program's memory. Things seem to be much more convoluted
than I expected, even for building a simple COM image.

Peter Szabo ended up creating a specialized tool to solve the problem:
https://github.com/pts/dosmc/blob/master/dosmc.dir/dosmc.pl

This is not a road I am willing to take, since I was simply (naively,
perhaps) looking for a way of building minimalist COM files using the C
language, hoping that Open Watcom would be able to do so, if properly
instructed. I think now that I might be using the wrong tool for the
job.

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<q55ici9v8rq109ta811n57uj1ocq2o9nhs@4ax.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=353&group=comp.os.msdos.programmer#353

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: t.ment@protocol.invalid (T. Ment)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library
Date: Tue, 01 Aug 2023 15:23:21 +0100
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <q55ici9v8rq109ta811n57uj1ocq2o9nhs@4ax.com>
References: <20230731172858.11ce54d9@mateusz> <1ag0mcoyxi8ep$.1fnwa248funqd$.dlg@40tude.net> <20230801145039.04a32a34@mateusz.lan>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="8d227e4a3e205481f1bca4a6947a6920";
logging-data="3890322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tb8oEo4RxqHFCjrTaT9K4HXuVIzs8i4Q="
Cancel-Lock: sha1:zurKfNjypcBK2ScjLzLWcytIaHI=
X-Newsreader: Forte Agent 1.93/32.576 English (American)
 by: T. Ment - Tue, 1 Aug 2023 14:23 UTC

On Tue, 1 Aug 2023 14:50:39 +0200, Mateusz Viste wrote:

> looking for a way of building minimalist COM files using the C
> language, hoping that Open Watcom would be able

Turbo C tiny model maybe. Never needed one myself though. IDK.

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<94cc74f4-c979-4637-a149-b02ec221c1c5n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=355&group=comp.os.msdos.programmer#355

  copy link   Newsgroups: comp.os.msdos.programmer
X-Received: by 2002:ac8:5c03:0:b0:40c:8ba5:33e6 with SMTP id i3-20020ac85c03000000b0040c8ba533e6mr65355qti.6.1691033315309;
Wed, 02 Aug 2023 20:28:35 -0700 (PDT)
X-Received: by 2002:a05:6870:5b08:b0:1bb:f2f:2a66 with SMTP id
ds8-20020a0568705b0800b001bb0f2f2a66mr18202649oab.10.1691033315122; Wed, 02
Aug 2023 20:28:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.msdos.programmer
Date: Wed, 2 Aug 2023 20:28:34 -0700 (PDT)
In-Reply-To: <20230731172858.11ce54d9@mateusz>
Injection-Info: google-groups.googlegroups.com; posting-host=98.47.8.185; posting-account=r_UqYQoAAADroB0Qe_EzH25J5Oyuce4G
NNTP-Posting-Host: 98.47.8.185
References: <20230731172858.11ce54d9@mateusz>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <94cc74f4-c979-4637-a149-b02ec221c1c5n@googlegroups.com>
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
From: alexfrunews@gmail.com (Alexei A. Frounze)
Injection-Date: Thu, 03 Aug 2023 03:28:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3256
 by: Alexei A. Frounze - Thu, 3 Aug 2023 03:28 UTC

On Monday, July 31, 2023 at 8:29:00 AM UTC-7, Mateusz Viste wrote:
> Hello all,
>
> I am experimenting with OpenWatcom, trying to compile a simple C
> file into a COM executable. The tricky part is that I'd like to avoid
> pulling in watcom's standard library and startup code in the process.
>
> I have such TEST.C file:
>
> void main(void) {
> static char *hello = "Hello$";
> _asm {
> mov ah, 9
> mov dx, hello
> int 0x21
> }
> }
>
> I compile it into an object and pass to wlink using these commands:
>
> wcc -0 -ms -od -s -d0 -zl -zls test.c
> wlink @TEST.LNK
>
> I filled TEST.LNK with the following directives:
>
> FORMAT DOS COM
> FILE test.obj
> OPTION NODEFAULTLIBS
> NAME TEST.COM
> OPTION START=main_
>
> I do get "something" out of this, but the binary file does not work
> properly. The disassembled COM looks like that:
>
> 00000000 53 push bx
> 00000001 51 push cx
> 00000002 52 push dx
> 00000003 56 push si
> 00000004 57 push di
> 00000005 B409 mov ah,0x9
> 00000007 8B160C00 mov dx,[0xc] <-- this should be 0x11C
> 0000000B CD21 int 0x21
> 0000000D 5F pop di
> 0000000E 5E pop si
> 0000000F 5A pop dx
> 00000010 59 pop cx
> 00000011 5B pop bx
> 00000012 C3 ret
> 00000013 004865 add [bx+si+0x65],cl
> 00000016 6C insb
> 00000017 6C insb
> 00000018 6F outsw
> 00000019 2400 and al,0x0
> 0000001B 0004 add [si],al <-- this should be 0x114
> 0000001D 00 db 0x00
>
> It appears that the COM file is not being originated at offset 0x100,
> despite the "FORMAT DOS COM" wlink directive. It's also not
> 0-originated, so I am not sure how the offsets are calculated exactly.
> Once I fix them with a hex editor, the executable works.
>
> What am I missing here?

If you make your own startup code with proper
----8<----
org 100h
_cstart_:
....
end _cstart_
----8<----
It may just work.

Alex

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230803102132.66863caa@mateusz>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=357&group=comp.os.msdos.programmer#357

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Thu, 3 Aug 2023 10:21:32 +0200
Organization: ...
Lines: 18
Message-ID: <20230803102132.66863caa@mateusz>
References: <20230731172858.11ce54d9@mateusz>
<94cc74f4-c979-4637-a149-b02ec221c1c5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="0e507c527cf7a0a57f550c1c0c79a194";
logging-data="708238"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18K8BhPlZo61T401hTNso6V"
Cancel-Lock: sha1:VhhGJpWbIbTWhlWsYxyTa4zUAGk=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Thu, 3 Aug 2023 08:21 UTC

dn. Wed, 2 Aug 2023 20:28:34 -0700 (PDT), Alexei A. Frounze napisał:
> If you make your own startup code with proper
> ----8<----
> org 100h
> _cstart_:
> ...
> end _cstart_
> ----8<----
> It may just work.

Is org 100h really required in this context? Isn't it the job of the
linker to compute proper addresses?

I tried nonetheless, but nasm does not understand the "org" directive
when using the -f obj target. It's apparently only valid for -f bin.

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<uafp57$m0mf$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=358&group=comp.os.msdos.programmer#358

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: address@is.invalid (R.Wieser)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library
Date: Thu, 3 Aug 2023 10:39:49 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <uafp57$m0mf$1@dont-email.me>
References: <20230731172858.11ce54d9@mateusz>
Injection-Date: Thu, 3 Aug 2023 08:40:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a7314cc104895da6d8e297df0c87be1a";
logging-data="721615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iEszyfm2wXnyFMaHlNxNtOvhH9Hgot8OhCwq7ha2Ang=="
Cancel-Lock: sha1:CkW3DIX1LF9iY+bFJA2v42+Io8w=
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-MSMail-Priority: Normal
X-Priority: 3
X-RFC2646: Format=Flowed; Original
 by: R.Wieser - Thu, 3 Aug 2023 08:39 UTC

Mateusz,

> I filled TEST.LNK with the following directives:
....
> OPTION START=main_

A COM file *always* starts at 0x0100. Maybe this directive interferes with
it ?

> 00000007 8B160C00 mov dx,[0xc] <-- this should be 0x11C

the 0xC is almost the offset from that commands address to the string (off
by one). IOW, it looks like the resolving (by "wlink") didn't quite kick
in. Maybe the linker needs to be told that it is converting a COM style
program too ?

> 0000001B 0004 add [si],al <-- this should be 0x114

AFAIKS everything from address 0x1A is beyond your code/program. IOW, no
idea what the remark is about.

Regards,
Rudy Wieser

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230803120734.34e59904@mateusz>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=359&group=comp.os.msdos.programmer#359

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Thu, 3 Aug 2023 12:07:34 +0200
Organization: ...
Lines: 43
Message-ID: <20230803120734.34e59904@mateusz>
References: <20230731172858.11ce54d9@mateusz>
<uafp57$m0mf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="0e507c527cf7a0a57f550c1c0c79a194";
logging-data="744216"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194SwUQ9emWWIMMGh8/3yXw"
Cancel-Lock: sha1:noxKo6mASLbpATK8XZW6BezjK6E=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Thu, 3 Aug 2023 10:07 UTC

dn. Thu, 3 Aug 2023 10:39:49 +0200, R.Wieser napisał:
> > OPTION START=main_
>
> A COM file *always* starts at 0x0100. Maybe this directive
> interferes with it ?

Without "OPTION START" the result is exactly the same, with the only
difference that wlink complains about "no starting address found".

> > 00000007 8B160C00 mov dx,[0xc] <-- this should be
> > 0x11C
>
> the 0xC is almost the offset from that commands address to the string
> (off by one). IOW, it looks like the resolving (by "wlink") didn't
> quite kick in. Maybe the linker needs to be told that it is
> converting a COM style program too ?

The only wlink options I found in this context are "FORMAT DOS COM" and
"SYSTEM COM". The former is not computing addresses properly (as
shown in this thread) and the latter forces watcom's startup code to be
pulled in, resulting in a kilobyte of bloat.

Looking at the DOSMC tool from Peter Szabo it looks like there is
quite some hoops to jump over: https://github.com/pts/dosmc
I was probably a bit naive to think that there would be a ready-to-go
wlink switch that would generate working COM files without the watcom
startup bloat.

> > 0000001B 0004 add [si],al <-- this should be 0x114
>
> AFAIKS everything from address 0x1A is beyond your code/program.
> IOW, no idea what the remark is about.

You are correct that 0x1B is beyond code, but it is not beyond data.
My understanding is that the "04 00" value starting at 1Ch is a near
pointer that is supposed to be loaded by mov dx,[0x0c] (ie. "load DX
with the value at memory location 0x0C"). Both the MOV and the pointer
are badly addressed though, that is why I needed to fix them both by
hand to get a working executable. How the values 0x000C and 0x0004
have been computed exactly, this I have no idea.

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<uag6v2$ouon$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=361&group=comp.os.msdos.programmer#361

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: address@is.invalid (R.Wieser)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library
Date: Thu, 3 Aug 2023 14:35:29 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <uag6v2$ouon$1@dont-email.me>
References: <20230731172858.11ce54d9@mateusz><uafp57$m0mf$1@dont-email.me> <20230803120734.34e59904@mateusz>
Injection-Date: Thu, 3 Aug 2023 12:35:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a7314cc104895da6d8e297df0c87be1a";
logging-data="817943"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/SzPwbZoggUZqfmGeNY5mKiVHk09yFkl5cu2kIHRClaA=="
Cancel-Lock: sha1:TQURXEnXCtYexRVIoqTnoN49XXI=
X-MSMail-Priority: Normal
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
 by: R.Wieser - Thu, 3 Aug 2023 12:35 UTC

Mateusz,

>> A COM file *always* starts at 0x0100. Maybe this directive
>> interferes with it ?
>
>Without "OPTION START" the result is exactly the same, with the only
>difference that wlink complains about "no starting address found".

That strengthens my gut feeling that the linker program /also/ needs to be
told what kind of executable to generate - its faulty 0xC offset in the COM
program being a result of not exactly knowing what to do.

>> > 0000001B 0004 add [si],al <-- this should be 0x114
>>
>> AFAIKS everything from address 0x1A is beyond your code/program.
>> IOW, no idea what the remark is about.
>
>You are correct that 0x1B is beyond code, but it is not beyond data.
> My understanding is that the "04 00" value starting at 1Ch is a near
> pointer that is supposed to be loaded by mov dx,[0x0c]

Ackkk.... I overlooked that you are doing an indirect load. :-\

Hmmm. In that case your program seems to expect DS to be one segment (0x10
bytes) beyond the CS segment. Makes some sense, giving the data segment as
much free space as possible.

Its still strange for a pure COM file though. No idea how to determine that
DS-to-CS offset though (might be an internally-generated label)

> How the values 0x000C and 0x0004 have been computed exactly, this
> I have no idea.

See above. :-)

Regards,
Rudy Wieser

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<b9c3cd0a-d693-4ad4-ab5d-fb2bf165b409n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=363&group=comp.os.msdos.programmer#363

  copy link   Newsgroups: comp.os.msdos.programmer
X-Received: by 2002:a05:620a:4d92:b0:76a:eab0:8581 with SMTP id uw18-20020a05620a4d9200b0076aeab08581mr1202qkn.8.1691116867822;
Thu, 03 Aug 2023 19:41:07 -0700 (PDT)
X-Received: by 2002:a05:6808:199c:b0:3a7:5f99:9fe1 with SMTP id
bj28-20020a056808199c00b003a75f999fe1mr587169oib.2.1691116867655; Thu, 03 Aug
2023 19:41:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.msdos.programmer
Date: Thu, 3 Aug 2023 19:41:07 -0700 (PDT)
In-Reply-To: <20230803102132.66863caa@mateusz>
Injection-Info: google-groups.googlegroups.com; posting-host=98.47.8.185; posting-account=r_UqYQoAAADroB0Qe_EzH25J5Oyuce4G
NNTP-Posting-Host: 98.47.8.185
References: <20230731172858.11ce54d9@mateusz> <94cc74f4-c979-4637-a149-b02ec221c1c5n@googlegroups.com>
<20230803102132.66863caa@mateusz>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b9c3cd0a-d693-4ad4-ab5d-fb2bf165b409n@googlegroups.com>
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
From: alexfrunews@gmail.com (Alexei A. Frounze)
Injection-Date: Fri, 04 Aug 2023 02:41:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3380
 by: Alexei A. Frounze - Fri, 4 Aug 2023 02:41 UTC

On Thursday, August 3, 2023 at 1:21:35 AM UTC-7, Mateusz Viste wrote:
> dn. Wed, 2 Aug 2023 20:28:34 -0700 (PDT), Alexei A. Frounze napisał:
> > If you make your own startup code with proper
> > ----8<----
> > org 100h
> > _cstart_:
> > ...
> > end _cstart_
> > ----8<----
> > It may just work.
> Is org 100h really required in this context? Isn't it the job of the
> linker to compute proper addresses?

Perhaps, but that's how the OBJ/OMF format has worked for years
in TASM, MASM, WASM.

> I tried nonetheless, but nasm does not understand the "org" directive
> when using the -f obj target. It's apparently only valid for -f bin.

Why not just use WASM if you're already using WCC/WCL/WLINK/etc?

Anyhow, if you dig your beloved NASM's nasmdoc.txt, you'll find this:
----8<----
8.2.2 Using the `obj' Format To Generate `.COM' Files

If you are writing a `.COM' program as more than one module, you may
wish to assemble several `.OBJ' files and link them together into a
`.COM' program. You can do this, provided you have a linker capable
of outputting `.COM' files directly (TLINK does this), or
alternatively a converter program such as `EXE2BIN' to transform the
`.EXE' file output from the linker into a `.COM' file.

If you do this, you need to take care of several things:

(*) The first object file containing code should start its code
segment with a line like `RESB 100h'. This is to ensure that the
code begins at offset `100h' relative to the beginning of the
code segment, so that the linker or converter program does not
have to adjust address references within the file when
generating the `.COM' file. Other assemblers use an `ORG'
directive for this purpose, but `ORG' in NASM is a format-
specific directive to the `bin' output format, and does not mean
the same thing as it does in MASM-compatible assemblers.
----8<----

HTH,
Alex

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<uai619$161tu$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=364&group=comp.os.msdos.programmer#364

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: address@is.invalid (R.Wieser)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library
Date: Fri, 4 Aug 2023 08:31:49 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uai619$161tu$1@dont-email.me>
References: <20230731172858.11ce54d9@mateusz><uafp57$m0mf$1@dont-email.me> <20230803120734.34e59904@mateusz>
Injection-Date: Fri, 4 Aug 2023 06:32:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f7686e357115dd89ea9bc52f24df29a2";
logging-data="1247166"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18n7BMImuILbX3QUAnnDUUskgfKUvNYgvJaJRnLuUm+Sg=="
Cancel-Lock: sha1:Ike68ZCeEwAeOXyrpGqtQW/n4P4=
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
 by: R.Wieser - Fri, 4 Aug 2023 06:31 UTC

Mateusz,

Something I overlooked/ignored while trying to figure out those wonkey
offsets :

[quote=me]
A COM file *always* starts at 0x0100.
[quote]

> 00000000 53 push bx
....

Either your disassembler is doing something funny, or it really thinks your
program starts at 0x0000 (and not 0x0100) ...

Could you add a command like "lea ax,main" and see which address "main" gets
translated too ? It should ofcourse show 0x0100. If it does not not than
the linker didn't generate a COM style file to begin with.

Also, have you checked the binary contents of your (supposed) .COM file ?
If it starts with "MZ" ...

Regards,
Rudy Wieser

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230804140302.0a84f7fe@mateusz>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=365&group=comp.os.msdos.programmer#365

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Fri, 4 Aug 2023 14:03:02 +0200
Organization: ...
Lines: 42
Message-ID: <20230804140302.0a84f7fe@mateusz>
References: <20230731172858.11ce54d9@mateusz>
<94cc74f4-c979-4637-a149-b02ec221c1c5n@googlegroups.com>
<20230803102132.66863caa@mateusz>
<b9c3cd0a-d693-4ad4-ab5d-fb2bf165b409n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="653926adf29b0e676122033ba5be0ae9";
logging-data="1312575"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Vc1vhSfPTevmG79cAvVCK"
Cancel-Lock: sha1:RQ0a119wfHNhdds5S6uYbLSxp6Y=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Fri, 4 Aug 2023 12:03 UTC

dn. Thu, 3 Aug 2023 19:41:07 -0700 (PDT), Alexei A. Frounze napisał:
> > Is org 100h really required in this context? Isn't it the job of
> > the linker to compute proper addresses?
>
> Perhaps, but that's how the OBJ/OMF format has worked for years
> in TASM, MASM, WASM.

I didn't know that, I naively assumed the linker would recompute all
addresses.

> The first object file containing code should start its code
> segment with a line like `RESB 100h'. This is to ensure that
> the code begins at offset `100h' relative to the beginning
> of the code segment, so that the linker or converter program
> does not have to adjust address references within the file

Thanks for your research, it does explain quite some things. For
starters, it means that there is no chance to end up with working
machine code without inserting some kind of startup code that would
enforce the 0x100 address of the entry point (and probably perform some
other magic, like setting up segments to whatever expectations the C
compiler has...).

Before trying to (ab)use Open Watcom I shortly played with SmlrC. It
looked very promising, but its inline assembly wasn't resolving C
symbols (ie. asm "mov ax, myvar" was literally writing "mov ax,
myvar" into the resulting asm file instead of resolving the address of
the myvar short int).

I also glanced at Dave Dunfield's micro C, but found it even more
limited. And then there were a couple of other things I checked, but
they were mostly limited to a subset of K&R C.

Are there any alternative that would be able to generate a tiny (no
ugly startup code or libc calls) COM file based on ANSI C code with
inline assembly?

The only one I still have to check out is DOSMC by Peter Szabo,
but sadly it does not work in DOS.

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230804140324.0ae56909@mateusz>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=366&group=comp.os.msdos.programmer#366

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Fri, 4 Aug 2023 14:03:24 +0200
Organization: ...
Lines: 29
Message-ID: <20230804140324.0ae56909@mateusz>
References: <20230731172858.11ce54d9@mateusz>
<uafp57$m0mf$1@dont-email.me>
<20230803120734.34e59904@mateusz>
<uai619$161tu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="653926adf29b0e676122033ba5be0ae9";
logging-data="1312575"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fvLwxuav19I0UocMcz8jg"
Cancel-Lock: sha1:ri8GCk7w0Zhg0qh2j8D8PrcPr7E=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Fri, 4 Aug 2023 12:03 UTC

dn. Fri, 4 Aug 2023 08:31:49 +0200, R.Wieser napisał:
> Could you add a command like "lea ax,main" and see which address
> "main" gets translated too ? It should ofcourse show 0x0100. If it
> does not not than the linker didn't generate a COM style file to
> begin with.

Here it is:

00000005 8D060000 lea ax,[0x0]

Not unexpectedly, main() starts at offset 0 because the linker does not
compute the addresses with an extra +0x100. Which is the whole issue.

> Also, have you checked the binary contents of your (supposed) .COM
> file ? If it starts with "MZ" ...

The disassembly I posted in the initial message truly is the entirety
of the generated file. It starts with push bx. No "MZ" nor any other
header.

It appears that without startup code, wlink simply won't generate a
proper COM. Then one can either rely on the (huge! 1K) startup provided
by Watcom, by using the "SYSTEM COM" wlink directive, or hand-craft its
own startup code that would mimic whatever the original startup needs
to set up. In other words, I take there is no easy way to achieve what
I was looking for.

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<uaj216$1a8bc$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=367&group=comp.os.msdos.programmer#367

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: address@is.invalid (R.Wieser)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library
Date: Fri, 4 Aug 2023 16:29:24 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <uaj216$1a8bc$1@dont-email.me>
References: <20230731172858.11ce54d9@mateusz><uafp57$m0mf$1@dont-email.me><20230803120734.34e59904@mateusz><uai619$161tu$1@dont-email.me> <20230804140324.0ae56909@mateusz>
Injection-Date: Fri, 4 Aug 2023 14:29:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f7686e357115dd89ea9bc52f24df29a2";
logging-data="1384812"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RkEDEf+LHWLr5o+n1Hg6X8qphgrPzdbl7BLIeVAFnoA=="
Cancel-Lock: sha1:uYa3vPKZ8GDuQikql4uycbcurq8=
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
 by: R.Wieser - Fri, 4 Aug 2023 14:29 UTC

Mateusz,

> It appears that without startup code, wlink simply won't generate
> a proper COM.

I did a quick DDG search for "OpenWatcom create COM style file", got
https://stackoverflow.com/questions/46408334/com-executables-with-open-watcom
and noticed "BlackJack"s response.

From there I did another search for "OpenWatcom set model tiny", and from
the DDG result (https://github.com/open-watcom/open-watcom-v2/issues/275)
and your initial post I noticed that you are compiling with the "-ms" switch
(small memory model), which is incompatible with a COM style executable.
Try "-mt" (tiny memory model) instead.

Regards,
Rudy Wieser

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230804165638.7a6ec341@mateusz>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=368&group=comp.os.msdos.programmer#368

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Fri, 4 Aug 2023 16:56:38 +0200
Organization: ...
Lines: 73
Message-ID: <20230804165638.7a6ec341@mateusz>
References: <20230731172858.11ce54d9@mateusz>
<uafp57$m0mf$1@dont-email.me>
<20230803120734.34e59904@mateusz>
<uai619$161tu$1@dont-email.me>
<20230804140324.0ae56909@mateusz>
<uaj216$1a8bc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="653926adf29b0e676122033ba5be0ae9";
logging-data="1385097"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WDL1ObjkO9QmLk9X8Id3E"
Cancel-Lock: sha1:/o2fbJM5B+pWRdfMmE32/5G2XtM=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Fri, 4 Aug 2023 14:56 UTC

dn. Fri, 4 Aug 2023 16:29:24 +0200, R.Wieser napisał:
> I noticed that you are compiling with the "-ms" switch
> (small memory model), which is incompatible with a COM style
> executable. Try "-mt" (tiny memory model) instead.

"-ms" is the proper switch for compiling object files for COM
executables. In fact, the wcc compiler doesn't even understand -mt.

"-mt" is only a convenience switch for wcl (Watcom's "compile & link"
tool) so it knows that after executing wcc -ms it has to pass the
"SYSTEM COM" option to wlink.

Building a COM itself is well documented and hence easy to achieve. The
problem here is that I was trying to make Open Watcom build a tiny (as
in "very small") COM file by avoiding Watcom's libc and startup code,
ie. passing "OPTION NODEFAULTLIBS" to wlink. Then the COM file indeed
becomes very small, but it also ceases working, as the generated code
seems to expect to be executed within an environment prepared by
Watcom's startup routines.

Most probably my expectations towards Open Watcom were too high. It is
an awesome tool, but it's simply not designed to build minimalist COM
files without major hackery.

Such hackery have been done by Peter Szabo (aka pts). I tested just now
his DOSMC tool, and it compiled this program:

void main(void) {
static char *hello = "Hello$";
_asm {
lea ax, main
mov ah, 9
mov dx, hello
int 0x21
}
}

Into this:

00000000 E80400 call word 0x7
00000003 B44C mov ah,0x4c
00000005 CD21 int 0x21
00000007 53 push bx
00000008 51 push cx
00000009 52 push dx
0000000A 56 push si
0000000B 57 push di
0000000C 8D060701 lea ax,[0x107]
00000010 B409 mov ah,0x9
00000012 8B162501 mov dx,[0x125]
00000016 CD21 int 0x21
00000018 5F pop di
00000019 5E pop si
0000001A 5A pop dx
0000001B 59 pop cx
0000001C 5B pop bx
0000001D C3 ret
0000001E 48 dec ax
0000001F 656C gs insb
00000021 6C insb
00000022 6F outsw
00000023 2400 and al,0x0
00000025 1E push ds
00000026 01 db 0x01

Works perfectly, at least on this simple test example.
Too bad DOSMC is a perl Linux-only tool.

https://github.com/pts/dosmc

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<uajavn$1bneu$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=369&group=comp.os.msdos.programmer#369

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: address@is.invalid (R.Wieser)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library
Date: Fri, 4 Aug 2023 19:02:28 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uajavn$1bneu$1@dont-email.me>
References: <20230731172858.11ce54d9@mateusz><uafp57$m0mf$1@dont-email.me><20230803120734.34e59904@mateusz><uai619$161tu$1@dont-email.me><20230804140324.0ae56909@mateusz><uaj216$1a8bc$1@dont-email.me> <20230804165638.7a6ec341@mateusz>
Injection-Date: Fri, 4 Aug 2023 17:02:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f7686e357115dd89ea9bc52f24df29a2";
logging-data="1433054"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MqC2jxQGVNAuCJyDGTBP0l6XTVY0sSlg2JGNVfZkpeg=="
Cancel-Lock: sha1:rqx3mvjvNRyi8phghYWqIN8Qmuo=
X-RFC2646: Format=Flowed; Original
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
 by: R.Wieser - Fri, 4 Aug 2023 17:02 UTC

Mateusz,

>> Try "-mt" (tiny memory model) instead.
>
> "-ms" is the proper switch for compiling object files for COM
> executables. In fact, the wcc compiler doesn't even understand -mt.

Thats too bad. At least you can't say I didn't try. :-)

> Building a COM itself is well documented and hence easy to achieve.
> The problem here is that I was trying to make Open Watcom build a tiny
> (as in "very small") COM file by avoiding Watcom's libc and startup code,

I read your first message describing that. Don't worry.

> Then the COM file indeed becomes very small, but it also ceases working,
> as the generated code seems to expect to be executed within an environment
> prepared by Watcom's startup routines.

Strange. Being able to specify a DOS COM output, but not actually getting
it. :-\

Regards,
Rudy Wieser

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20230804211803.7d89dbdf@mateusz.lan>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=371&group=comp.os.msdos.programmer#371

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Fri, 4 Aug 2023 21:18:03 +0200
Organization: ...
Lines: 14
Message-ID: <20230804211803.7d89dbdf@mateusz.lan>
References: <20230731172858.11ce54d9@mateusz>
<uafp57$m0mf$1@dont-email.me>
<20230803120734.34e59904@mateusz>
<uai619$161tu$1@dont-email.me>
<20230804140324.0ae56909@mateusz>
<uaj216$1a8bc$1@dont-email.me>
<20230804165638.7a6ec341@mateusz>
<uajavn$1bneu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="653926adf29b0e676122033ba5be0ae9";
logging-data="1468088"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199c9pPuPvtXoTjRajL83gg"
Cancel-Lock: sha1:M8RrpgUMfHZuY8hAcAkIdX6+9ew=
X-Newsreader: Claws Mail 4.0.0 (GTK+ 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Fri, 4 Aug 2023 19:18 UTC

dn. Fri, 4 Aug 2023 19:02:28 +0200, R.Wieser napisał:
> Thats too bad. At least you can't say I didn't try. :-)

And your kind effort is very much appreciated. :)

> Strange. Being able to specify a DOS COM output, but not actually
> getting it. :-\

Indeed. It's COM all right, but only as long as one links to the
Watcom-supplied startup library (or equivalent). If not, then all bets
are off.

Mateusz

Re: [OpenWatcom] building a COM file without pulling in the Watcom standard library

<20231110001940.4a91a71b@mateusz>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=665&group=comp.os.msdos.programmer#665

  copy link   Newsgroups: comp.os.msdos.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mateusz@x.invalid (Mateusz Viste)
Newsgroups: comp.os.msdos.programmer
Subject: Re: [OpenWatcom] building a COM file without pulling in the Watcom
standard library
Date: Fri, 10 Nov 2023 00:19:40 +0100
Organization: ...
Lines: 105
Message-ID: <20231110001940.4a91a71b@mateusz>
References: <20230731172858.11ce54d9@mateusz>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="c14a2f72e63258597b70312664dca330";
logging-data="2529431"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mMtrA/AYiFNqcNK0lzzwW"
Cancel-Lock: sha1:qwah8vcGI0CsGLqu5E/xBuxyO0U=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-suse-linux-gnu)
 by: Mateusz Viste - Thu, 9 Nov 2023 23:19 UTC

dn. Mon, 31 Jul 2023 17:28:58 +0200, Mateusz Viste napisał:
> It appears that the COM file is not being originated at offset 0x100,
> despite the "FORMAT DOS COM" wlink directive. It's also not
> 0-originated, so I am not sure how the offsets are calculated exactly.
> Once I fix them with a hex editor, the executable works.
>
> What am I missing here?

Hello all,

I talked with Bernd Böckmann today and I was surprised to learn that
he tackled this very same problem recently. He was, however, far more
successful than me and kindly shared the piece of information that I
have missed all along.

Bernd said:
"Because in tiny memory model the code is in the same segment as the
data, the linker must be told to merge these segments to a single one
while linking, otherwise the addresses are messed up. This is done by
the GROUP directive in startup.asm, which includes _TEXT (as opposed to
the .EXE version)."

The need of a custom startup code was already hinted in this thread by
Alexei A. Frounze, and I did attempt to create such startup back then,
but the necessity of grouping segments was lost on me.

Bernd provided me with a working example of his startup code. With this
new bit of information I was able to adapt my proof of concept project
- and this time, it works! The resulting executable size is 45 bytes.
I am pasting here below all the files for posterity.

Mateusz

--- HELLO.LNK ---------------------------------------------

name hello
system dos com
option map
option nodefaultlibs
file startup
file hello

--- HELLO.C -----------------------------------------------

void main(void) {
char *hello = "Hello$";
_asm {
mov ah, 9
mov dx, hello
int 0x21
}
}

--- STARTUP.ASM -------------------------------------------

..8086

dgroup group _TEXT,_DATA,CONST,CONST2,_BSS,

extrn "C",main : near

; public _cstart_, _small_code_, __STK
public _cstart_, _small_code_

_TEXT segment word public 'CODE'
org 100h

_small_code_ label near

_cstart_:
call main
mov ah, 4ch
int 21h

; Stack overflow checking routine is absent. Remember to compile your
; programs with the -s option to avoid referencing __STK
;__STK:
; ret

_DATA segment word public 'DATA'
_DATA ends

CONST segment word public 'DATA'
CONST ends

CONST2 segment word public 'DATA'
CONST2 ends

_BSS segment word public 'BSS'
_BSS ends

_TEXT ends

end _cstart_

--- BUILD.BAT ---------------------------------------------

wasm startup.asm
wcc -os -zl -ms -s -bt=dos hello.c
wlink @hello.lnk

-----------------------------------------------------------

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor