require '_h2ph_pre.ph';

unless(defined(&PSR_IMPL)) {
    eval 'sub PSR_IMPL () {0xf0000000;}' unless defined(&PSR_IMPL);
    eval 'sub PSR_VER () {0x0f000000;}' unless defined(&PSR_VER);
    eval 'sub PSR_ICC () {0x00f00000;}' unless defined(&PSR_ICC);
    eval 'sub PSR_N () {0x00800000;}' unless defined(&PSR_N);
    eval 'sub PSR_Z () {0x00400000;}' unless defined(&PSR_Z);
    eval 'sub PSR_O () {0x00200000;}' unless defined(&PSR_O);
    eval 'sub PSR_C () {0x00100000;}' unless defined(&PSR_C);
    eval 'sub PSR_EC () {0x00002000;}' unless defined(&PSR_EC);
    eval 'sub PSR_EF () {0x00001000;}' unless defined(&PSR_EF);
    eval 'sub PSR_PIL () {0x00000f00;}' unless defined(&PSR_PIL);
    eval 'sub PSR_S () {0x00000080;}' unless defined(&PSR_S);
    eval 'sub PSR_PS () {0x00000040;}' unless defined(&PSR_PS);
    eval 'sub PSR_ET () {0x00000020;}' unless defined(&PSR_ET);
    eval 'sub PSR_CWP () {0x0000001f;}' unless defined(&PSR_CWP);
    eval 'sub PSR_BITS () {"\\20\\16EC\\15EF\\10S\\7PS\\6ET";}' unless defined(&PSR_BITS);
    eval 'sub PIL_CLOCK () {10;}' unless defined(&PIL_CLOCK);
    if(defined( &_KERNEL)  && !defined( &_LOCORE)) {
	eval 'sub SPL {
	    local($name, $newipl) = @_;
    	    eval q( &static  &__inline \'int\' $name  &__P(( &void));  &static  &__inline \'int\' $name() { \'int\'  &psr,  &oldipl;  &__asm  &__volatile(\\"rd %%psr,%0\\" : \\"=r\\" ( &psr));  &oldipl =  &psr &  &PSR_PIL;  &psr &= ~ &oldipl;  &__asm  &__volatile(\\"wr %0,%1,%%psr\\" : : \\"r\\" ( &psr), \\"n\\" (($newipl) << 8));  &__asm  &__volatile(\\"nop; nop; nop\\");  &return ( &oldipl); });
	}' unless defined(&SPL);
	eval 'sub SPLHOLD {
	    local($name, $newipl) = @_;
    	    eval q( &static  &__inline \'int\' $name  &__P(( &void));  &static  &__inline \'int\' $name() { \'int\'  &psr,  &oldipl;  &__asm  &__volatile(\\"rd %%psr,%0\\" : \\"=r\\" ( &psr));  &oldipl =  &psr &  &PSR_PIL;  &if (($newipl << 8) <=  &oldipl)  &return  &oldipl;  &psr &= ~ &oldipl;  &__asm  &__volatile(\\"wr %0,%1,%%psr\\" : : \\"r\\" ( &psr), \\"n\\" (($newipl) << 8));  &__asm  &__volatile(\\"nop; nop; nop\\");  &return ( &oldipl); });
	}' unless defined(&SPLHOLD);
	eval 'sub splsoftclock () { &splsoftint;}' unless defined(&splsoftclock);
	eval 'sub splsoftnet () { &splsoftint;}' unless defined(&splsoftnet);
	eval 'sub PIL_AUSOFT () {4;}' unless defined(&PIL_AUSOFT);
	eval 'sub PIL_FDSOFT () {4;}' unless defined(&PIL_FDSOFT);
	eval 'sub PIL_NET () {6;}' unless defined(&PIL_NET);
	eval 'sub PIL_TTY () {6;}' unless defined(&PIL_TTY);
    }
}
1;
