/* --- Copyright University of Sussex 1998. All rights reserved. ----------
 * File:	    C.power/src/amain.s
 * Purpose:	    Entry routine for Pop
 * Author:	    John Gibson, Mar 17 1998
 */

;;; ------------ ENTRY POINT FOR THE POPLOG SYSTEM ------------------------

#_<

#_INCLUDE 'asm.ph'

vars $-Sys$- _init_args, Sys$-Extern$- _invocation_fp;

>_#

ASM_START_FILE



#_IF DEF AIX or DEF DARWIN_PPC


	.text
	.align	0 /*OJO MODIFICADO*/

DEF_C_LAB(Sys$- _entry_point)	
	
.globl _main
_main:

	mfcr	rt0
	stW	rt0, _WOFFS*1(rsp)	;;; save condition reg in caller frame
	mflr	rt0
	stW	rt0, _WOFFS*2(rsp)	;;; save link reg in caller frame
	mr	rt0, rsp

	;;; save AIX local registers (13-31)
	la	rsp, -_WOFFS*19(rsp)	;;; alloc space to save regs
	stW	r13, _WOFFS*0(rsp)
	stW	r14, _WOFFS*1(rsp)
	stW	r15, _WOFFS*2(rsp)
	stW	r16, _WOFFS*3(rsp)
	stW	r17, _WOFFS*4(rsp)
	stW	r18, _WOFFS*5(rsp)
	stW	r19, _WOFFS*6(rsp)
	stW	r20, _WOFFS*7(rsp)
	stW	r21, _WOFFS*8(rsp)
	stW	r22, _WOFFS*9(rsp)
	stW	r23, _WOFFS*10(rsp)
	stW	r24, _WOFFS*11(rsp)
	stW	r25, _WOFFS*12(rsp)
	stW	r26, _WOFFS*13(rsp)
	stW	r27, _WOFFS*14(rsp)
	stW	r28, _WOFFS*15(rsp)
	stW	r29, _WOFFS*16(rsp)
	stW	r30, _WOFFS*17(rsp)
	stW	r31, _WOFFS*18(rsp)

	;;; 2nd arg (R4 = rt7) is the address of arg string vec
	addis	r10,0,hi16(I_LAB(Sys$- _init_args))
	ori	r10,r10,lo16(I_LAB(Sys$- _init_args))
	stW	rt7, 0(rt1)		;;; store in _init_args

	;;; set up _special_var_block in rsvp
	addis	r14,0,hi16(C_LAB(_special_var_block))
	ori	r14,r14,lo16(C_LAB(_special_var_block))

	;;; save fp in _invocation_fp for unwinding after an error signal
	stW	rt0, _svb_INVOC_FP	;;; save original sp

	ldW	rfalse, _svb_FALSE	;;; set rfalse to false
	INIT_POP_REGISTERS		;;; set pop lvar registers to false
	li	R0, 0
	stW	R0, _svb_IN_USER_EXTERN	;;; clear _in_user_extern
	ldW	rusp, _svb_SAVED_USP	;;; temp user stack pointer in rusp
	;;;addis	r15,0,hi16(c.comparacion)	;;; get setpop
	;;;ori	r15,r15,lo16(c.comparacion)
	;;;bl	XC_LAB(comparacion)
	addis	r15,0,hi16(c.setpop)	;;; get setpop
	ori	r15,r15,lo16(c.setpop)
	bl	XC_LAB(setpop)		;;; call setpop

	;;; restore AIX local registers
	ldW	r13, _WOFFS*0(rsp)
	ldW	r14, _WOFFS*1(rsp)
	ldW	r15, _WOFFS*2(rsp)
	ldW	r16, _WOFFS*3(rsp)
	ldW	r17, _WOFFS*4(rsp)
	ldW	r18, _WOFFS*5(rsp)
	ldW	r19, _WOFFS*6(rsp)
	ldW	r20, _WOFFS*7(rsp)
	ldW	r21, _WOFFS*8(rsp)
	ldW	r22, _WOFFS*9(rsp)
	ldW	r23, _WOFFS*10(rsp)
	ldW	r24, _WOFFS*11(rsp)
	ldW	r25, _WOFFS*12(rsp)
	ldW	r26, _WOFFS*13(rsp)
	ldW	r27, _WOFFS*14(rsp)
	ldW	r28, _WOFFS*15(rsp)
	ldW	r29, _WOFFS*16(rsp)
	ldW	r30, _WOFFS*17(rsp)
	ldW	r31, _WOFFS*18(rsp)
	la	rsp, _WOFFS*19(rsp)

	ldW	rt0, _WOFFS*1(rsp)	;;; restore condition reg
	mtcrf	0xff, rt0
	ldW	rt0, _WOFFS*2(rsp)	;;; restore link reg
	mtlr	rt0
	li	rchain, 0		;;; normal exit status (= R3)
	blr				;;; return
		

			

#_ENDIF

ASM_END_FILE
