require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_MACHINE_LOCK_H_)) {
    eval 'sub _MACHINE_LOCK_H_ () {1;}' unless defined(&_MACHINE_LOCK_H_);
    eval 'sub __SIMPLELOCK_LOCKED () {1;}' unless defined(&__SIMPLELOCK_LOCKED);
    eval 'sub __SIMPLELOCK_UNLOCKED () {0;}' unless defined(&__SIMPLELOCK_UNLOCKED);
    eval 'sub __cpu_simple_lock_init {
        my($alp) = @_;
	    eval q({  &__asm  &__volatile( \\"# BEGIN __cpu_simple_lock_init\\\\n\\" \\"	stl	$31, %0		\\\\n\\" \\"	mb			\\\\n\\" \\"	# END __cpu_simple_lock_init\\" : \\"=m\\" (*$alp)); });
    }' unless defined(&__cpu_simple_lock_init);
    eval 'sub __cpu_simple_lock {
        my($alp) = @_;
	    eval q({ my $t0;  &__asm  &__volatile( \\"# BEGIN __cpu_simple_lock\\\\n\\" \\"1:	ldl_l	%0, %3		\\\\n\\" \\"	bne	%0, 2f		\\\\n\\" \\"	bis	$31, %2, %0	\\\\n\\" \\"	stl_c	%0, %1		\\\\n\\" \\"	beq	%0, 3f		\\\\n\\" \\"	mb			\\\\n\\" \\"	br	4f		\\\\n\\" \\"2:	ldl	%0, %3		\\\\n\\" \\"	beq	%0, 1b		\\\\n\\" \\"	br	2b		\\\\n\\" \\"3:	br	1b		\\\\n\\" \\"4:				\\\\n\\" \\"	# END __cpu_simple_lock\\\\n\\" : \\"=&r\\" ( $t0), \\"=m\\" (*$alp) : \\"i\\" ( &__SIMPLELOCK_LOCKED), \\"m\\" (*$alp) : \\"memory\\"); });
    }' unless defined(&__cpu_simple_lock);
    eval 'sub __cpu_simple_lock_try {
        my($alp) = @_;
	    eval q({ my $t0,  &v0;  &__asm  &__volatile( \\"# BEGIN __cpu_simple_lock_try\\\\n\\" \\"1:	ldl_l	%0, %4		\\\\n\\" \\"	bne	%0, 2f		\\\\n\\" \\"	bis	$31, %3, %0	\\\\n\\" \\"	stl_c	%0, %2		\\\\n\\" \\"	beq	%0, 3f		\\\\n\\" \\"	mb			\\\\n\\" \\"	bis	$31, 1, %1	\\\\n\\" \\"	br	4f		\\\\n\\" \\"2:	bis	$31, $31, %1	\\\\n\\" \\"	br	4f		\\\\n\\" \\"3:	br	1b		\\\\n\\" \\"4:				\\\\n\\" \\"	# END __cpu_simple_lock_try\\" : \\"=&r\\" ( $t0), \\"=r\\" ( &v0), \\"=m\\" (*$alp) : \\"i\\" ( &__SIMPLELOCK_LOCKED), \\"m\\" (*$alp) : \\"memory\\"); ( &v0 != 0); });
    }' unless defined(&__cpu_simple_lock_try);
    eval 'sub __cpu_simple_unlock {
        my($alp) = @_;
	    eval q({  &__asm  &__volatile( \\"# BEGIN __cpu_simple_unlock\\\\n\\" \\"	mb			\\\\n\\" \\"	stl	$31, %0		\\\\n\\" \\"	# END __cpu_simple_unlock\\" : \\"=m\\" (*$alp)); });
    }' unless defined(&__cpu_simple_unlock);
    if(defined(&MULTIPROCESSOR)) {
	eval 'sub SPINLOCK_SPIN_HOOK () { &do { \'struct cpu_info\' * &__ci =  &curcpu(); \'int\'  &__s;  &if ( ($__ci->{ci_ipis}) != 0) {  &__s =  &splipi();  &alpha_ipi_process( &__ci,  &NULL);  &splx( &__s); } }  &while (0);}' unless defined(&SPINLOCK_SPIN_HOOK);
    }
}
1;
