;
; wspace.s
;
; Handling of DLL workspace and similar things
;
;  1994 Straylight
;

;----- Standard stuff -------------------------------------------------------

		GET	libs:header
		GET	libs:swis

;----- Other external dependencies ------------------------------------------

		IMPORT	|x$stack_overflow|
		IMPORT	malloc

		IMPORT	|__errno|,WEAK		;Vile hack :-(

;----- Main code ------------------------------------------------------------

		AREA	|DLL$$Code|,CODE,READONLY

; --- _dll_giveMemory ---

		EXPORT	|_dll_giveMemory|
|_dll_giveMemory| ROUT

		MOV	ip,sp
		STMFD	sp!,{v1,fp,ip,lr,pc}
		SUB	fp,ip,#4
		CMP	sp,sl
		BLLT	|x$stack_overflow|

		MOV	v1,#0			;Start with magic number at 0
00		SWI	DLL_InstanceVars	;Give DLL some variables
		CMP	v1,#0			;Is this the end yet?
		LDMEQDB	fp,{v1,fp,sp,pc}^	;Yes -- return to caller
		BL	malloc			;Allocate variables as reqd.
		B	%b00			;And give to the DLL

		LTORG

; --- _dll_appspace ---

		EXPORT	|_dll_appspace|
|_dll_appspace|	ROUT

		MOV	ip,lr			;Keep hold of link register
		MOV	a1,sl			;Point to stack limit thingy
		SWI	DLL_AppData		;Tell DLLManager about this
		MOVS	pc,ip			;Return to caller

		LTORG

; --- _dll_clibdata ---

		EXPORT	|_dll_clibdata|
|_dll_clibdata|	ROUT

		MOV	ip,lr			;Keep link register safe
		LDR	a1,=|__errno|		;Find the C Library's space
		SWI	DLL_GiveCLibData	;Pass on the CLib data
		MOVS	pc,ip			;Return to caller

		LTORG

;----- That's all, folks ----------------------------------------------------

		END
