require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_AMD64_PCTR_H_)) {
    eval 'sub _AMD64_PCTR_H_ () {1;}' unless defined(&_AMD64_PCTR_H_);
    require 'sys/ioccom.ph';
    eval 'sub PCTR_NUM () {4;}' unless defined(&PCTR_NUM);
    eval 'sub PCTR_U () {0x10000;}' unless defined(&PCTR_U);
    eval 'sub PCTR_K () {0x20000;}' unless defined(&PCTR_K);
    eval 'sub PCTR_E () {0x40000;}' unless defined(&PCTR_E);
    eval 'sub PCTR_EN () {0x400000;}' unless defined(&PCTR_EN);
    eval 'sub PCTR_I () {0x800000;}' unless defined(&PCTR_I);
    eval 'sub PCTR_UM_M () {0x800;}' unless defined(&PCTR_UM_M);
    eval 'sub PCTR_UM_E () {0x400;}' unless defined(&PCTR_UM_E);
    eval 'sub PCTR_UM_S () {0x200;}' unless defined(&PCTR_UM_S);
    eval 'sub PCTR_UM_I () {0x100;}' unless defined(&PCTR_UM_I);
    eval 'sub PCTR_UM_MESI () {( &PCTR_UM_M| &PCTR_UM_E| &PCTR_UM_S| &PCTR_UM_I);}' unless defined(&PCTR_UM_MESI);
    eval 'sub PCTR_UM_A () {0x2000;}' unless defined(&PCTR_UM_A);
    eval 'sub PCTR_UM_SHIFT () {8;}' unless defined(&PCTR_UM_SHIFT);
    eval 'sub PCTR_CM_SHIFT () {24;}' unless defined(&PCTR_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 PCIOCS2 () { &_IOW(ord(\'c\'), 10, \'unsigned int\');}' unless defined(&PCIOCS2);
    eval 'sub PCIOCS3 () { &_IOW(ord(\'c\'), 11, \'unsigned int\');}' unless defined(&PCIOCS3);
    eval 'sub _PATH_PCTR () {"/dev/pctr";}' unless defined(&_PATH_PCTR);
    eval 'sub rdtsc () {
        eval q(({  &u_int32_t  &hi,  &lo;  &__asm  &__volatile(\\"rdtsc\\" : \\"=d\\" ( &hi), \\"=a\\" ( &lo)); (( &u_int64_t) &hi << 32) | ( &u_int64_t) &lo; }));
    }' unless defined(&rdtsc);
    eval 'sub rdpmc {
        my($pmc) = @_;
	    eval q(({  &u_int32_t  &hi,  &lo;  &__asm  &__volatile(\\"rdpmc\\" : \\"=d\\" ( &hi), \\"=a\\" ( &lo) : \\"c\\" ($pmc));  &hi &= 0xffffff; ((( &u_int64_t) &hi << 32) | ( &u_int64_t) &lo); }));
    }' unless defined(&rdpmc);
    if(defined(&_KERNEL)) {
	eval 'sub rdmsr {
	    my($msr) = @_;
    	    eval q(({  &u_int32_t  &hi,  &lo;  &__asm  &__volatile(\\"rdmsr\\" : \\"=d\\" ( &hi), \\"=a\\" ( &lo) : \\"c\\" ($msr)); (( &u_int64_t) &hi << 32) | ( &u_int64_t)  &lo; }));
	}' unless defined(&rdmsr);
	eval 'sub wrmsr {
	    my($msr, $v) = @_;
    	    eval q(({  &__asm  &__volatile(\\"wrmsr\\" : : \\"a\\" (( &u_int64_t)$v & 0xffffffff), \\"d\\" (( &u_int64_t)$v >> 32), \\"c\\" ($msr)); }));
	}' unless defined(&wrmsr);
    }
}
1;
