require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_I386_PCTR_H_)) {
    eval 'sub _I386_PCTR_H_ () {1;}' unless defined(&_I386_PCTR_H_);
    require 'sys/ioccom.ph';
    eval 'sub PCTR_NUM () {2;}' unless defined(&PCTR_NUM);
    eval 'sub P5CTR_K () {0x40;}' unless defined(&P5CTR_K);
    eval 'sub P5CTR_U () {0x80;}' unless defined(&P5CTR_U);
    eval 'sub P5CTR_C () {0x100;}' unless defined(&P5CTR_C);
    eval 'sub P6CTR_U () {0x10000;}' unless defined(&P6CTR_U);
    eval 'sub P6CTR_K () {0x20000;}' unless defined(&P6CTR_K);
    eval 'sub P6CTR_E () {0x40000;}' unless defined(&P6CTR_E);
    eval 'sub P6CTR_EN () {0x400000;}' unless defined(&P6CTR_EN);
    eval 'sub P6CTR_I () {0x800000;}' unless defined(&P6CTR_I);
    eval 'sub P6CTR_UM_M () {0x800;}' unless defined(&P6CTR_UM_M);
    eval 'sub P6CTR_UM_E () {0x400;}' unless defined(&P6CTR_UM_E);
    eval 'sub P6CTR_UM_S () {0x200;}' unless defined(&P6CTR_UM_S);
    eval 'sub P6CTR_UM_I () {0x100;}' unless defined(&P6CTR_UM_I);
    eval 'sub P6CTR_UM_MESI () {( &P6CTR_UM_M| &P6CTR_UM_E| &P6CTR_UM_S| &P6CTR_UM_I);}' unless defined(&P6CTR_UM_MESI);
    eval 'sub P6CTR_UM_A () {0x2000;}' unless defined(&P6CTR_UM_A);
    eval 'sub P6CTR_CM_SHIFT () {24;}' unless defined(&P6CTR_CM_SHIFT);
    eval 'sub PCIOCRD () { &_IOR(ord(\'c\'), 1, \'struct pctrst\');}' unless defined(&PCIOCRD);
    eval 'sub PCIOCS0 () { &_IOW(ord(\'c\'), 8, \'unsigned int\');}' unless defined(&PCIOCS0);
    eval 'sub PCIOCS1 () { &_IOW(ord(\'c\'), 9, \'unsigned int\');}' unless defined(&PCIOCS1);
    eval 'sub _PATH_PCTR () {"/dev/pctr";}' unless defined(&_PATH_PCTR);
    eval 'sub rdtsc () {
        eval q(({  &pctrval  &v;  &__asm  &__volatile (\\"rdtsc\\" : \\"=A\\" ( &v));  &v; }));
    }' unless defined(&rdtsc);
    eval 'sub rdpmc {
        local($ctr) = @_;
	    eval q(({  &pctrval  &v;  &__asm  &__volatile (\\"rdpmc\\\\n\\" \\"\\\\tandl $0xff, %%edx\\" : \\"=A\\" ( &v) : \\"c\\" ($ctr));  &v; }));
    }' unless defined(&rdpmc);
    if(defined(&_KERNEL)) {
	eval 'sub rdmsr {
	    local($msr) = @_;
    	    eval q(({  &pctrval  &v;  &__asm  &__volatile (\\"rdmsr\\" : \\"=A\\" ( &v) : \\"c\\" ($msr));  &v; }));
	}' unless defined(&rdmsr);
	eval 'sub wrmsr {
	    local($msr, $v) = @_;
    	    eval q( &__asm  &__volatile (\\"wrmsr\\" :: \\"A\\" (( &u_quad_t) ($v)), \\"c\\" ($msr)););
	}' unless defined(&wrmsr);
    }
}
1;
