Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!pdn!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.unix.xenix Subject: Re: alloca() for Xenix 386 2.3.2 Message-ID: <2690B6A4.59F@tct.uucp> Date: 3 Jul 90 15:15:48 GMT References: <15558@s.ms.uky.edu> Organization: ComDev/TCT, Sarasota, FL Lines: 112 According to simon@ms.uky.edu (G. Simon Gales): >I'm need an alloc() for Xenix, to compile gas/gcc/etc. Your wish is my sharchive... #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'alloca386.s' <<'END_OF_FILE' X; alloca386.s 1.2 X; GNU-compatible stack allocation function for Xenix/386. X; Written by Chip Salzenberg at ComDev. X; Last modified 90/01/11 X X TITLE $alloca386 X X .386 XDGROUP GROUP CONST, _BSS, _DATA X_DATA SEGMENT DWORD USE32 PUBLIC 'DATA' X_DATA ENDS X_BSS SEGMENT DWORD USE32 PUBLIC 'BSS' X_BSS ENDS XCONST SEGMENT DWORD USE32 PUBLIC 'CONST' XCONST ENDS X_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE' X ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP X X PUBLIC _alloca X_alloca PROC NEAR X X; Get argument. X pop edx ; edx -> return address X pop eax ; eax = amount to allocate X X; Validate allocation amount. X add eax,3 X and eax,not 3 X cmp eax,0 X jg aa_size_ok X mov eax,4 Xaa_size_ok: X X; Allocate stack space. X mov ecx,esp ; ecx -> old stack pointer X sub esp,eax ; perform allocation X mov eax,esp ; eax -> new stack pointer X X; Copy the three saved register variables from old stack top to new stack top. X; They may not be there. So we waste twelve bytes. Big fat hairy deal. X push DWORD PTR 8[ecx] X push DWORD PTR 4[ecx] X push DWORD PTR 0[ecx] X X; Push something so the caller can pop it off. X push eax X X; Return to caller. X jmp edx X X_alloca ENDP X X_TEXT ENDS X END END_OF_FILE if test 1282 -ne `wc -c <'alloca386.s'`; then echo shar: \"'alloca386.s'\" unpacked with wrong size! fi # end of 'alloca386.s' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(215 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# Makefile for alloca386 X XLIB = Sliballoca.a XOBJ = alloca386.o X X$(LIB): $(OBJ) X ar rc $(LIB) $(OBJ) X ranlib $(LIB) X Xclean: X rm -f $(OBJ) Xclobber: clean X rm -f $(LIB) X X.SUFFIXES: .s X.s.o: X masm -Mx -o$@ $*.s END_OF_FILE if test 215 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi echo shar: End of shell archive. exit 0 -- Chip Salzenberg at ComDev/TCT ,