Re: Kernel size over 64K: what is needed, how to implement?

David Given <[email protected]>
Newsgroups org.kernel.vger.linux-8086
Message-ID <[email protected]>
On 17/02/12 22:51, David Given wrote:
[...]
> Regarding C compilers --- has anyone ever tried Open Watcom? It claims
> to support all these weird 8086 segmentation modes, and there is a Linux
> version. It's also supposed to produce pretty decent code, which may
> well be more compact than bcc's and so save crucial kernel space.  Never
> touched it myself, though.

I just had a play. Apparently Open Watcom produces OMF object files,
which none of myself, binutils-multiarch or file have ever heard of.
Rumour has it that the Open Watcom linker is capable of being scripted
--- I don't know whether this is to a useful extent.

OTOH the code is definitely good. Here's a source file:

int global;

fnord(a, b)
	int a;
	int b;
{
	int i = a + b;
	int j = global - a;
	global += i;
	return j;
}

(K&R C because I wanted to use the same file for Open Watcom and bcc;
Open Watcom supports ANSI. It even supports some C99.)

In fastcall mode, Open Watcom produces:

0000                          @fnord:
0000    01 C2                     add         dx,ax
0002    8B 1E 00 00               mov         bx,word ptr _global
0006    29 C3                     sub         bx,ax
0008    89 D8                     mov         ax,bx
000A    01 16 00 00               add         word ptr _global,dx
000E    C3                        ret

In cdecl mode, it produces:

0000                          _fnord:
0000    55                        push        bp
0001    89 E5                     mov         bp,sp
0003    8B 46 04                  mov         ax,word ptr 0x4[bp]
0006    8B 56 06                  mov         dx,word ptr 0x6[bp]
0009    01 C2                     add         dx,ax
000B    8B 1E 00 00               mov         bx,word ptr _global
000F    29 C3                     sub         bx,ax
0011    89 D8                     mov         ax,bx
0013    01 16 00 00               add         word ptr _global,dx
0017    5D                        pop         bp
0018    C2 04 00                  ret         0x0004

bcc produces (and you may want to brace yourselves):

_fnord:
push	bp
mov	bp,sp
push	di
push	si
dec	sp
dec	sp
mov	ax,4[bp]
add	ax,6[bp]
mov	-6[bp],ax
dec	sp
dec	sp
mov	ax,[_global]
sub	ax,4[bp]
mov	-8[bp],ax
mov	ax,[_global]
add	ax,-6[bp]
mov	[_global],ax
mov	ax,-8[bp]
add	sp,*4
pop	si
pop	di
pop	bp
ret

Note that that last is without optimisation; when I try -O I get an
error message about not being able to find /usr/lib/bcc/rules.start. Is
optimisation supported for the 8086? Also I notice that the bcc code
seems to be returning the value in ax, so I may not have got the calling
conventions to match.

If anyone actually wanted to use this, I suspect the easiest thing to do
would be to compile with Open Watcom, disassemble the object files and
use a script of some kind to convert them to gas syntax. Which would
suck, but is almost certainly easier than adding OMF support to dev86.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ "Never attribute to malice what can be adequately explained by
│ stupidity." --- Nick Diamos (Hanlon's Razor)
signature.asc (application/pgp-signature, 254 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFPQWtEf9E0noFvlzgRAvOmAKDFojEm7wJK4J5L2kfnL0Z29mylsACdH5uc
xJIc+mXQzea+GMdHkb1Y+Gc=
=lNNI
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.