require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_MACHINE_TCB_H_)) {
    eval 'sub _MACHINE_TCB_H_ () {1;}' unless defined(&_MACHINE_TCB_H_);
    if(defined(&_KERNEL)) {
	eval 'sub TCB_GET {
	    my($p) = @_;
    	    eval q((( &void *) &trapframe($p)-> $fixreg[2]));
	}' unless defined(&TCB_GET);
	eval 'sub TCB_SET {
	    my($p, $addr) = @_;
    	    eval q(( &trapframe($p)-> $fixreg[2] = ( &__register_t)($addr)));
	}' unless defined(&TCB_SET);
    } else {
	eval 'sub TLS_VARIANT () {1;}' unless defined(&TLS_VARIANT);
	if(0) {
	    eval 'sub TCB_GET () {
	        eval q(( &__tcb));
	    }' unless defined(&TCB_GET);
	    eval 'sub TCB_GET_MEMBER {
	        my($member) = @_;
    		eval q((( &void *)( ($__tcb->{member}))));
	    }' unless defined(&TCB_GET_MEMBER);
	    eval 'sub TCB_SET {
	        my($tcb) = @_;
    		eval q((( &__tcb) = ($tcb)));
	    }' unless defined(&TCB_SET);
	} else {
	    require 'stddef.ph';
	    eval 'sub TCB_GET () {
	        eval q( &__powerpc_get_tcb());
	    }' unless defined(&TCB_GET);
	    eval 'sub TCB_GET_MEMBER {
	        my($member) = @_;
    		eval q( &__powerpc_read_tcb( &offsetof(\'struct thread_control_block\', $member)));
	    }' unless defined(&TCB_GET_MEMBER);
	    eval 'sub TCB_SET {
	        my($tcb) = @_;
    		eval q( &__asm  &__volatile(\\"mr %%r2, %0\\" : : \\"r\\" ($tcb)));
	    }' unless defined(&TCB_SET);
	}
    }
}
1;
