1139825Simp/*- 277957Sbenno * Copyright (C) 1995-1997 Wolfgang Solfrank. 377957Sbenno * Copyright (C) 1995-1997 TooLs GmbH. 477957Sbenno * All rights reserved. 577957Sbenno * 677957Sbenno * Redistribution and use in source and binary forms, with or without 777957Sbenno * modification, are permitted provided that the following conditions 877957Sbenno * are met: 977957Sbenno * 1. Redistributions of source code must retain the above copyright 1077957Sbenno * notice, this list of conditions and the following disclaimer. 1177957Sbenno * 2. Redistributions in binary form must reproduce the above copyright 1277957Sbenno * notice, this list of conditions and the following disclaimer in the 1377957Sbenno * documentation and/or other materials provided with the distribution. 1477957Sbenno * 3. All advertising materials mentioning features or use of this software 1577957Sbenno * must display the following acknowledgement: 1677957Sbenno * This product includes software developed by TooLs GmbH. 1777957Sbenno * 4. The name of TooLs GmbH may not be used to endorse or promote products 1877957Sbenno * derived from this software without specific prior written permission. 1977957Sbenno * 2077957Sbenno * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2177957Sbenno * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2277957Sbenno * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2377957Sbenno * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2477957Sbenno * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2577957Sbenno * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2677957Sbenno * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2777957Sbenno * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2877957Sbenno * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2977957Sbenno * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3077957Sbenno * 3177957Sbenno * $NetBSD: cpu.h,v 1.11 2000/05/26 21:19:53 thorpej Exp $ 3277957Sbenno * $FreeBSD: releng/11.0/sys/powerpc/include/cpu.h 293052 2016-01-02 18:15:10Z nwhitehorn $ 3377957Sbenno */ 3477957Sbenno 3577957Sbenno#ifndef _MACHINE_CPU_H_ 3677957Sbenno#define _MACHINE_CPU_H_ 3777957Sbenno 3877957Sbenno#include <machine/frame.h> 3977957Sbenno#include <machine/pcb.h> 4077957Sbenno#include <machine/psl.h> 4177957Sbenno 42199886Snwhitehorn/* 43199886Snwhitehorn * CPU Feature Attributes 44199886Snwhitehorn * 45199886Snwhitehorn * These are defined in the PowerPC ELF ABI for the AT_HWCAP vector, 46199886Snwhitehorn * and are exported to userland via the machdep.cpu_features 47199886Snwhitehorn * sysctl. 48199886Snwhitehorn */ 49199886Snwhitehorn 50199886Snwhitehornextern int cpu_features; 51293052Snwhitehornextern int cpu_features2; 52199886Snwhitehorn 53199886Snwhitehorn#define PPC_FEATURE_32 0x80000000 /* Always true */ 54199886Snwhitehorn#define PPC_FEATURE_64 0x40000000 /* Defined on a 64-bit CPU */ 55199886Snwhitehorn#define PPC_FEATURE_HAS_ALTIVEC 0x10000000 56199886Snwhitehorn#define PPC_FEATURE_HAS_FPU 0x08000000 57199886Snwhitehorn#define PPC_FEATURE_HAS_MMU 0x04000000 58293052Snwhitehorn#define PPC_FEATURE_UNIFIED_CACHE 0x01000000 59293052Snwhitehorn#define PPC_FEATURE_BOOKE 0x00008000 60293052Snwhitehorn#define PPC_FEATURE_SMT 0x00004000 61293052Snwhitehorn#define PPC_FEATURE_ARCH_2_05 0x00001000 62293052Snwhitehorn#define PPC_FEATURE_HAS_DFP 0x00000400 63293052Snwhitehorn#define PPC_FEATURE_ARCH_2_06 0x00000100 64293052Snwhitehorn#define PPC_FEATURE_HAS_VSX 0x00000080 65199886Snwhitehorn 66293052Snwhitehorn#define PPC_FEATURE2_ARCH_2_07 0x80000000 67293052Snwhitehorn#define PPC_FEATURE2_HAS_HTM 0x40000000 68293052Snwhitehorn#define PPC_FEATURE2_HAS_VCRYPTO 0x02000000 69293052Snwhitehorn 70199886Snwhitehorn#define PPC_FEATURE_BITMASK \ 71199886Snwhitehorn "\20" \ 72279189Snwhitehorn "\040PPC32\037PPC64\035ALTIVEC\034FPU\033MMU\031UNIFIEDCACHE" \ 73293052Snwhitehorn "\020BOOKE\017SMT\015ARCH205\013DFP\011ARCH206\010VSX" 74293052Snwhitehorn#define PPC_FEATURE2_BITMASK \ 75293052Snwhitehorn "\20" \ 76293052Snwhitehorn "\040ARCH207\037HTM\032VCRYPTO" 77199886Snwhitehorn 7891459Sbenno#define TRAPF_USERMODE(frame) (((frame)->srr1 & PSL_PR) != 0) 7979036Sbenno#define TRAPF_PC(frame) ((frame)->srr0) 8079036Sbenno 8177957Sbenno/* 8277957Sbenno * CTL_MACHDEP definitions. 8377957Sbenno */ 8477957Sbenno#define CPU_CACHELINE 1 8577957Sbenno 8677957Sbennostatic __inline u_int64_t 8777957Sbennoget_cyclecount(void) 8877957Sbenno{ 89109476Sgrehan u_int32_t _upper, _lower; 90109476Sgrehan u_int64_t _time; 9177957Sbenno 9277957Sbenno __asm __volatile( 9377957Sbenno "mftb %0\n" 9477957Sbenno "mftbu %1" 95109476Sgrehan : "=r" (_lower), "=r" (_upper)); 9677957Sbenno 97109476Sgrehan _time = (u_int64_t)_upper; 98109476Sgrehan _time = (_time << 32) + _lower; 99109476Sgrehan return (_time); 10077957Sbenno} 10177957Sbenno 10283682Smp#define cpu_getstack(td) ((td)->td_frame->fixreg[1]) 103278481Snwhitehorn#define cpu_spinwait() __asm __volatile("or 27,27,27") /* yield */ 10477957Sbenno 105184316Smarcelextern char btext[]; 106184316Smarcelextern char etext[]; 107184316Smarcel 108118990Smarcelvoid cpu_halt(void); 109118990Smarcelvoid cpu_reset(void); 110261309Sjhibbitsvoid cpu_sleep(void); 111261309Sjhibbitsvoid flush_disable_caches(void); 112118990Smarcelvoid fork_trampoline(void); 113118990Smarcelvoid swi_vm(void *); 114118990Smarcel 11577957Sbenno#endif /* _MACHINE_CPU_H_ */ 116