[comp.unix.xenix] Xenix runtime support for GCC

Ronald.Khoo@robobar.Co.Uk (05/03/90)

In article <1990May1.225803.17093@metro.ucc.su.OZ.AU> glenn@extro.ucc.su.oz.au (Glenn Geers) writes:

> 	I'm trying to port gcc to a 386 box with no DS and I'd like to have a look
> at dissasembled versions of crt[1n].o so I can figure out the order of things
> on the runtime stack at startup. So if anyone has disassembled the starup files

Steve's been on at me to wrap and post this for a while,  (yes, I do the
Christmas wrapping around here) so here it is.

[ abstracted from README ]

Here is the basic run-time support for people who want to run Xenix GCC
without the Microsoft Library.  If you don't know what all this means,
you probably don't want this file right now, but please save it anyway for
further use if you use Xenix GCC :-)

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	README
#	Scrt0.s
#	Sseg.uu
#	altlib.sh
#	echo.c
#	exit.c
#	ftol.s
#	hack.S
#	makesseg.c
#	start.c
# This archive created: Thu May  3 13:40:37 1990
export PATH; PATH=/bin:$PATH
echo shar: extracting "'README'" '(2401 characters)'
if test -f 'README'
then
	echo shar: will not over-write existing file "'README'"
else
sed 's/^X//' << \SHAR_EOF > 'README'
X
XHere is the basic run-time support for people who want to run Xenix GCC
Xwithout the Microsoft Library.  If you don't know what all this means,
Xyou probably don't want this file right now, but please save it anyway for
Xfurther use if you use Xenix GCC :-)
X
Xmakesseg.c	/ Program to generate minimal segment ordering object file.
XSseg.uu		/ UUencoded output from makesseg
XScrt0.s		/ C runtime start-off.
Xstart.c		/ Continued from Scrt0.s
Xexit.c		/ Dummy for use when no stdio library is in sight.
Xecho.c		/ Demonstration program.  Doesn't implement -n or \ escapes.
Xhack.S		/ Needed to complete the link of the above.  Mainly syscalls.
X
XThese were mostly written by Steve B. except for the system calls which
Xwere abstracted from an earlier comp.unix.xenix posting.  I wrote this
Xbit of prose and threw the kit together.
X
XTo run demonstration module:
X	1) EITHER
X		$ HERE=`pwd`
X		$ cp makesseg.c <your Xenix-patched GAS directory>
X		$ cd <that GAS directory>
X		$ gcc makesseg.c xenixomf.o
X		$ ./a.out
X		$ mv Sseg.o $HERE
X		$ cd $HERE
X	   OR
X		$ uudecode < Sseg.uu
X
X	2)
X		$ gcc -nostdlib Sseg.o Scrt0.s start.c echo.c hack.S exit.c
X
X./a.out should now be an executable image which contains no Microsoft library
Xcruft at all.
X
XA couple of extra files:
X
Xftol.s		/ called by CC compiled gnulib, hopefully Microsoft compatible
X		/ but should be faster.
Xaltlib.sh	/ How to generate gnulib without CC at all, just using GCC
X
XYou know how anything that's free comes with no warranty?  Well, these come
Xwith even less.  This distribution is intended for Dedicated Hackers Only.
X
XSseg.o Scrt0.o could be moved to /usr/local/lib/gcc-{Sseg.o,Scrt0.o} for
Xpermanent use (Then DO NOT metion -nostdlib on the gcc control card)
Xand start.o should be in your /usr/local/lib/gcc-Slibc.a along with the
Xrest of your libc.
X
XVarious bits of libc can be found in the comp.sources.unix archive and the
XBSD 4.3-tahoe free'd software tape.  I have also successfully run the
Xxercise test of Earl Chew <cechew@bruce.OZ> 's stdio library which was
Xposted to comp.os.minix (though I think I had to reverse the definitions
Xof __STDIO_VA_LIST__ and __STDIO_VA__ and #undef _SIZE_T to make it work).
X
XAnother possible stdio candidate is the one posted recently to alt.sources
Xby Steve Summit <scs@adam.mit.edu>.
X
XI've also thrown together a ctype package, If anyone wants it, mail me
Xand I'll post it if I get fed up of mailing it out.
SHAR_EOF
if test 2401 -ne "`wc -c < 'README'`"
then
	echo shar: error transmitting "'README'" '(should have been 2401 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'Scrt0.s'" '(617 characters)'
if test -f 'Scrt0.s'
then
	echo shar: will not over-write existing file "'Scrt0.s'"
else
sed 's/^X//' << \SHAR_EOF > 'Scrt0.s'
X/
X/ @(#)$Header: /pdsrc/Local/RCS/Scrt0.s,v 1.1 90/04/27 19:08:41 root Exp $
X/ (Optional) Part of GCC Xenix 386 port by Steve.Bleazard@Robobar.Co.Uk
X/ Replacement minimal C Runtime StartOff -- link IMMEDIATELY after Sseg.o
X/
X	.file	"Scrt0.s"
X.data
X.globl _errno
X_errno:
X	.long	0
X.text
X	.align 0		/ Ultra Paranoia.
X.globl first
Xfirst:
X	jmp start0		/ Paranoia, some OS's might want to see jmp.
X
X	.align 2		/ End Paranoia.
X.globl start0
Xstart0:
X	xor %ebp,%ebp		/ Debugger's traceback terminator.
X	call __start		/ Main startup.
X	push %eax		/ _exit(_start()) by default.
X	call __exit
X.1:	jmp .1			/ Last dose of Paranoia.
SHAR_EOF
if test 617 -ne "`wc -c < 'Scrt0.s'`"
then
	echo shar: error transmitting "'Scrt0.s'" '(should have been 617 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'Sseg.uu'" '(595 characters)'
if test -f 'Sseg.uu'
then
	echo shar: will not over-write existing file "'Sseg.uu'"
else
sed 's/^X//' << \SHAR_EOF > 'Sseg.uu'
X$Header: /pdsrc/Local/RCS/Sseg.uu,v 1.1 90/05/01 18:53:24 root Exp $
XMicrosoft compatible(ish) Sseg.o created by makesseg.c
Xbegin 640 Sseg.o
XM@ H "%-S96<N87-M;99R   &1$=23U50!DE'4D]54 ="14=$051!!T5.1$1!
XM5$$'14Y$0T]$10=#7T5415A4 T)34P1$051!!$-/1$4$145.1 1.54Q,!%]"
XM4U,%141!5$$%4U1!0TL%7T1!5$$%0T].4U0%7U1%6%0&14Y$0E-3"9D) *D 
XM    $@H F9D) *D     !P8 J)D) &D     # 0 Y9D) *D     $ D G)D)
XM *D     $1$ DYD) *D     #@4 HID) *D     #0@ H)D) *D     "Q, 
XMEYD) '4     #P\ RYH0  +_ _\$_P7_!O\'_PC_"3&:!@ #_P'_ ER1#P  
XM @9?971E>'0      ,^1#0  " 1?96YD      # D0\   8&7V5D871A    
X(  #VBP(  ', 
X 
Xend
SHAR_EOF
if test 595 -ne "`wc -c < 'Sseg.uu'`"
then
	echo shar: error transmitting "'Sseg.uu'" '(should have been 595 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'altlib.sh'" '(2065 characters)'
if test -f 'altlib.sh'
then
	echo shar: will not over-write existing file "'altlib.sh'"
else
sed 's/^X//' << \SHAR_EOF > 'altlib.sh'
X
X#if 0
X# $Header: /pdsrc/Local/RCS/altlib.sh,v 1.1 90/05/01 19:27:02 root Exp $
X#
X# $Log:	altlib.sh,v $
X# Revision 1.1  90/05/01  19:27:02  root
X# Initial revision
X# 
X#
X# Script and source code for SCO Xenix gnulib compiled with GCC.
X#
X# SCO Xenix 386 gnulib only has three self-recursive functions and these
X# can be replaced by assembly language versions whose source code is in
X# this file.  Executing this file with /bin/sh (NOT csh) in the GCC
X# source directory will result in the production of an alternative gnulib
X# called altgnulib which is entirely compiled with GCC.
X#
X
XAR=ar
XGCC=gcc
XCCLIBFLAGS=-O
XINCLUDES="-I. -Iconfig"
X
XLIBFUNCS="_eprintf _builtin_new _builtin_New _builtin_del 
X	_umulsi3 _mulsi3 _umodsi3 _modsi3 
X	_lshrsi3 _lshlsi3 _ashrsi3 _ashlsi3 
X	_divdf3 _muldf3 _negdf2 _adddf3 _subdf3 _cmpdf2 
X	_fixunsdfsi _floatsidf _truncdfsf2 _extendsfdf2 
X	_addsf3 _negsf2 _subsf3 _cmpsf2 _mulsf3 _divsf3"
X
XALIBFUNCS="_udivsi3 _divsi3 _fixdfsi"
X
Xrm -f altgnulib
X
Xfor name in $LIBFUNCS
Xdo 
X	  echo Compiling $name
X	  rm -f $name.c
X	  cp gnulib.c $name.c
X	  $GCC $CCLIBFLAGS $INCLUDES -c -DL$name $name.c 
X	  $AR qc altgnulib $name.o
X	  rm -f $name.[co]
Xdone
X
Xfor name in $ALIBFUNCS
Xdo 
X	  echo Assembling $name
X	  rm -f $name.S
X	  cp $0 $name.S
X	  $GCC $CCLIBFLAGS $INCLUDES -c -DL$name $name.S
X	  $AR qc altgnulib $name.o
X	  rm -f $name.[So]
Xdone
X
Xranlib altgnulib
X
Xexit 0
X
X#endif
X
X#ifdef L_udivsi3
X	.file	"__udivsi3.s"
X.text
X	.align 2
X.globl ___udivsi3
X___udivsi3:
X	pushl %ebp
X	movl %esp,%ebp
X	movl 8(%ebp),%eax
X	xorl %edx,%edx
X	divl 12(%ebp)
X	leave
X	ret
X#endif
X
X#ifdef L_divsi3
X	.file	"__divsi3.s"
X.text
X	.align 2
X.globl ___divsi3
X___divsi3:
X	pushl %ebp
X	movl %esp,%ebp
X	movl 8(%ebp),%eax
X	cdq
X	idivl 12(%ebp)
X	leave
X	ret
X#endif
X
X#ifdef L_fixdfsi
X	.file	"__fixdfsi.s"
X.text
X	.align 2
X.globl ___fixdfsi
X___fixdfsi:
X	pushl %ebp
X	movl %esp,%ebp
X	subl	$12,%esp
X	fstcw	-4(%ebp)  
X	movw	-4(%ebp),%ax
X	orw	$0x0c00,%ax  
X	movw	%ax,-2(%ebp) 
X	fldcw	-2(%ebp)     
X	fldl	8(%ebp)
X	fistpl	-12(%ebp)    
X	fldcw	-4(%ebp)     
X	movl	-12(%ebp),%eax
X	leave
X	ret
X#endif
SHAR_EOF
if test 2065 -ne "`wc -c < 'altlib.sh'`"
then
	echo shar: error transmitting "'altlib.sh'" '(should have been 2065 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'echo.c'" '(365 characters)'
if test -f 'echo.c'
then
	echo shar: will not over-write existing file "'echo.c'"
else
sed 's/^X//' << \SHAR_EOF > 'echo.c'
X/*
X * Minimal echo program that is VERY inefficient but doesn't use stdio
X */
X
Xstrlen(register char *s)
X{
X	register rval = 0;
X	while (s && *s++) rval++;
X	return rval;
X}
X
Xmain(int argc, char **argv)
X{
X	int gotarg = argc > 1;
X	while (--argc) {
X		char *arg = *++argv;
X		int l = strlen(arg);
X		write(1, arg, l);
X		write(1, " ", 1);
X	}
X	if (gotarg) write(1, "\n", 1);
X}
SHAR_EOF
if test 365 -ne "`wc -c < 'echo.c'`"
then
	echo shar: error transmitting "'echo.c'" '(should have been 365 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'exit.c'" '(137 characters)'
if test -f 'exit.c'
then
	echo shar: will not over-write existing file "'exit.c'"
else
sed 's/^X//' << \SHAR_EOF > 'exit.c'
X/* $Header: /pdsrc/Local/RCS/exit.c,v 1.1 90/05/01 18:51:46 root Exp $ */
X/* dummy(ish) exit */
X
Xexit(code)
Xint code;
X{
X	_exit(code);
X}
X
SHAR_EOF
if test 137 -ne "`wc -c < 'exit.c'`"
then
	echo shar: error transmitting "'exit.c'" '(should have been 137 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'ftol.s'" '(422 characters)'
if test -f 'ftol.s'
then
	echo shar: will not over-write existing file "'ftol.s'"
else
sed 's/^X//' << \SHAR_EOF > 'ftol.s'
X/
X/ @(#) $Header: /pdsrc/Local/RCS/ftol.s,v 1.1 90/04/27 18:53:56 root Exp $
X/ (Optional) Part of Xenix 386 GCC port by Steve.Bleazard@Robobar.Co.Uk
X/
X
X	.file	"ftol.s"
X.text
X	.align 2
X.globl __ftol
X__ftol:
X	pushl %ebp
X	movl %esp,%ebp
X	subl	$12,%esp
X	fstcw	-4(%ebp)  
X	movw	-4(%ebp),%ax
X	orw	$0x0c00,%ax  
X	movw	%ax,-2(%ebp) 
X	fldcw	-2(%ebp)     
X	fistpl	-12(%ebp)    
X	fldcw	-4(%ebp)     
X	movl	-12(%ebp),%eax
X	leave
X	ret
SHAR_EOF
if test 422 -ne "`wc -c < 'ftol.s'`"
then
	echo shar: error transmitting "'ftol.s'" '(should have been 422 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'hack.S'" '(948 characters)'
if test -f 'hack.S'
then
	echo shar: will not over-write existing file "'hack.S'"
else
sed 's/^X//' << \SHAR_EOF > 'hack.S'
X/ minimal 2 syscalls for demonstration echo program
X/ Just write and _exit defined here.
X/ Abstracted from syscall library by:
X/ From: pgd@compuram.bbt.se
X/ Message-Id: <9004162210.AA14300@compuram.bbt.se>
X/ which was reposted to comp.unix.xenix by:
X/ From: dws@uafsun4.uark.edu (David W. Summers)
X/ Message-ID: <4088@uafhp.uark.edu>
X
X	.set	exit,1
X	.set	write,4
X
X#define	sys(fun)	movl	$fun,%eax;.byte	0x9a,0,0,0,0,7,0
X
X#define	DEFSYS(fun,lbl)			\
X	.globl	lbl		;	\
Xlbl:	sys(fun)		;	\
X	jb	1f		;	\
X	ret			;	\
X1:	movl	%eax,_errno	;	\
X	movl	$-1,%eax	;	\
X	ret				\
X
X	.text
XDEFSYS(write,_write)	
X
X	.globl	__exit
X__exit:
X	sys(exit)
X	movl	%eax,_errno
X	movl	$-1,%eax
X	ret
X
X/ Gross hack.  This program _doesn't_ use flotaing point printf, but there's
X/ no easy way we can tell when its needed, so the __fltused EXTDEF is
X/ generated in the normal case for safety.  SO we define it here to keep the
X/ linker happy.
X	.data
X	.globl __fltused
X__fltused:
X	.byte 0
SHAR_EOF
if test 948 -ne "`wc -c < 'hack.S'`"
then
	echo shar: error transmitting "'hack.S'" '(should have been 948 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'makesseg.c'" '(2546 characters)'
if test -f 'makesseg.c'
then
	echo shar: will not over-write existing file "'makesseg.c'"
else
sed 's/^X//' << \SHAR_EOF > 'makesseg.c'
X#include "xenixomf.h"
X#include <stdio.h>
X#include <fcntl.h>
X
X#define I386		1
X
X#define L_DGROUP	2
X#define L_IGROUP	3
X#define L_BEGDATA	4
X#define L_ENDDATA	5
X#define L_ENDCODE	6
X#define L_C_ETEXT	7
X#define L_BSS		8
X#define L_DATA		9
X#define L_CODE		10
X#define L_EEND		11
X#define L_NULL		12
X#define L_UBSS		13
X#define L_EDATA		14
X#define L_STACK		15
X#define L_UDATA		16
X#define L_CONST		17
X#define L_UTEXT		18
X#define L_ENDBSS	19
X
Xextern int outfile;
Xchar *lnames[] = {
X	"",
X	"",
X	"DGROUP",
X	"IGROUP",
X	"BEGDATA",
X	"ENDDATA",
X	"ENDCODE",
X	"C_ETEXT",
X	"BSS",
X	"DATA",
X	"CODE",
X	"EEND",
X	"NULL",
X	"_BSS",
X	"EDATA",
X	"STACK",
X	"_DATA",
X	"CONST",
X	"_TEXT",
X	"ENDBSS"
X};
X
X#define NLNAMES		((sizeof(lnames) / sizeof(char *)) - 1)
X
Xstruct segtable {
X	unsigned char attrib;
X	long length;
X	unsigned nameindex;
X	unsigned classindex;
X};
X
X/* SEGDEF's */
X
Xstatic struct segtable segt[] = {
X	{0, 0, 0, 0},
X	{SD_DWORD|SD_PUBLIC|SD_PGRES, 0, L_UTEXT, L_CODE},
X	{SD_DWORD|SD_PUBLIC|SD_PGRES, 0, L_C_ETEXT, L_ENDCODE},
X	{SD_PARA|SD_PUBLIC|SD_PGRES,  0, L_NULL, L_BEGDATA},
X	{SD_DWORD|SD_PUBLIC|SD_PGRES, 0, L_UDATA, L_DATA},
X	{SD_DWORD|SD_PUBLIC|SD_PGRES, 0, L_CONST, L_CONST},
X	{SD_DWORD|SD_PUBLIC|SD_PGRES, 0, L_EDATA, L_ENDDATA},
X	{SD_DWORD|SD_PUBLIC|SD_PGRES, 0, L_UBSS, L_BSS},
X	{SD_DWORD|SD_PUBLIC|SD_PGRES, 0, L_EEND, L_ENDBSS},
X	{SD_PARA|SD_STACK|SD_PGRES,   0, L_STACK, L_STACK},
X};
X
X#define SDEF_SIZE	((sizeof(segt) / sizeof(struct segtable)) - 1)
X
Xunsigned int dgroup_tab[] = {3, 4, 5, 6, 7, 8, 9};
X#define DGRPTABSIZ (sizeof(dgroup_tab) / sizeof(int))
Xunsigned int igroup_tab[] = {1, 2};
X#define IGRPTABSIZ (sizeof(igroup_tab) / sizeof(int))
X
Xmain()
X{
X	int i;
X
X	if ((outfile = creat("Sseg.o", 0644)) < 0)
X	{
X		fprintf(stderr, "cannot open Sseg.o\n");
X		exit(-1);
X	}
X	omf_theadr("Sseg.asm");		/* Lies, Lies */
X
X	omf_start_lnames();
X	for (i = 1; i <= NLNAMES; i++)
X		omf_lnames(lnames[i]);
X	omf_end_lnames();
X
X	for (i = 1; i <= SDEF_SIZE; i++)
X		omf_segdef(I386, segt[i].attrib, 0, 0L, segt[i].length,
X			   segt[i].nameindex, segt[i].classindex);
X
X	omf_start_grpdef(L_DGROUP);
X	for (i = 0; i < DGRPTABSIZ; i++)
X		omf_grpdef(dgroup_tab[i]);
X	omf_end_grpdef();
X
X	omf_start_grpdef(L_IGROUP);
X	for (i = 0; i < IGRPTABSIZ; i++)
X		omf_grpdef(igroup_tab[i]);
X	omf_end_grpdef();
X
X	omf_start_pubdef(I386, 0, 2, 0);
X	omf_pubdef(I386, "_etext", 0, 0);
X	omf_end_pubdef();
X	omf_start_pubdef(I386, 0, 8, 0);
X	omf_pubdef(I386, "_end", 0, 0);
X	omf_end_pubdef();
X	omf_start_pubdef(I386, 0, 6, 0);
X	omf_pubdef(I386, "_edata", 0, 0);
X	omf_end_pubdef();
X
X	omf_modend(I386);
X}
SHAR_EOF
if test 2546 -ne "`wc -c < 'makesseg.c'`"
then
	echo shar: error transmitting "'makesseg.c'" '(should have been 2546 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'start.c'" '(344 characters)'
if test -f 'start.c'
then
	echo shar: will not over-write existing file "'start.c'"
else
sed 's/^X//' << \SHAR_EOF > 'start.c'
X/* $Header: /pdsrc/Local/RCS/start.c,v 1.1 90/05/01 18:51:35 root Exp $ */
X/* Startup file for gcc _start is called from start0 in Scrt0.s */
X
Xchar ** environ;
X_start(argc, arga)
Xint argc;
Xint arga;
X{
X	char **argv = (char **)&arga;	/* OS and Compiler dependent!!!! */
X	char **envp = environ = argv + argc + 1;
X
X	exit(main(argc, argv, envp));
X}
SHAR_EOF
if test 344 -ne "`wc -c < 'start.c'`"
then
	echo shar: error transmitting "'start.c'" '(should have been 344 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0

-- 
Eunet: Ronald.Khoo@robobar.Co.Uk   Phone: +44 1 991 1142    Fax: +44 1 998 8343
Paper: Robobar Ltd. 22 Wadsworth Road, Perivale, Middx., UB6 7JD ENGLAND.