All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Given <dg@cowlark.com>
To: ELKS Mailing List <linux-8086@vger.kernel.org>
Subject: Re: Kernel size over 64K: what is needed, how to implement?
Date: Sun, 19 Feb 2012 21:36:01 +0000	[thread overview]
Message-ID: <4F416B41.7000804@cowlark.com> (raw)
In-Reply-To: <4F3ED9FB.4010408@cowlark.com>

[-- Attachment #1: Type: text/plain, Size: 3250 bytes --]

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)


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 254 bytes --]

  reply	other threads:[~2012-02-19 21:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-17 18:20 Kernel size over 64K: what is needed, how to implement? Jody Bruchon
2012-02-17 22:51 ` David Given
2012-02-19 21:36   ` David Given [this message]
2012-02-19 23:01     ` Kirn Gill
2012-02-20  0:51       ` David Given
2012-02-20 13:13         ` Alan Carvalho de Assis
2012-02-21 18:24           ` Juan Perez-Sanchez
2012-02-22  0:31             ` David Given
     [not found]           ` <FC79A7424F669341A72EFA787A3C767541F8ECD7@exchdb1-vm-srv.infopulse.local>
2012-02-22 14:53             ` Andrey Romanenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F416B41.7000804@cowlark.com \
    --to=dg@cowlark.com \
    --cc=linux-8086@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.