From patchwork Thu Oct 21 14:36:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?Q?Llu=C3=ADs?= X-Patchwork-Id: 68955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0E174B6EE8 for ; Sat, 23 Oct 2010 07:06:17 +1100 (EST) Received: from localhost ([127.0.0.1]:48845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9NsO-0004t6-8S for incoming@patchwork.ozlabs.org; Fri, 22 Oct 2010 16:06:08 -0400 Received: from [140.186.70.92] (port=58995 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9MuU-00026f-5i for qemu-devel@nongnu.org; Fri, 22 Oct 2010 15:04:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P9MuS-0006ev-PF for qemu-devel@nongnu.org; Fri, 22 Oct 2010 15:04:13 -0400 Received: from mailout-de.gmx.net ([213.165.64.23]:48970 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1P9MuS-0006en-Ct for qemu-devel@nongnu.org; Fri, 22 Oct 2010 15:04:12 -0400 Received: (qmail invoked by alias); 22 Oct 2010 19:04:10 -0000 Received: from unknown (EHLO localhost) [84.88.53.92] by mail.gmx.net (mp059) with SMTP; 22 Oct 2010 21:04:10 +0200 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX184OVs1kX04wZzxdOOvS4+0rSg/F6WAPk8IMl9z9S a6JXEtV+ynIS9T From: xscript@gmx.net (=?utf-8?Q?Llu=C3=ADs?=) To: qemu-devel@nongnu.org In-Reply-To: Date: Thu, 21 Oct 2010 16:36:29 +0200 References: Message-Id: <1a678ab4a0015952bc61db7b6eb0c36133e22d28.1287772676.git.vilanova@ac.upc.edu> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 11/18] instrument: Code-generation macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Provides some code-generation macros intended to be used by the user when generating code on instrumentation points. Signed-off-by: Lluís Vilanova --- cpu-all.h | 2 + instrument/generate.h | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ instrument/types.h | 33 +++++++++++++ 3 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 instrument/generate.h create mode 100644 instrument/types.h diff --git a/cpu-all.h b/cpu-all.h index 1be1c60..b15253f 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -24,6 +24,8 @@ #if defined(CONFIG_INSTRUMENT) +#include "instrument/types.h" +#include "instrument/generate.h" #include "instrument/control.h" #include "instrument/state.h" diff --git a/instrument/generate.h b/instrument/generate.h new file mode 100644 index 0000000..7e4b35c --- /dev/null +++ b/instrument/generate.h @@ -0,0 +1,124 @@ +/* + * User macros for code generation in static instrumentation points. + * + * Copyright (c) 2010 Lluís Vilanova + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef INSTRUMENT__GENERATE_H +#define INSTRUMENT__GENERATE_H + +/* Generate calls to code helpers (callback) with the provided arguments. + * + * Note that each argument comes in pairs: the type (instr_arg_type_t) and the + * value. + */ + +#define INSTR_GEN_0(callback) \ + do { \ + gen_helper_ ##callback(); \ + } while(0) + +#define INSTR_GEN_1(callback, type1, arg1) \ + do { \ + __INSTR_ARG_DECL(tmp1, type1, arg1); \ + gen_helper_ ##callback (tmp1); \ + __INSTR_ARG_FREE(tmp1, type1); \ + } while(0) + +#define INSTR_GEN_2(callback, type1, arg1, type2, arg2) \ + do { \ + __INSTR_ARG_DECL(tmp1, type1, arg1); \ + __INSTR_ARG_DECL(tmp2, type2, arg2); \ + gen_helper_ ##callback (tmp1, tmp2); \ + __INSTR_ARG_FREE(tmp1, type1); \ + __INSTR_ARG_FREE(tmp2, type2); \ + } while(0) + +#define INSTR_GEN_3(callback, type1, arg1, type2, arg2, type3, arg3) \ + do { \ + __INSTR_ARG_DECL(tmp1, type1, arg1); \ + __INSTR_ARG_DECL(tmp2, type2, arg2); \ + __INSTR_ARG_DECL(tmp3, type3, arg3); \ + gen_helper_ ##callback (tmp1, tmp2, tmp3); \ + __INSTR_ARG_FREE(tmp1, type1); \ + __INSTR_ARG_FREE(tmp2, type2); \ + __INSTR_ARG_FREE(tmp3, type3); \ + } while(0) + +#define INSTR_GEN_4(callback, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4) \ + do { \ + __INSTR_ARG_DECL(tmp1, type1, arg1); \ + __INSTR_ARG_DECL(tmp2, type2, arg2); \ + __INSTR_ARG_DECL(tmp3, type3, arg3); \ + __INSTR_ARG_DECL(tmp4, type4, arg4); \ + gen_helper_ ##callback (tmp1, tmp2, tmp3, tmp4); \ + __INSTR_ARG_FREE(tmp1, type1); \ + __INSTR_ARG_FREE(tmp2, type2); \ + __INSTR_ARG_FREE(tmp3, type3); \ + __INSTR_ARG_FREE(tmp4, type4); \ + } while(0) + +#define INSTR_GEN_5(callback, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5) \ + do { \ + __INSTR_ARG_DECL(tmp1, type1, arg1); \ + __INSTR_ARG_DECL(tmp2, type2, arg2); \ + __INSTR_ARG_DECL(tmp3, type3, arg3); \ + __INSTR_ARG_DECL(tmp4, type4, arg4); \ + __INSTR_ARG_DECL(tmp5, type5, arg5); \ + gen_helper_ ##callback (tmp1, tmp2, tmp3, tmp4, tmp5); \ + __INSTR_ARG_FREE(tmp1, type1); \ + __INSTR_ARG_FREE(tmp2, type2); \ + __INSTR_ARG_FREE(tmp3, type3); \ + __INSTR_ARG_FREE(tmp4, type4); \ + __INSTR_ARG_FREE(tmp5, type5); \ + } while(0) + + +/* Internal API */ + +/* Argument type conversion into TCGv temporaries */ + +#define __INSTR_ARG_I32_DECL(tcg, value) TCGv_i32 tcg = tcg_const_i32((value)) +#define __INSTR_ARG_I64_DECL(tcg, value) TCGv_i64 tcg = tcg_const_i64((value)) +#if TARGET_LONG_BITS == 64 +#define __INSTR_ARG_TUL_DECL(tcg, value) __INSTR_ARG_I64_DECL(tcg, value) +#define __INSTR_ARG_TCGv_i64_DECL(tcg, value) TCGv_i64 tcg = value +#else +#define __INSTR_ARG_TUL_DECL(tcg, value) __INSTR_ARG_I32_DECL(tcg, value) +#define __INSTR_ARG_TCGv_i32_DECL(tcg, value) TCGv_i32 tcg = value +#endif + +#define __INSTR_ARG_DECL(tcg, type, value) __INSTR_ARG_ ##type ##_DECL(tcg, value) + + +/* Free TCGv temporaries */ + +#define __INSTR_ARG_I32_FREE(tcg) tcg_temp_free_i32(tcg) +#define __INSTR_ARG_I64_FREE(tcg) tcg_temp_free_i64(tcg) +#if TARGET_LONG_BITS == 64 +#define __INSTR_ARG_TUL_FREE(tcg) __INSTR_ARG_I64_FREE(tcg) +#else +#define __INSTR_ARG_TUL_FREE(tcg) __INSTR_ARG_I32_FREE(tcg) +#endif +#define __INSTR_ARG_TCGv_i64_FREE(tcg) +#define __INSTR_ARG_TCGv_i32_FREE(tcg) +#define __INSTR_ARG_TCGv_FREE(tcg) + +#define __INSTR_ARG_FREE(tcg, type) __INSTR_ARG_ ##type ##_FREE(tcg) + +#endif /* INSTRUMENT__GENERATE_H */ diff --git a/instrument/types.h b/instrument/types.h new file mode 100644 index 0000000..eb4036b --- /dev/null +++ b/instrument/types.h @@ -0,0 +1,33 @@ +/* + * Static instrumentation data types. + * + * Copyright (c) 2010 Lluís Vilanova + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef INSTRUMENT__TYPES_H +#define INSTRUMENT__TYPES_H + +/** Instrumentation argument types. */ +typedef enum { + INSTR_ARG_I32, /**< immediate of 32bits */ + INSTR_ARG_I64, /**< immediate of 64bits */ + INSTR_ARG_TUL, /**< immediate target_ulong */ + INSTR_ARG_TCGv_i32, /**< 32-bit TCGv variable */ + INSTR_ARG_TCGv_i64, /**< 64-bit TCGv variable */ + INSTR_ARG_TCGv, /**< target-bit TCGv variable*/ +} instr_arg_type_t; + +#endif /* INSTRUMENT__TYPES_H */