	.globl	__app		; short, declared in crtinit.c
	.globl	__base		; BASEPAGE *, declared in crtinit.c
	.globl	__heapbase	; void *
	.globl	__stksize	; long, declared by user or in stack.c

; Assumption: basepage is passed in a0 for accessories; for programs
; a0 is always 0.

	.text
	.even
	.globl	__start
__start:
	sub.l	a6,a6		; clear a6 for debuggers
	cmp.w	#0,a0		; test if acc or program
	beq	__startprg	; if a program, go elsewhere
	tst.l	36(a0)		; also test parent basepage pointer
	bne	__startprg	; for acc's, it must be 0
	move.l	a0,__base	; acc basepage is in A0
	move.l	__heapbase,sp	; stack must be set from heap
	add.l	__stksize,sp
	jmp	__acc_main	; function is in crtinit.c

; program startup code: doesn't actually do much, other than push
; the basepage onto the stack and call _start1 in crtinit.c

__startprg:
	move.l	4(sp),a0	; get basepage
	move.l	a0,__base	; save it
	move.l	4(a0),d0	; get _base->p_hitpa
	bclr.l	#0,d0		; round off
	move.l	d0,sp		; set stack (temporarily)
	jmp	__crtinit	; in crtinit.c

; _setstack: changes the stack pointer; called as
;     void setstack( void *newsp )
; called from crtinit.c once the new stack size has been decided upon
;
; WARNING WARNING WARNING: after you do this, local variables may no longer
; be accessible!
; destroys a0 and a7

	.globl	__setstack
__setstack:
	move.l	(sp)+,a0	; save return address
	move.l	(sp)+,sp	; new stack pointer
	subq.l	#4,sp		; fixup for tidy upon return
	jmp	(a0)		; back to caller

;
; interfaces for gprof: for crt0.s, does nothing
; How does profiling work under Sozobon.
;
	.globl 	__monstartup
	.globl	__moncontrol
	.globl 	___mcleanup
__monstartup:
__moncontrol:
___mcleanup:
	rts
