require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_MIPS64_ASM_H)) {
    eval 'sub _MIPS64_ASM_H () {1;}' unless defined(&_MIPS64_ASM_H);
    require 'machine/regdef.ph';
    if(defined(&NEED_OLD_RM7KFIX)) {
	eval 'sub ITLBNOPFIX () { &nop; &nop; &nop; &nop; &nop; &nop; &nop; &nop; &nop; &nop;;}' unless defined(&ITLBNOPFIX);
    } else {
	eval 'sub ITLBNOPFIX () { &nop; &nop; &nop; &nop;}' unless defined(&ITLBNOPFIX);
    }
    eval 'sub _MIPS_ISA_MIPS1 () {1;}' unless defined(&_MIPS_ISA_MIPS1);
    eval 'sub _MIPS_ISA_MIPS2 () {2;}' unless defined(&_MIPS_ISA_MIPS2);
    eval 'sub _MIPS_ISA_MIPS3 () {3;}' unless defined(&_MIPS_ISA_MIPS3);
    eval 'sub _MIPS_ISA_MIPS4 () {4;}' unless defined(&_MIPS_ISA_MIPS4);
    if(!defined( &ABICALLS)  && !defined( &_NO_ABICALLS)) {
	eval 'sub ABICALLS () {. &abicalls;}' unless defined(&ABICALLS);
    }
    if(defined( &ABICALLS)  && !defined( &_KERNEL)) {
    }
    eval 'sub _C_LABEL {
        my($x) = @_;
	    eval q($x);
    }' unless defined(&_C_LABEL);
    if(!defined( &__MIPSEL__)  && !defined( &__MIPSEB__)) {
	die("__MIPSEL__ or __MIPSEB__ must be defined");
    }
    if(defined( &__MIPSEL__)) {
	eval 'sub LWLO () { &lwl;}' unless defined(&LWLO);
	eval 'sub LWHI () { &lwr;}' unless defined(&LWHI);
	eval 'sub SWLO () { &swl;}' unless defined(&SWLO);
	eval 'sub SWHI () { &swr;}' unless defined(&SWHI);
	eval 'sub LDLO () { &ldl;}' unless defined(&LDLO);
	eval 'sub LDHI () { &ldr;}' unless defined(&LDHI);
	eval 'sub SDLO () { &sdl;}' unless defined(&SDLO);
	eval 'sub SDHI () { &sdr;}' unless defined(&SDHI);
    }
    if(defined( &__MIPSEB__)) {
	eval 'sub LWLO () { &lwr;}' unless defined(&LWLO);
	eval 'sub LWHI () { &lwl;}' unless defined(&LWHI);
	eval 'sub SWLO () { &swr;}' unless defined(&SWLO);
	eval 'sub SWHI () { &swl;}' unless defined(&SWHI);
	eval 'sub LDLO () { &ldr;}' unless defined(&LDLO);
	eval 'sub LDHI () { &ldl;}' unless defined(&LDHI);
	eval 'sub SDLO () { &sdr;}' unless defined(&SDLO);
	eval 'sub SDHI () { &sdl;}' unless defined(&SDHI);
    }
    if(defined( &ABICALLS)  && !defined( &_KERNEL)  && !defined( &_STANDALONE)) {
	unless(defined(&_MIPS_SIM)) {
	    eval 'sub _MIPS_SIM () {1;}' unless defined(&_MIPS_SIM);
	    eval 'sub _ABIO32 () {1;}' unless defined(&_ABIO32);
	}
	unless(defined(&_MIPS_ISA)) {
	    eval 'sub _MIPS_ISA () {2;}' unless defined(&_MIPS_ISA);
	    eval 'sub _MIPS_ISA_MIPS2 () {2;}' unless defined(&_MIPS_ISA_MIPS2);
	}
	if(((defined(&_MIPS_SIM) ? &_MIPS_SIM : 0) == (defined(&_ABIO32) ? &_ABIO32 : 0)) || ((defined(&_MIPS_SIM) ? &_MIPS_SIM : 0) == (defined(&_ABI32) ? &_ABI32 : 0))) {
	    eval 'sub NARGSAVE () {4;}' unless defined(&NARGSAVE);
	    eval 'sub SETUP_GP () {. &set  &noreorder; . &cpload  &t9; . &set  &reorder;;}' unless defined(&SETUP_GP);
	    eval 'sub SAVE_GP {
	        my($x) = @_;
    		eval q(. &cprestore $x);
	    }' unless defined(&SAVE_GP);
	    eval 'sub SETUP_GP64 {
	        my($gpoff, $name) = @_;
    		eval q();
	    }' unless defined(&SETUP_GP64);
	    eval 'sub RESTORE_GP64 () {1;}' unless defined(&RESTORE_GP64);
	}
	if(((defined(&_MIPS_SIM) ? &_MIPS_SIM : 0) == (defined(&_ABI64) ? &_ABI64 : 0)) || ((defined(&_MIPS_SIM) ? &_MIPS_SIM : 0) == (defined(&_ABIN32) ? &_ABIN32 : 0))) {
	    eval 'sub NARGSAVE () {0;}' unless defined(&NARGSAVE);
	    eval 'sub SETUP_GP () {1;}' unless defined(&SETUP_GP);
	    eval 'sub SAVE_GP {
	        my($x) = @_;
    		eval q();
	    }' unless defined(&SAVE_GP);
	    eval 'sub SETUP_GP64 {
	        my($gpoff, $name) = @_;
    		eval q(. &cpsetup  &t9, $gpoff, $name);
	    }' unless defined(&SETUP_GP64);
	    eval 'sub RESTORE_GP64 () {. &cpreturn;}' unless defined(&RESTORE_GP64);
	}
	eval 'sub MKFSIZ {
	    my($narg,$locals) = @_;
    	    eval q(((($narg+$locals)* &REGSZ+31)(~31)));
	}' unless defined(&MKFSIZ);
    } else {
	eval 'sub NARGSAVE () {4;}' unless defined(&NARGSAVE);
	eval 'sub SETUP_GP () {1;}' unless defined(&SETUP_GP);
	eval 'sub SAVE_GP {
	    my($x) = @_;
    	    eval q();
	}' unless defined(&SAVE_GP);
	eval 'sub ALIGNSZ () {16;}' unless defined(&ALIGNSZ);
	eval 'sub FRAMESZ {
	    my($sz) = @_;
    	    eval q(((($sz) + ( &ALIGNSZ-1)) & ~( &ALIGNSZ-1)));
	}' unless defined(&FRAMESZ);
    }
    if(((defined(&_MIPS_ISA) ? &_MIPS_ISA : 0) == (defined(&_MIPS_ISA_MIPS1) ? &_MIPS_ISA_MIPS1 : 0) || (defined(&_MIPS_ISA) ? &_MIPS_ISA : 0) == (defined(&_MIPS_ISA_MIPS2) ? &_MIPS_ISA_MIPS2 : 0))) {
	eval 'sub REGSZ () {4;}' unless defined(&REGSZ);
	eval 'sub LOGREGSZ () {2;}' unless defined(&LOGREGSZ);
	eval 'sub REG_S () { &sw;}' unless defined(&REG_S);
	eval 'sub REG_L () { &lw;}' unless defined(&REG_L);
	eval 'sub CF_SZ () {24;}' unless defined(&CF_SZ);
	eval 'sub CF_ARGSZ () {16;}' unless defined(&CF_ARGSZ);
	eval 'sub CF_RA_OFFS () {20;}' unless defined(&CF_RA_OFFS);
    }
    if(((defined(&_MIPS_ISA) ? &_MIPS_ISA : 0) == (defined(&_MIPS_ISA_MIPS3) ? &_MIPS_ISA_MIPS3 : 0) || (defined(&_MIPS_ISA) ? &_MIPS_ISA : 0) == (defined(&_MIPS_ISA_MIPS4) ? &_MIPS_ISA_MIPS4 : 0))) {
	eval 'sub REGSZ () {8;}' unless defined(&REGSZ);
	eval 'sub LOGREGSZ () {3;}' unless defined(&LOGREGSZ);
	eval 'sub REG_S () { &sd;}' unless defined(&REG_S);
	eval 'sub REG_L () { &ld;}' unless defined(&REG_L);
	eval 'sub CF_SZ () {48;}' unless defined(&CF_SZ);
	eval 'sub CF_ARGSZ () {32;}' unless defined(&CF_ARGSZ);
	eval 'sub CF_RA_OFFS () {40;}' unless defined(&CF_RA_OFFS);
    }
    unless(defined(&__LP64__)) {
	eval 'sub PTR_L () { &lw;}' unless defined(&PTR_L);
	eval 'sub PTR_S () { &sw;}' unless defined(&PTR_S);
	eval 'sub PTR_SUB () { &sub;}' unless defined(&PTR_SUB);
	eval 'sub PTR_ADD () { &add;}' unless defined(&PTR_ADD);
	eval 'sub PTR_SUBU () { &subu;}' unless defined(&PTR_SUBU);
	eval 'sub PTR_ADDU () { &addu;}' unless defined(&PTR_ADDU);
	eval 'sub LI () { &li;}' unless defined(&LI);
	eval 'sub LA () { &la;}' unless defined(&LA);
	eval 'sub PTR_SLL () { &sll;}' unless defined(&PTR_SLL);
	eval 'sub PTR_SRL () { &srl;}' unless defined(&PTR_SRL);
	eval 'sub PTR_VAL () {. &word;}' unless defined(&PTR_VAL);
    } else {
	eval 'sub PTR_L () { &ld;}' unless defined(&PTR_L);
	eval 'sub PTR_S () { &sd;}' unless defined(&PTR_S);
	eval 'sub PTR_ADD () { &dadd;}' unless defined(&PTR_ADD);
	eval 'sub PTR_SUB () { &dsub;}' unless defined(&PTR_SUB);
	eval 'sub PTR_SUBU () { &dsubu;}' unless defined(&PTR_SUBU);
	eval 'sub PTR_ADDU () { &daddu;}' unless defined(&PTR_ADDU);
	eval 'sub LI () { &dli;}' unless defined(&LI);
	eval 'sub LA () { &dla;}' unless defined(&LA);
	eval 'sub PTR_SLL () { &dsll;}' unless defined(&PTR_SLL);
	eval 'sub PTR_SRL () { &dsrl;}' unless defined(&PTR_SRL);
	eval 'sub PTR_VAL () {. &dword;}' unless defined(&PTR_VAL);
    }
    if(defined( &XGPROF) || defined( &XPROF)) {
	eval 'sub MCOUNT () { &PTR_SUBU  &sp,  &sp, 32;  &SAVE_GP(16);  &sw  &ra, 28( &sp);  &sw  &gp, 24( &sp); . &set  &noat; . &set  &noreorder;  &move  &AT,  &ra;  &jal  &_mcount;  &PTR_SUBU  &sp,  &sp, 8;  &lw  &ra, 28( &sp);  &PTR_ADDU  &sp,  &sp, 32; . &set  &reorder; . &set  &at;;}' unless defined(&MCOUNT);
    } else {
	eval 'sub MCOUNT () {1;}' unless defined(&MCOUNT);
    }
    eval 'sub LEAF {
        my($x, $fsize) = @_;
	    eval q(. &align 3; . &globl $x; . &ent $x, 0; $x: ; . &frame  &sp, $fsize,  &ra;  &SETUP_GP  &MCOUNT);
    }' unless defined(&LEAF);
    eval 'sub ALEAF {
        my($x) = @_;
	    eval q(. &globl $x; $x:);
    }' unless defined(&ALEAF);
    eval 'sub NLEAF {
        my($x, $fsize) = @_;
	    eval q(. &align 3; . &globl $x; . &ent $x, 0; $x: ; . &frame  &sp, $fsize,  &ra;  &SETUP_GP);
    }' unless defined(&NLEAF);
    eval 'sub NON_LEAF {
        my($x, $fsize, $retpc) = @_;
	    eval q(. &align 3; . &globl $x; . &ent $x, 0; $x: ; . &frame  &sp, $fsize, $retpc;  &SETUP_GP  &MCOUNT);
    }' unless defined(&NON_LEAF);
    eval 'sub NNON_LEAF {
        my($x, $fsize, $retpc) = @_;
	    eval q(. &align 3; . &globl $x; . &ent $x, 0; $x: ; . &frame  &sp, $fsize, $retpc  &SETUP_GP);
    }' unless defined(&NNON_LEAF);
    eval 'sub END {
        my($x) = @_;
	    eval q(. &end $x);
    }' unless defined(&END);
    eval 'sub PANIC {
        my($msg) = @_;
	    eval q( &LA  &a0, 9 &f;  &jal  &panic;  &nop ;  &MSG($msg));
    }' unless defined(&PANIC);
    eval 'sub PRINTF {
        my($msg) = @_;
	    eval q( &la  &a0, 9 &f;  &jal  &printf;  &nop ;  &MSG($msg));
    }' unless defined(&PRINTF);
    eval 'sub MSG {
        my($msg) = @_;
	    eval q(. &rdata; 9: . &asciiz $msg; . &text);
    }' unless defined(&MSG);
    eval 'sub ASMSTR {
        my($str) = @_;
	    eval q(. &asciiz $str; . &align 3);
    }' unless defined(&ASMSTR);
}
1;
