Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754524AbbGXJpl (ORCPT ); Fri, 24 Jul 2015 05:45:41 -0400 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]:57128 "EHLO eu-smtp-delivery-143.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754358AbbGXJou (ORCPT ); Fri, 24 Jul 2015 05:44:50 -0400 From: "Suzuki K. Poulose" To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, edward.nevill@linaro.org, aph@redhat.com, linux-kernel@vger.kernel.org, "Suzuki K. Poulose" Subject: sample: arm64 cpu feature: Test program Date: Fri, 24 Jul 2015 10:43:57 +0100 Message-Id: <1437731037-25795-12-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1437731037-25795-1-git-send-email-suzuki.poulose@arm.com> References: <1437731037-25795-1-git-send-email-suzuki.poulose@arm.com> X-OriginalArrivalTime: 24 Jul 2015 09:44:43.0011 (UTC) FILETIME=[5E192530:01D0C5F5] X-MC-Unique: CWDfS7bgSUmECNmQYP4K7A-7 Content-Type: text/plain; charset=WINDOWS-1252 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id t6O9kSgm027120 Content-Length: 3135 Lines: 114 From: "Suzuki K. Poulose" Attached is a sample program that fetches all the emulated cpu feature registers and traps on accessing an invalid id register. --- /* * show_sysregs_all: Sample program to retrieve the * CPU feature registers. * * Author: Suzuki K. Poulose * * Copyright (C) 2015 ARM Ltd. * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include /// /* Copied from asm/sysreg.h */ #define sys_reg(op0, op1, crn, crm, op2) \ ((((op0)&3)<<19)|((op1)<<16)|((crn)<<12)|((crm)<<8)|((op2)<<5)) asm( " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" " .equ __reg_num_x\\num, \\num\n" " .endr\n" " .equ __reg_num_xzr, 31\n" "\n" " .macro mrs_s, rt, sreg\n" " .inst 0xd5200000|(\\sreg)|(__reg_num_\\rt)\n" " .endm\n" "\n" " .macro msr_s, sreg, rt\n" " .inst 0xd5000000|(\\sreg)|(__reg_num_\\rt)\n" " .endm\n" ); /// #define get_cpu_ftr(id) ({ \ unsigned long long __val; \ asm("mrs %0, "#id : "=r" (__val)); \ printf("%-20s: 0x%016lx\n", #id, __val); \ }) #define __get_id_reg(id) ({ \ unsigned long long __val; \ asm("mrs_s %0, "#id : "=r" (__val)); \ printf("%-20s: 0x%016lx\n", get_id_str(id), __val); \ }) #define get_id_reg(x) __get_id_reg(x) #define get_id_range(CRm) \ get_id_reg(sys_reg(3, 0, 0, CRm, 0)); \ get_id_reg(sys_reg(3, 0, 0, CRm, 1)); \ get_id_reg(sys_reg(3, 0, 0, CRm, 2)); \ get_id_reg(sys_reg(3, 0, 0, CRm, 3)); \ get_id_reg(sys_reg(3, 0, 0, CRm, 4)); \ get_id_reg(sys_reg(3, 0, 0, CRm, 5)); \ get_id_reg(sys_reg(3, 0, 0, CRm, 6)); \ get_id_reg(sys_reg(3, 0, 0, CRm, 7)); #define Op0(id) (((id) >> 19) & 0x3) #define Op1(id) (((id) >> 16) & 0x7) #define CRn(id) (((id) >> 12) & 0xf) #define CRm(id) (((id) >> 8) & 0xf) #define Op2(id) (((id) >> 5) & 0x7) char *get_id_str(int id) { static char buf[64]; sprintf(buf, "S%d_%d_%d_%d_%d", Op0(id), Op1(id), CRn(id), CRm(id), Op2(id)); return buf; } main() { get_id_range(1); get_id_range(2); get_id_range(3); get_id_range(4); get_id_range(5); get_id_range(6); get_id_range(7); get_cpu_ftr(MIDR_EL1); get_cpu_ftr(REVIDR_EL1); get_cpu_ftr(MPIDR_EL1); /* Trap */ get_id_reg(sys_reg(3, 0, 0, 0, 2)); return 0; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/