[comp.os.minix] More than 64K text

wheeler@IDA.ORG (David Wheeler) (10/28/89)

From article <816@lzaz.ATT.COM>, by bds@lzaz.ATT.COM (Buce Szablak):
> In article <3539@ast.cs.vu.nl>, ast@cs.vu.nl (Andy Tanenbaum) writes:
>> 3. If you promise to write a lint for MINIX, I promise to use it.
>> Andy Tanenbaum (ast@cs.vu.nl)
>
> It has occurred to me, that a compromise might be to support the Medium
> model - 64K data, >64K text. Thus, you could keep the same fork/exec
                   ^^^^^^^^^^
> semantics, but maybe you could support an ANSI C compiler. I suspect that
> the ACK compiler will choke on function pointers and data pointers being
> of differing size, so I would recommend making all pointers 32 bits.
> Thus, you will even be set up for 386 implementations that have 32 bit
> segments (I also expect 386 processors to be more prevalent in 1991).
>
 
A different method for handling this problem was implemented in QNX (a
PC OS). There, code can be greater than 64K in length, yet using only 16-bit
function pointers, by allowing multiple 64K text code segments to
be used by a program.  The program uses intersegment calls when needed,
and function stubs to deal with intersegment calls are automatically
generated (by the linker, compiler, or some pre/post processing; the
linker is the obvious place to do this).

In QNX the linker creates these multiple-segment programs
and automatically creates the correct stubs for intersegment calls.
 
There are a thousand ways to do this; I think the important point
is to hide the details into the compiler & linker so that code would
(hardly) notice the automatic breaking up of the executable.

Here's an example:

This C code will go into code segment 1:
#include <stdio.h>
int main() { f(); }
int g() { printf("hello"); }


This C code will go into code segment 2:
int f() {  g(); }


The resulting code could look like (in pseudo-assembly):

Code segment 1:
; the following is generated automatically, say by the compiler.
f:  intersegment call to C2call, pass it f.
    return  ; intrasegment, not intersegment, return.
inter_return: intersegment return;
C1call: take parameter as a function address in this code segment and call it
        as a subroutine.
        intersegment return;
; the following is normal stuff.

main: ...
      call f    ;  see the beginning of this segment

g: ....



Code segment 2 pseudo-assembly:
; the following is generated automatically, say by the compiler.
C2call: take parameter as a function address in this code segment and call it
        as a subroutine.
        intersegment return;
g: 
    intersegment call to C1call, pass it g.
; the following is normal stuff.
f:  ....
    call g2
    ret   ; intrasegment, not intersegment, return.


There may be problems with &function depending on how you divide up
the program.  The other solution, of course, is to change the OS to
deal with large model programs.
 
--- David A. Wheeler
    wheeler@ida.org