[comp.os.minix] Turbo C - asm modules

dono@killer.DALLAS.TX.US (Don OConnell) (02/14/89)

This is a repost of the assembler modules that were originally posted by:
		evas@euraiv1.UUCP (Eelco van Asperen)  
They work with TurboC 1.5 , and are in Masm syntax but should work with
the A86 assembler; they will probably need a little tweaking to work with
another C compiler.

I have used them in building 1.2 1.3 1.3[a-d] 1.4[a- ] and still use them.

------------------------------Cut Here---------------------------------
#! /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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  catchsig.asm crtso.asm getutil.asm head.asm sendrec.asm
#   setjmp.asm prologue.h
# Wrapped by dono@killer on Mon Feb 13 21:20:15 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f catchsig.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"catchsig.asm\"
else
echo shar: Extracting \"catchsig.asm\" \(1037 characters\)
sed "s/^X//" >catchsig.asm <<'END_OF_catchsig.asm'
Xtitle catchsig  -  C86 version; now TurboC version [EVAS]
Xpage,132
X
Xinclude	prologue.h
X
X_DATA	segment	para public 'DATA'
X
X	extrn  _vectab:word, _M:word
X
X	dummy	 DW	 0
X
X_DATA	ends
X
X
X_TEXT	segment	byte public 'CODE'
X
X	assume	CS:_TEXT,DS:DGROUP
X
X	public _begsig
X
X
XMTYPE = 2			; M+mtype =  &M.m_type
X
X_begsig	proc near
X
X	push ax			; after interrupt, save all regs
X	push bx
X	push cx
X	push dx
X	push si
X	push di
X	push bp
X	push ds
X	push es
X
X	mov bp,sp
X	mov bx,18[bp]		; bx = signal number
X	dec bx			; vectab[0] is for sig 1
X	add bx,bx		; pointers are two bytes on 8088
X	mov bx,_vectab[bx]	; bx = address of routine to call
X	push _M+mtype		; push status of last system call
X	push ax			; func called with signal number as arg
X	call bx
Xback:
X	pop ax			; get signal number off stack
X	pop _M+mtype		; restore status of previous system call
X	pop es			; signal handling finished
X	pop ds
X	pop bp
X	pop di
X	pop si
X	pop dx
X	pop cx
X	pop bx
X	pop ax
X	pop dummy		; remove signal number from stack
X
X	iret
X
X_begsig	endp
X
X_TEXT	ends
X
X
X	END	; end of assembly-file
END_OF_catchsig.asm
if test 1037 -ne `wc -c <catchsig.asm`; then
    echo shar: \"catchsig.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f crtso.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"crtso.asm\"
else
echo shar: Extracting \"crtso.asm\" \(2117 characters\)
sed "s/^X//" >crtso.asm <<'END_OF_crtso.asm'
XTitle $MAIN    C-86 run-time start-off for Minix; Now for Turbo C [EVAS]
Xpage,132
X
X
X	PAGE	60,132
X;[]------------------------------------------------------------[]
X;|      start-up module for using Turbo C under MINIX; 		|
X;|	derived from:						|
X;|								|
X;|	C0.ASM -- Start Up Code					|
X;|								|
X;|	Turbo-C Run Time Library	version 1.0		|
X;|								|
X;|	Copyright (c) 1987 by Borland International Inc.	|
X;|	All Rights Reserved.					|
X;[]------------------------------------------------------------[]
X
Xinclude	prologue.h
X
X	ASSUME	CS:_TEXT, DS:DGROUP
X
X;	External References
X
X
XPUBLIC	__end, _brksize, edata, $main, _environ, kamikaze
X
X
XSTACKSIZE EQU 2560	; default stack is 5 Kb (2K words)
X
X_DATA	segment	para public 'DATA'
X
X_brksize	DW	offset dgroup:__end+2  	; dynamic changeable end of bss
X_environ	DW	0			; save environment pointer here
X
X_DATA	ends
X
X
X_DATAEND	segment	para public 'DATA'
X
X; _DATAEND holds nothing. The label just tells us where
X; the initialized data (.data) ends.
X
Xedata	label byte
X
X_DATAEND ENDS
X
X_BSSEND SEGMENT BYTE PUBLIC 'BSS'
X
X; _BSSEND holds nothing. The label in the segment just tells
X; us where the data+bss ends.
X
X__end	label	byte
X
X_BSSEND ENDS
X
X
X@STACK	SEGMENT	BYTE STACK 'STACK'
X	DW	STACKSIZE dup(?)	; add stack segment to bss
X@STACK	ENDS
X
X
X_TEXT	segment	byte public 'CODE'
X	ASSUME	CS:_TEXT,DS:DGROUP
X
XEXTRN   _main:NEAR, _exit:NEAR
X
X; This is the C run-time start-off routine.  It's job is to take the
X; arguments as put on the stack by EXEC, and to parse them and set them up the
X; way main expects them.
X;
X
X$main:
X	mov	ax,DGROUP	; force relocation of data & bss
X	mov	bx,sp		; set stackframe pointer (ds=ss)
X	mov	cx,[bx]		; get argc
X	add	bx,2		; point at next parameter
X	mov	ax,cx
X	inc	ax		; calculate envp
X	shl	ax,1
X	add	ax,bx
X	mov	_environ,ax	; save envp
X	push	ax		; stack envp
X	push	bx		; stack argv
X	push	cx		; stack argc
X
X	call	_main		; call _main(arc,argv,envp)
X
X	add	sp,6
X	push	ax		; stack program-termination status
X	call	_exit		; this will never return
X
X	; DEBUG from here on
X
Xkamikaze: 	int 3
X		ret
X
X_TEXT	ENDS
X
X
X	END	$main	; program entry-point (could be anywhere)
END_OF_crtso.asm
if test 2117 -ne `wc -c <crtso.asm`; then
    echo shar: \"crtso.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f getutil.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"getutil.asm\"
