pmc_mdep.h revision 182790
1145256Sjkoshy/*- 2147191Sjkoshy * Copyright (c) 2003-2005 Joseph Koshy 3174395Sjkoshy * Copyright (c) 2007 The FreeBSD Foundation 4145256Sjkoshy * All rights reserved. 5145256Sjkoshy * 6174395Sjkoshy * Portions of this software were developed by A. Joseph Koshy under 7174395Sjkoshy * sponsorship from the FreeBSD Foundation and Google, Inc. 8174395Sjkoshy * 9145256Sjkoshy * Redistribution and use in source and binary forms, with or without 10145256Sjkoshy * modification, are permitted provided that the following conditions 11145256Sjkoshy * are met: 12145256Sjkoshy * 1. Redistributions of source code must retain the above copyright 13145256Sjkoshy * notice, this list of conditions and the following disclaimer. 14145256Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright 15145256Sjkoshy * notice, this list of conditions and the following disclaimer in the 16145256Sjkoshy * documentation and/or other materials provided with the distribution. 17145256Sjkoshy * 18145256Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19145256Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20145256Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21145256Sjkoshy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22145256Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23145256Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24145256Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25145256Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26145256Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27145256Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28145256Sjkoshy * SUCH DAMAGE. 29145256Sjkoshy * 30145256Sjkoshy * $FreeBSD: head/sys/i386/include/pmc_mdep.h 182790 2008-09-05 14:45:56Z jkoshy $ 31145256Sjkoshy */ 32145256Sjkoshy 33145256Sjkoshy#ifndef _MACHINE_PMC_MDEP_H 34145256Sjkoshy#define _MACHINE_PMC_MDEP_H 1 35145256Sjkoshy 36147191Sjkoshy/* 37147191Sjkoshy * On the i386 platform we support the following PMCs. 38147191Sjkoshy * 39147191Sjkoshy * K7 AMD Athlon XP/MP and other 32 bit processors. 40147191Sjkoshy * K8 AMD Athlon64 and Opteron PMCs in 32 bit mode. 41147191Sjkoshy * PIV Intel P4/HTT and P4/EMT64 42147191Sjkoshy * PPRO Intel Pentium Pro, Pentium-II, Pentium-III, Celeron and 43147191Sjkoshy * Pentium-M processors 44147191Sjkoshy * PENTIUM Intel Pentium MMX. 45147191Sjkoshy */ 46145256Sjkoshy 47147191Sjkoshy#include <dev/hwpmc/hwpmc_amd.h> /* K7 and K8 */ 48147191Sjkoshy#include <dev/hwpmc/hwpmc_piv.h> 49147191Sjkoshy#include <dev/hwpmc/hwpmc_ppro.h> 50147191Sjkoshy#include <dev/hwpmc/hwpmc_pentium.h> 51145256Sjkoshy 52147191Sjkoshy/* 53147191Sjkoshy * Architecture specific extensions to <sys/pmc.h> structures. 54147191Sjkoshy */ 55145256Sjkoshy 56147191Sjkoshyunion pmc_md_op_pmcallocate { 57147191Sjkoshy struct pmc_md_amd_op_pmcallocate pm_amd; 58147191Sjkoshy struct pmc_md_ppro_op_pmcallocate pm_ppro; 59147191Sjkoshy struct pmc_md_pentium_op_pmcallocate pm_pentium; 60147191Sjkoshy struct pmc_md_p4_op_pmcallocate pm_p4; 61147191Sjkoshy uint64_t __pad[4]; 62147191Sjkoshy}; 63145256Sjkoshy 64147191Sjkoshy/* Logging */ 65147191Sjkoshy#define PMCLOG_READADDR PMCLOG_READ32 66147191Sjkoshy#define PMCLOG_EMITADDR PMCLOG_EMIT32 67145256Sjkoshy 68147191Sjkoshy#ifdef _KERNEL 69145256Sjkoshy 70147191Sjkoshy/* MD extension for 'struct pmc' */ 71147191Sjkoshyunion pmc_md_pmc { 72147191Sjkoshy struct pmc_md_amd_pmc pm_amd; 73147191Sjkoshy struct pmc_md_ppro_pmc pm_ppro; 74147191Sjkoshy struct pmc_md_pentium_pmc pm_pentium; 75147191Sjkoshy struct pmc_md_p4_pmc pm_p4; 76147191Sjkoshy}; 77145256Sjkoshy 78147191Sjkoshystruct pmc; 79145256Sjkoshy 80174395Sjkoshy#define PMC_TRAPFRAME_TO_PC(TF) ((TF)->tf_eip) 81174395Sjkoshy#define PMC_TRAPFRAME_TO_FP(TF) ((TF)->tf_ebp) 82174395Sjkoshy#define PMC_TRAPFRAME_TO_SP(TF) ((TF)->tf_esp) 83174395Sjkoshy 84174395Sjkoshy#define PMC_IN_KERNEL_STACK(S,START,END) \ 85174395Sjkoshy ((S) >= (START) && (S) < (END)) 86174395Sjkoshy#define PMC_IN_KERNEL(va) (((va) >= USRSTACK) && \ 87174395Sjkoshy ((va) < VM_MAX_KERNEL_ADDRESS)) 88174395Sjkoshy 89174395Sjkoshy#define PMC_IN_USERSPACE(va) ((va) <= VM_MAXUSER_ADDRESS) 90174395Sjkoshy 91174395Sjkoshy#define PMC_IN_TRAP_HANDLER(PC) \ 92174395Sjkoshy ((PC) >= (uintptr_t) start_exceptions && \ 93174395Sjkoshy (PC) < (uintptr_t) end_exceptions) 94174395Sjkoshy 95174395Sjkoshy#define PMC_AT_FUNCTION_PROLOGUE_PUSH_BP(I) \ 96182790Sjkoshy (((I) & 0x00ffffff) == 0xe58955) /* pushl %ebp; movl %esp,%ebp */ 97174395Sjkoshy#define PMC_AT_FUNCTION_PROLOGUE_MOV_SP_BP(I) \ 98182790Sjkoshy (((I) & 0x0000ffff) == 0xe589) /* movl %esp,%ebp */ 99174395Sjkoshy#define PMC_AT_FUNCTION_EPILOGUE_RET(I) \ 100174395Sjkoshy (((I) & 0xFF) == 0xC3) /* ret */ 101174395Sjkoshy 102145256Sjkoshy/* 103145256Sjkoshy * Prototypes 104145256Sjkoshy */ 105145256Sjkoshy 106174395Sjkoshyvoid start_exceptions(void), end_exceptions(void); 107147191Sjkoshyvoid pmc_x86_lapic_enable_pmc_interrupt(void); 108145256Sjkoshy 109145256Sjkoshy#endif /* _KERNEL */ 110145256Sjkoshy#endif /* _MACHINE_PMC_MDEP_H */ 111