;
;			c r e s p r _ x
;
;	Startup code for C68 module that is to be run as a resident
;	extension rather than as a free-standing program.
;
;	A version of the start-up module that is suitable for programs
;	that are to be started via LRESPR.	This has the following
;	restrictions compared to the full startup
;	 - No stack is allocated (the one of the calling job is used).
;	 - No attempt is made to parse any command line parameters.
;	   (argc and argv are not even set up)
;	 - No attempt is made to set up default channels (it is assumed
;	   that the STDIO package will NOT be used).
;	 - Dynamic memory allocation is not automatically included.
;
;
;  Amendment History
;  ~~~~~~~~~~~~~~~~~
;	01 Oct 94	DJW   - The startup code has been far more modularised as part
;						of the work to introduce RLL support.  This ha happened
;						at two levels:
;					  - All code that is specific to intialising the C
;						environment has been moved to a seperate module that
;						is called via a vector.  This removes the need to have
;						seperate versions of the startup code for the case
;						when the full C environment is not wanted.
;					  - Certain routines are added to the file via 'include'
;						statements.  This is to cater for the fact that these
;						routines are shared by the various start up modules
;						and the RLM, but we want only one file to maintain.
;
;	12 Mar 94	DJW   - Incorporated fixes provided by Erik Slagter to run
;						correctly when LRESPRed from Basic.
;----------------------------------------------------------------------------

	.text	 

MT.INF	 equ	$00
SMS.SSJB equ	$08
;
;		Enter here 
;
;************************************************************************
;
;	Start of real code area
;
;************************************************************************

	.globl	__progbase

__progbase:

	moveq	#MT.INF,d0		; System and job information
	trap	#1				; ... do it
	trap	#0				; enter Supervisor mode
	lea 	basic_a6(pc),a1 ; Save A6 for BASIC
	move.l	a6,(a1)
	move.l	a0,a6			; save system variable pointer


	bsr 	PROCTYPE		; Now do the processor detection code
	bsr 	CACHEOFF		; Disable caches if present
	move.l	d0,-(sp)		; PUSH cache state

	lea 	__progbase(pc),a1		; Start of job in memory
	move.l	a1,d1					; save it in d1
	add.l	RELLEN(pc),a1			; start of relocation info

#ifdef GST
#include	"relocGST_x"
#else
#include	"relocLD_x"
#endif

	move.l	(sp)+,d0		; POP saved cache state
	bsr 	CACHEON 		; restore cache states

	move.l	a6,__sys_var	; save address of global variables
	move.l	basic_a6(pc),a6 ; restore BASIC a6
	and.w	#$dfff,sr		; remove supervisor bit from status register

;======================================================================
;  Start up user code
;  ~~~~~~~~~~~~~~~~~~
;  Finally it is time to call the user code !
;
;----------------------------------------------------------------------

	jmp 	_main			; ======= Call user program =========

basic_a6:
	dc.l	0
PROGNAME:
	dc.w	6
	dc.b	'CRESPR'

#include   "proctype_x"
#include   "cache_x"
#include   "crtdata_x"