else
echo shar: Extracting \"getutil.asm\" \(1182 characters\)
sed "s/^X//" >getutil.asm <<'END_OF_getutil.asm'
Xtitle GetUtil  -  C86 version; now for Turbo C [EVAS]
Xpage,132
X
Xinclude	prologue.h
X
X	PUBLIC _get_base, _get_size, _get_tot_mem
X
X	EXTRN  __end:byte
X
X
X_TEXT	SEGMENT byte public 'CODE'
X
X	ASSUME	CS:_TEXT,DS:DGROUP
X
X;========================================================================
X;                           utilities                                     
X;========================================================================
X
X_get_base:			; return click at which prog starts
X	mov ax,ds
X	ret
X
X_get_size:			   ; return prog size in bytes [text+data+bss]
X	mov ax,offset dgroup:__end  ; end is label at end of bss
X	ret
X
X; Find out how much memory the machine has, including vectors, kernel MM, etc.
X_get_tot_mem:
X	cli
X	push es
X	push di
X	mov ax,8192		; start search at 128K [8192 clicks]
X	sub di,di
Xy1:	mov es,ax
X	mov es:[di],0A5A4h	; write random bit pattern to memory
X	xor bx,bx
X	mov bx,es:[di]		; read back pattern just written
X	cmp bx,0A5A4h		; compare with expected value
X	jne y2			; if different, no memory present
X	add ax,4096		; advance counter by 64K
X	cmp ax,0A000h		; stop seaching at 640K
X	jne y1
Xy2:	pop di
X	pop es
X	sti
X	ret
X
X_TEXT	ENDS
X
X	END	; end of assembly-file
END_OF_getutil.asm
if test 1182 -ne `wc -c <getutil.asm`; then
    echo shar: \"getutil.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f head.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"head.asm\"
else
echo shar: Extracting \"head.asm\" \(1045 characters\)
sed "s/^X//" >head.asm <<'END_OF_head.asm'
Xtitle Head  -  Start-off for initt, mm and fs (C86-compiler); now for Turbo C [EVAS]
Xpage ,132
X
Xinclude	prologue.h
X
XEXTRN _main:NEAR
XPUBLIC $main, _data_org,	brksize, sp_limit, __end
XEXTRN  _stackpt:word
X
X
X_TEXT	SEGMENT byte public 'CODE'
X
X	assume	cs:_TEXT,ds:DGROUP
X
X$main:	jmp	short L0
X
X	ORG 10h			; kernel uses this area	as stack for inital IRET
XL0: 	mov	sp,dgroup:_stackpt
X	call	_main
XL1:    	jmp L1			; this will never be executed
X	mov	ax,DGROUP	; force	relocation for dos2out (never executed)
X
X_TEXT	ENDS
X
X
X_DATA	SEGMENT
X				; fs needs to know where build stuffed table
X_data_org DW 0DADAh		; 0xDADA is magic number for build
X	 DW 7 dup(0)		; first 8 words of MM, FS, INIT are for stack
Xbrksize	 DW	offset dgroup:__end  ; first free memory
Xsp_limit DW	0
X
X_DATA	ENDS
X
X_BSSEND SEGMENT
X
X; _BSSEND holds nothing. The label in the segment just tells
X; us where the data+bss ends.
X
X__end	label	byte
X
X_BSSEND ENDS
X
X
X@STACK	SEGMENT	BYTE STACK 'STACK'
X@STACK	ENDS				; Add stack to satisfy DOS-linker
X
X	END	$main			; end of assembly & entry-point
X
END_OF_head.asm
if test 1045 -ne `wc -c <head.asm`; then
    echo shar: \"head.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f sendrec.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"sendrec.asm\"
