Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/810695/?format=api
{ "id": 810695, "url": "http://patchwork.ozlabs.org/api/1.2/patches/810695/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170906160612.22769-7-richard.henderson@linaro.org/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/1.2/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170906160612.22769-7-richard.henderson@linaro.org>", "list_archive_url": null, "date": "2017-09-06T16:05:46", "name": "[PULL,06/32] tcg: Add generic translation framework", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "50f141754f7d374b13710c90c97ae626e0264401", "submitter": { "id": 72104, "url": "http://patchwork.ozlabs.org/api/1.2/people/72104/?format=api", "name": "Richard Henderson", "email": "richard.henderson@linaro.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170906160612.22769-7-richard.henderson@linaro.org/mbox/", "series": [ { "id": 1847, "url": "http://patchwork.ozlabs.org/api/1.2/series/1847/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=1847", "date": "2017-09-06T16:05:41", "name": "[PULL,01/32] tcg: Add generic DISAS_NORETURN", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/1847/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/810695/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/810695/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)", "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"aabH3fkf\"; dkim-atps=neutral" ], "Received": [ "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnT7Y0mjkz9s7c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 7 Sep 2017 02:10:00 +1000 (AEST)", "from localhost ([::1]:36965 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dpctp-0002Vj-LT\n\tfor incoming@patchwork.ozlabs.org; Wed, 06 Sep 2017 12:09:57 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:41578)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <richard.henderson@linaro.org>) id 1dpcqP-0008Mb-NW\n\tfor qemu-devel@nongnu.org; Wed, 06 Sep 2017 12:06:32 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <richard.henderson@linaro.org>) id 1dpcqO-0001hB-3O\n\tfor qemu-devel@nongnu.org; Wed, 06 Sep 2017 12:06:25 -0400", "from mail-pg0-x229.google.com ([2607:f8b0:400e:c05::229]:37870)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <richard.henderson@linaro.org>)\n\tid 1dpcqN-0001gn-R4\n\tfor qemu-devel@nongnu.org; Wed, 06 Sep 2017 12:06:24 -0400", "by mail-pg0-x229.google.com with SMTP id d8so15974014pgt.4\n\tfor <qemu-devel@nongnu.org>; Wed, 06 Sep 2017 09:06:23 -0700 (PDT)", "from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net.\n\t[97.126.108.236]) by smtp.gmail.com with ESMTPSA id\n\tt65sm262863pfk.59.2017.09.06.09.06.21\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 06 Sep 2017 09:06:21 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=R62/TouQaAsAwTFblPipbaD9zB1SKMXzhPWYt2bTtDQ=;\n\tb=aabH3fkfUYAsgy0ADf21qgP0VeVLYh4acSwqNWnLDP4uH0Qko4XonddyxNLaqFBRWx\n\tO4i1BEWQAPodQXYoiA5YVdDSLhnCCWEhphNo9Zkjma9SbwiFjHZ8SlizVHaqD14sRTcn\n\tuSYOp0NttRFBp6sJ+tijeI84Gy5J3zs0j7exw=", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=R62/TouQaAsAwTFblPipbaD9zB1SKMXzhPWYt2bTtDQ=;\n\tb=WhIQlQqgWc/DyEmKp5ulT6owpeT8V+XN9WV5hKF4eNKaZxipSNDWICc157ipXPIkDI\n\t1DSh7B+RBrwTyJE8KmP7Xz0AMOhW703bFUR2GrjJYp9gbmrUzfSettZbmi6ocvppgc5V\n\tm9iUMkcDI2qEimBlQu0N8EyhXYbRcACmErzfiU/93Xx0TCppZ/4vKVDw+azhpnNJYSTW\n\trtcSNhtZSuICg+9cxUx7QpkqLgz9ofjDVHDXmUPhV4DBq5nKTwrEDudw/9qyzksAzYA6\n\taNJRgzbKZzI+dL7pvWyKG4IfIsx4KDWXiXD4IDEMrZXiPuPHFzOltVcDv2uNQYSdAMyM\n\tNJAw==", "X-Gm-Message-State": "AHPjjUjdow4VYFlxn7w8ealy8IL8axnoQMH64nKWRoCskbLQtdOQRKgQ\n\tbDFX1+Ut/XxuqoAXBVmI7Q==", "X-Google-Smtp-Source": "ADKCNb6xEgj9vjQ9h1pbonaEngW9HkjJK1+Z3w8CmoFrSRSLXuUTqxhZOAk+DO2smRx35aZcz8ey0g==", "X-Received": "by 10.101.66.139 with SMTP id j11mr8237803pgp.132.1504713982443; \n\tWed, 06 Sep 2017 09:06:22 -0700 (PDT)", "From": "Richard Henderson <richard.henderson@linaro.org>", "To": "qemu-devel@nongnu.org", "Date": "Wed, 6 Sep 2017 09:05:46 -0700", "Message-Id": "<20170906160612.22769-7-richard.henderson@linaro.org>", "X-Mailer": "git-send-email 2.13.5", "In-Reply-To": "<20170906160612.22769-1-richard.henderson@linaro.org>", "References": "<20170906160612.22769-1-richard.henderson@linaro.org>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.", "X-Received-From": "2607:f8b0:400e:c05::229", "Subject": "[Qemu-devel] [PULL 06/32] tcg: Add generic translation framework", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.21", "Precedence": "list", "List-Id": "<qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Cc": "peter.maydell@linaro.org, =?utf-8?q?Llu=C3=ADs_Vilanova?=\n\t<vilanova@ac.upc.edu>, \tRichard Henderson <rth@twiddle.net>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>" }, "content": "From: Lluís Vilanova <vilanova@ac.upc.edu>\n\nReviewed-by: Emilio G. Cota <cota@braap.org>\nSigned-off-by: Lluís Vilanova <vilanova@ac.upc.edu>\nMessage-Id: <150002073981.22386.9870422422367410100.stgit@frigg.lan>\n[rth: Moved max_insns adjustment from tb_start to init_disas_context.\nRemoved pc_next return from translate_insn.\nRemoved tcg_check_temp_count from generic loop.\nMoved gen_io_end to exactly match gen_io_start.\nUse qemu_log instead of error_report for temporary leaks.\nMoved TB size/icount assignments before disas_log.]\nSigned-off-by: Richard Henderson <rth@twiddle.net>\n---\n include/exec/translator.h | 104 ++++++++++++++++++++++++++++++++++\n accel/tcg/translator.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++\n accel/tcg/Makefile.objs | 1 +\n 3 files changed, 243 insertions(+)\n create mode 100644 accel/tcg/translator.c", "diff": "diff --git a/include/exec/translator.h b/include/exec/translator.h\nindex b51b8f8a4e..e2dc2a04ae 100644\n--- a/include/exec/translator.h\n+++ b/include/exec/translator.h\n@@ -10,6 +10,19 @@\n #ifndef EXEC__TRANSLATOR_H\n #define EXEC__TRANSLATOR_H\n \n+/*\n+ * Include this header from a target-specific file, and add a\n+ *\n+ * DisasContextBase base;\n+ *\n+ * member in your target-specific DisasContext.\n+ */\n+\n+\n+#include \"exec/exec-all.h\"\n+#include \"tcg/tcg.h\"\n+\n+\n /**\n * DisasJumpType:\n * @DISAS_NEXT: Next instruction in program order.\n@@ -37,4 +50,95 @@ typedef enum DisasJumpType {\n DISAS_TARGET_11,\n } DisasJumpType;\n \n+/**\n+ * DisasContextBase:\n+ * @tb: Translation block for this disassembly.\n+ * @pc_first: Address of first guest instruction in this TB.\n+ * @pc_next: Address of next guest instruction in this TB (current during\n+ * disassembly).\n+ * @is_jmp: What instruction to disassemble next.\n+ * @num_insns: Number of translated instructions (including current).\n+ * @singlestep_enabled: \"Hardware\" single stepping enabled.\n+ *\n+ * Architecture-agnostic disassembly context.\n+ */\n+typedef struct DisasContextBase {\n+ TranslationBlock *tb;\n+ target_ulong pc_first;\n+ target_ulong pc_next;\n+ DisasJumpType is_jmp;\n+ unsigned int num_insns;\n+ bool singlestep_enabled;\n+} DisasContextBase;\n+\n+/**\n+ * TranslatorOps:\n+ * @init_disas_context:\n+ * Initialize the target-specific portions of DisasContext struct.\n+ * The generic DisasContextBase has already been initialized.\n+ * Return max_insns, modified as necessary by db->tb->flags.\n+ *\n+ * @tb_start:\n+ * Emit any code required before the start of the main loop,\n+ * after the generic gen_tb_start().\n+ *\n+ * @insn_start:\n+ * Emit the tcg_gen_insn_start opcode.\n+ *\n+ * @breakpoint_check:\n+ * When called, the breakpoint has already been checked to match the PC,\n+ * but the target may decide the breakpoint missed the address\n+ * (e.g., due to conditions encoded in their flags). Return true to\n+ * indicate that the breakpoint did hit, in which case no more breakpoints\n+ * are checked. If the breakpoint did hit, emit any code required to\n+ * signal the exception, and set db->is_jmp as necessary to terminate\n+ * the main loop.\n+ *\n+ * @translate_insn:\n+ * Disassemble one instruction and set db->pc_next for the start\n+ * of the following instruction. Set db->is_jmp as necessary to\n+ * terminate the main loop.\n+ *\n+ * @tb_stop:\n+ * Emit any opcodes required to exit the TB, based on db->is_jmp.\n+ *\n+ * @disas_log:\n+ * Print instruction disassembly to log.\n+ */\n+typedef struct TranslatorOps {\n+ int (*init_disas_context)(DisasContextBase *db, CPUState *cpu,\n+ int max_insns);\n+ void (*tb_start)(DisasContextBase *db, CPUState *cpu);\n+ void (*insn_start)(DisasContextBase *db, CPUState *cpu);\n+ bool (*breakpoint_check)(DisasContextBase *db, CPUState *cpu,\n+ const CPUBreakpoint *bp);\n+ void (*translate_insn)(DisasContextBase *db, CPUState *cpu);\n+ void (*tb_stop)(DisasContextBase *db, CPUState *cpu);\n+ void (*disas_log)(const DisasContextBase *db, CPUState *cpu);\n+} TranslatorOps;\n+\n+/**\n+ * translator_loop:\n+ * @ops: Target-specific operations.\n+ * @db: Disassembly context.\n+ * @cpu: Target vCPU.\n+ * @tb: Translation block.\n+ *\n+ * Generic translator loop.\n+ *\n+ * Translation will stop in the following cases (in order):\n+ * - When is_jmp set by #TranslatorOps::breakpoint_check.\n+ * - set to DISAS_TOO_MANY exits after translating one more insn\n+ * - set to any other value than DISAS_NEXT exits immediately.\n+ * - When is_jmp set by #TranslatorOps::translate_insn.\n+ * - set to any value other than DISAS_NEXT exits immediately.\n+ * - When the TCG operation buffer is full.\n+ * - When single-stepping is enabled (system-wide or on the current vCPU).\n+ * - When too many instructions have been translated.\n+ */\n+void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n+ CPUState *cpu, TranslationBlock *tb);\n+\n+void translator_loop_temp_check(DisasContextBase *db);\n+\n #endif /* EXEC__TRANSLATOR_H */\ndiff --git a/accel/tcg/translator.c b/accel/tcg/translator.c\nnew file mode 100644\nindex 0000000000..afa3af478a\n--- /dev/null\n+++ b/accel/tcg/translator.c\n@@ -0,0 +1,138 @@\n+/*\n+ * Generic intermediate code generation.\n+ *\n+ * Copyright (C) 2016-2017 Lluís Vilanova <vilanova@ac.upc.edu>\n+ *\n+ * This work is licensed under the terms of the GNU GPL, version 2 or later.\n+ * See the COPYING file in the top-level directory.\n+ */\n+\n+#include \"qemu/osdep.h\"\n+#include \"qemu-common.h\"\n+#include \"qemu/error-report.h\"\n+#include \"cpu.h\"\n+#include \"tcg/tcg.h\"\n+#include \"tcg/tcg-op.h\"\n+#include \"exec/exec-all.h\"\n+#include \"exec/gen-icount.h\"\n+#include \"exec/log.h\"\n+#include \"exec/translator.h\"\n+\n+/* Pairs with tcg_clear_temp_count.\n+ To be called by #TranslatorOps.{translate_insn,tb_stop} if\n+ (1) the target is sufficiently clean to support reporting,\n+ (2) as and when all temporaries are known to be consumed.\n+ For most targets, (2) is at the end of translate_insn. */\n+void translator_loop_temp_check(DisasContextBase *db)\n+{\n+ if (tcg_check_temp_count()) {\n+ qemu_log(\"warning: TCG temporary leaks before \"\n+ TARGET_FMT_lx \"\\n\", db->pc_next);\n+ }\n+}\n+\n+void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n+ CPUState *cpu, TranslationBlock *tb)\n+{\n+ int max_insns;\n+\n+ /* Initialize DisasContext */\n+ db->tb = tb;\n+ db->pc_first = tb->pc;\n+ db->pc_next = db->pc_first;\n+ db->is_jmp = DISAS_NEXT;\n+ db->num_insns = 0;\n+ db->singlestep_enabled = cpu->singlestep_enabled;\n+\n+ /* Instruction counting */\n+ max_insns = db->tb->cflags & CF_COUNT_MASK;\n+ if (max_insns == 0) {\n+ max_insns = CF_COUNT_MASK;\n+ }\n+ if (max_insns > TCG_MAX_INSNS) {\n+ max_insns = TCG_MAX_INSNS;\n+ }\n+ if (db->singlestep_enabled || singlestep) {\n+ max_insns = 1;\n+ }\n+\n+ max_insns = ops->init_disas_context(db, cpu, max_insns);\n+ tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */\n+\n+ /* Reset the temp count so that we can identify leaks */\n+ tcg_clear_temp_count();\n+\n+ /* Start translating. */\n+ gen_tb_start(db->tb);\n+ ops->tb_start(db, cpu);\n+ tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */\n+\n+ while (true) {\n+ db->num_insns++;\n+ ops->insn_start(db, cpu);\n+ tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */\n+\n+ /* Pass breakpoint hits to target for further processing */\n+ if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {\n+ CPUBreakpoint *bp;\n+ QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {\n+ if (bp->pc == db->pc_next) {\n+ if (ops->breakpoint_check(db, cpu, bp)) {\n+ break;\n+ }\n+ }\n+ }\n+ /* The breakpoint_check hook may use DISAS_TOO_MANY to indicate\n+ that only one more instruction is to be executed. Otherwise\n+ it should use DISAS_NORETURN when generating an exception,\n+ but may use a DISAS_TARGET_* value for Something Else. */\n+ if (db->is_jmp > DISAS_TOO_MANY) {\n+ break;\n+ }\n+ }\n+\n+ /* Disassemble one instruction. The translate_insn hook should\n+ update db->pc_next and db->is_jmp to indicate what should be\n+ done next -- either exiting this loop or locate the start of\n+ the next instruction. */\n+ if (db->num_insns == max_insns && (db->tb->cflags & CF_LAST_IO)) {\n+ /* Accept I/O on the last instruction. */\n+ gen_io_start();\n+ ops->translate_insn(db, cpu);\n+ gen_io_end();\n+ } else {\n+ ops->translate_insn(db, cpu);\n+ }\n+\n+ /* Stop translation if translate_insn so indicated. */\n+ if (db->is_jmp != DISAS_NEXT) {\n+ break;\n+ }\n+\n+ /* Stop translation if the output buffer is full,\n+ or we have executed all of the allowed instructions. */\n+ if (tcg_op_buf_full() || db->num_insns >= max_insns) {\n+ db->is_jmp = DISAS_TOO_MANY;\n+ break;\n+ }\n+ }\n+\n+ /* Emit code to exit the TB, as indicated by db->is_jmp. */\n+ ops->tb_stop(db, cpu);\n+ gen_tb_end(db->tb, db->num_insns);\n+\n+ /* The disas_log hook may use these values rather than recompute. */\n+ db->tb->size = db->pc_next - db->pc_first;\n+ db->tb->icount = db->num_insns;\n+\n+#ifdef DEBUG_DISAS\n+ if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)\n+ && qemu_log_in_addr_range(db->pc_first)) {\n+ qemu_log_lock();\n+ qemu_log(\"----------------\\n\");\n+ ops->disas_log(db, cpu);\n+ qemu_log(\"\\n\");\n+ qemu_log_unlock();\n+ }\n+#endif\n+}\ndiff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs\nindex 70cd474c01..22642e6f75 100644\n--- a/accel/tcg/Makefile.objs\n+++ b/accel/tcg/Makefile.objs\n@@ -1,3 +1,4 @@\n obj-$(CONFIG_SOFTMMU) += tcg-all.o\n obj-$(CONFIG_SOFTMMU) += cputlb.o\n obj-y += cpu-exec.o cpu-exec-common.o translate-all.o\n+obj-y += translator.o\n", "prefixes": [ "PULL", "06/32" ] }