Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp946545rdh; Sun, 24 Sep 2023 20:19:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7JQGXhT33UxRM5t/OyfuYyEDVSDOTDmNukgoBwxl2/hQ/2J3ODakmdQPlEDzuX6Dd5jDe X-Received: by 2002:a17:902:eb53:b0:1c3:df77:3159 with SMTP id i19-20020a170902eb5300b001c3df773159mr5795370pli.50.1695611996462; Sun, 24 Sep 2023 20:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695611996; cv=none; d=google.com; s=arc-20160816; b=DqrQ3UAUONvP7bHYpj6fX2jpgbR0RDahplM87E+TEuGZ/iAYYMK2MUkGlUcYW+nxk8 jTEvNbEF4Ao9Xx2nEbk3PfkbARmZHJZVuXR6hcN+1JmqipAH43czr18GNwJCmyl9Ikrn HQPvpW2IuMMAB3emilwz9/3nrCNkRXgsgVSRrbFD1hkOPl60e9aU8LLqdt/pQNAxpXpx xlC5rmJb00AtHGZAJlvVXNnGeMJFWuWrzyfP2qYM9zyeDYy1jZaVzSoNleivMmT2XMOe eWPUL+mzxIQI1HkYRZPkG0twG3EuUkXnPmDEGlQ0BZVBphXhW7Jphg2DWQH0sUtLsEkk zGqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date:dkim-signature; bh=Tun3obuVK7/qfAB+oJbmril64B5dSAF0AnmI6yjr2CE=; fh=5jGoFPLEUF4AB5jEnsonqDGemjBSSywww1e8yfvlFuo=; b=vzNFOvgogvg2iFrUN3TwnXnPgBUxZg8+AsagTS4NHdYJxhQZ039RTCVKD2bSj332Xv 9PUHLpw80oj7blE266ut9MtYJ1btmx2CeLLaTK0bAoFcQgRCJeSp8R546LxVJkpoi3Ug 6gQiolVpb6kKBp6bCIZdvWX+m5XXN0iGtSGEVhOduqL2xZVqsV6BD2PtJD9Y11mL+f4h 7wKrBHnqtd1Ax5jiNPGLHK+AW4MqQmzJU1w7Uf7c83juGYvwA5L2SdnwNGXrln3jqr2y 0xRFcGOe7VANzN2vjPQk7WTq0oN0OGQvyKBxYDa09ZVdATtUC6VSfPyzu+vHKHkG7ktr k2gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zvjUjFuB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id m7-20020a170902db0700b001bb3bcd05bbsi9475855plx.471.2023.09.24.20.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 20:19:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zvjUjFuB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id DFFAD819BB6E; Sun, 24 Sep 2023 20:19:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbjIYDTr (ORCPT + 99 others); Sun, 24 Sep 2023 23:19:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjIYDTp (ORCPT ); Sun, 24 Sep 2023 23:19:45 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37D7AA3 for ; Sun, 24 Sep 2023 20:19:39 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c60778a3bfso18499105ad.1 for ; Sun, 24 Sep 2023 20:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1695611978; x=1696216778; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Tun3obuVK7/qfAB+oJbmril64B5dSAF0AnmI6yjr2CE=; b=zvjUjFuBBHybX92Nzh3F0VOJ/HOrJ1qJ8w+TxdRo6+J6UIOyaon8lOyTo2QFb7STdT G2TtfhWw4Krn8GSs5MdV1BG3cehPm0kPHC7e3GJ3YykjdIo2OcTrRt9sSpxgvG95q9JW KUynJlDVAZ/4cojeMQJwOb2XwjrDQcd8Eb+1wTQ3PmJZEDxHqPySZvHrYgcxgktTnQjG o/MVTefNL0QseqjJ/BNiy75ODjDkRYIdPosB0RRBSug5K1/CK2Sx2VegVS6/nR2PrVwk VU1KEud86X9I4kdBBVgtuSwyeZUL/5S9+OKAo/32nug0+I58aZJM/1180zQOHlJ3T1os LqdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695611978; x=1696216778; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tun3obuVK7/qfAB+oJbmril64B5dSAF0AnmI6yjr2CE=; b=anSAfZtr81mcPUaz+IVCU01YiFp6N7S1vHayH3v7Y40jQhzFTx5D8GMY3PyjgLT/6n WHW712Xyt1tNGJu9FPh/S+nWmTYV3wK2mHMxLdIfT/8KsuE/P5gKjsgm0lgnNGFUvJ2y Ka3lQRVJfEueAzsu70tif3UGMsjaxyijPJ7+U/g2NdWCXklYwpgVnrA2tZK+mgDAhxN2 +HUhZXFxcR06RP2qPAXx1YC+DusI8lwP/SA3q338yluw0Cdbs01YdWOSvcK4byENvPqe fRT11dlzzO14NGHuRX/S7c9oQmVks4rzpHHod/3byntIerZWJEC8lZVsNJCOXL50ZKwN XXxQ== X-Gm-Message-State: AOJu0YxWxfI2zcfE66/W1yICKMBiq9zi5dox7LD7xAvX82bjHUfdroxF tlb89H5AdKFDJlQnAeOBspWUTQ== X-Received: by 2002:a17:902:cec1:b0:1c4:4dbc:92a3 with SMTP id d1-20020a170902cec100b001c44dbc92a3mr6737645plg.29.1695611978659; Sun, 24 Sep 2023 20:19:38 -0700 (PDT) Received: from ghost ([2601:647:5700:6860:ecfd:15f5:ab42:52dd]) by smtp.gmail.com with ESMTPSA id u6-20020a170902b28600b001c61acd5bd2sm934195plr.112.2023.09.24.20.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 20:19:38 -0700 (PDT) Date: Sun, 24 Sep 2023 20:19:35 -0700 From: Charlie Jenkins To: Andrew Jones , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Palmer Dabbelt , Jessica Clarke , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC] riscv: Script to autogenerate instruction handling code Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 24 Sep 2023 20:19:54 -0700 (PDT) I have heeded Andrew Jones' advice and written a script to generate the instruction handling code. It is still in development, but currently lives on a fork of riscv-opcodes [1]. I am interested if what I have produced so far is in line with what people would want to see. An insn.h file can be generated by running the following in the repo: make python3 parse_linux.py instr_dict.yaml insn.h opcodes_config variable_field_data.yaml I have pushed the generated files to the repo so people do not need to run the script. Each instruction has "variable fields" such as registers and immediates. For each variable field that appears in any provided instruction 3 functions are provided: extract a variable field from an instruction, insert a value into a variable field of an instruction, update a value into a variable field of an instruction. Update first clears the previous value of the variable field of the instruction. Then for each instruction, the script generates a function to check if an arbitrary 32-bit value matches the given instruction, and a function to generate the binary for the instruction given the required variable fields. I was able to use riscv-opcodes to parse the instruction files, but needed to create a new data structure in variable_field_data.py [2] which holds the positioning of immediates inside of an instruction. I envision that opcodes_config [3] would live inside of the kernel alongside a simple script to call riscv-opcodes (that resides somewhere in the user's file system) with appropriate parameters. When somebody wants to add a new instruction, they can add an instruction to opcodes_config, run the script, and commit the resulting generated file. If this script is in a direction that people like, I will continue to fix up the issues in it and try to get it upstreamed to riscv-opcodes before I send a kernel patch. - Charlie [1] https://github.com/charlie-rivos/riscv-opcodes/tree/linux_parsing [2] https://github.com/charlie-rivos/riscv-opcodes/blob/linux_parsing/variable_field_data.py [3] https://github.com/charlie-rivos/riscv-opcodes/blob/linux_parsing/opcodes_config