else
echo shar: Extracting \"sendrec.asm\" \(1022 characters\)
sed "s/^X//" >sendrec.asm <<'END_OF_sendrec.asm'
Xtitle Send/Receive  -  C86 version; now for Turbo C [EVAS]
Xpage,132
X
Xinclude prologue.h
X
X	PUBLIC _send, _receive, _send_rec, _sendrec
X
X
X; The following definitions are from  ../h/com.h
X
X	__SEND	= 1
X	__RECEIVE= 2
X	__BOTH	= 3
X	__SYSVEC	= 32
X
X
X_TEXT	SEGMENT byte public 'CODE'
X
X	ASSUME	CS:_TEXT,DS:DGROUP
X
X;========================================================================
X;                           send and receive                              
X;========================================================================
X; send(), receive(), send_rec() all save bp, but destroy ax, bx, and cx.
X
X_send:	mov cx,__SEND		; send(dest, ptr)
X	jmp L0
X
X_receive:
X	mov cx,__RECEIVE		; receive(src, ptr)
X	jmp L0
X
X_sendrec:
X_send_rec:
X	mov cx,__BOTH		; send_rec(srcdest, ptr)
X	jmp L0
X
X  L0:	push bp			; save bp
X	mov bp,sp		; can't index off sp
X	mov ax,4[bp]		; ax = dest-src
X	mov bx,6[bp]		; bx = message pointer
X	int __SYSVEC		; trap to the kernel
X	pop bp			; restore bp
X	ret			; return
X
X_TEXT	ENDS
X
X	END	; end of assembly-file
END_OF_sendrec.asm
if test 1022 -ne `wc -c <sendrec.asm`; then
    echo shar: \"sendrec.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f setjmp.asm -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"setjmp.asm\"
else
echo shar: Extracting \"setjmp.asm\" \(916 characters\)
sed "s/^X//" >setjmp.asm <<'END_OF_setjmp.asm'
Xtitle setjmp/longjmp  -  C86 version
Xpage,132
X
Xinclude ..\lib\prologue.h
X
X
X	PUBLIC _setjmp, _longjmp
X	EXTRN _exit:near
X
X
X; 	struct jmpbuf {
X;		int bp;
X;	 	int sp;
X;	 	int ret-addr;
X; 	}
X
XJMPERR	EQU	-99		; call _exit(JMPERR) when jmp-error
X
X_TEXT	SEGMENT byte public 'CODE'
X
X	ASSUME	CS:_TEXT,DS:DGROUP
X
X_setjmp:
X	mov	bx,sp
X	mov	ax,[bx]		; ret-addr.
X	mov	bx,2[bx]	; addr of jmp-struct
X	mov	[bx],bp
X	mov	2[bx],sp
X	mov	4[bx],ax
X	xor	ax,ax
X	ret
X
X_longjmp:
X	push	bp
X	mov	bp,sp		; set new frame pointer to sp
X	mov	bx,4[bp]	; get address of jmp-structure
X	mov	ax,6[bp]	; get ret-code
X	or	ax,ax
X	jne	L1
X	inc	ax		; return code may not be zero
X    L1:	mov	sp,[bx+2]
X	mov	bp,[bx]
X	or	bp,bp		; test if last frame-pointer (error)
X	jne	L2		; else execute the longjmp
X	pop	bp
X	mov	ax,JMPERR
X	push	ax
X	call	_exit		; should never return
X	hlt
X    L2:	mov	bx,[bx+4]
X	pop	cx		; dump the bp we pushed upon entry
X	jmp	bx
X
X_TEXT	ENDS
X
X	END
END_OF_setjmp.asm
if test 916 -ne `wc -c <setjmp.asm`; then
    echo shar: \"setjmp.asm\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f prologue.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"prologue.h\"
else
echo shar: Extracting \"prologue.h\" \(415 characters\)
sed "s/^X//" >prologue.h <<'END_OF_prologue.h'
X
X;	Segment and Group declarations
X
X_TEXT	SEGMENT BYTE PUBLIC 'CODE'
X_TEXT	ENDS
X_DATABEG	SEGMENT PARA PUBLIC 'DATA'
X_DATABEG	ENDS
X_DATA	SEGMENT PARA PUBLIC 'DATA'
X_DATA	ENDS
X_DATAEND SEGMENT PARA PUBLIC 'DATA'
X_DATAEND ENDS
X_BSS	SEGMENT WORD PUBLIC 'BSS'
X_BSS	ENDS
X_BSSEND SEGMENT BYTE PUBLIC 'BSS'
X_BSSEND ENDS
X_STACK	SEGMENT STACK 'STACK'
X_STACK	ENDS
X
XDGROUP	GROUP	_DATABEG,_DATA, _DATAEND, _BSS, _BSSEND, _STACK
X
END_OF_prologue.h
if test 415 -ne `wc -c <prologue.h`; then
    echo shar: \"prologue.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0


Don O'Connell					killer!dono