Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1096973rda; Mon, 23 Oct 2023 02:19:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGt7aQgd3HjghnN+aQezvjXZ4oaw0BxliRk+mXBwwMnPY2+AAcMmurtRC4YfSK0utvqADfV X-Received: by 2002:a17:90a:fa96:b0:27d:65:53e1 with SMTP id cu22-20020a17090afa9600b0027d006553e1mr5802336pjb.16.1698052793006; Mon, 23 Oct 2023 02:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698052792; cv=none; d=google.com; s=arc-20160816; b=jCcr/a93frSYATMQlGucxrQ+EVvZeWQQgyfLU6mP/eNcQC9JS4f3H47czgwupcPqLI Y8Z+eU3pva0zGtD4M1V0pnB2bODgrOfpVFzytuhiOg1z+ULfSNtiVg0TCjzJRcUGdbdw DX/90eMAbjQ/RBynr0MYQ+rvFDfJwTgiZfFDFWVTu5ufz2TlGB2it1T29AFXKb+sOEGG UQhtxtUTdc5mJXNW8v53Xj5x8CK5m8aHIKqDyJPuI7qrLPpzEPaX+WwzNRtMK6FL2DXN NJUkmQ5BRtLjF6jfnK/8SSz8zFq6ZJxuWOvng/65Jxv82rICzu2YfTuN70Si0Jbels9Z +EIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OCckZKiavm/5db1JMZXPnnv3QX7n6P10MPj5nZzGxrk=; fh=mH7kG5cT4eb/36WoRdhpunKmpt96WRoHbcvicvHt6uk=; b=ufGENh5ECVFHOAiOfg8msVVtnagHZDXYFWycAH4Ys7MNWVvhPmHv9i2cOl4qOb2RhD kPYyOX+fan12GcXhbCejqJr+6fIFywkjz4eUko+l1yG9kxj5HfxaGnwDOgaPMFrGWAV6 sdNPbb6hJZDIOzQqa7G28mIjXhYQB2FgWAXoE1lVvJGEGGaTKAnBqEzCEbE3n/t3Dvyp 8WbhyHraFmpIvL+e0znqtmalq6PnAf0OHRDRg773GAvlB15sPGl2XH7DetH1DEOYC/MQ MNgzi2UDngEBjdCgFzONJLvNhCdh9N8qN2osCvJ8pgdL/ta8Z60vmybpYDqfKTugeMlM dvxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=Ii1qYfDv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h7-20020a17090adb8700b0027da14d1513si5879374pjv.124.2023.10.23.02.19.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 02:19:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=Ii1qYfDv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 5E75E807C6FC; Mon, 23 Oct 2023 02:19:50 -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 S229662AbjJWJT3 (ORCPT + 99 others); Mon, 23 Oct 2023 05:19:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjJWJT2 (ORCPT ); Mon, 23 Oct 2023 05:19:28 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C6D498 for ; Mon, 23 Oct 2023 02:19:26 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9ba081173a3so483508666b.1 for ; Mon, 23 Oct 2023 02:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1698052765; x=1698657565; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OCckZKiavm/5db1JMZXPnnv3QX7n6P10MPj5nZzGxrk=; b=Ii1qYfDvi15GMKeUaSeeUqjFYUJzTENLWErugtqxuImbDnu/OZG0JWo1dUssb0pa66 buPQZlXlrAYfHDT1p/lnUssrcqYZCbwq7qsBCRMhIRr80ng2+S6RWMsQ04xtIHdjqRlZ QUaCJlgHTKfN+NpOiCfyLPPQzGikGQIwqmhxZTEFNgqOM6o4IDyHpc0LxCyPE6pEPds3 p24+gbStQZJANzL2Ow8nvov5fXFXmT6I5zF+q/XjKEEtuI3cwGsKJHLuTSH/nDNeYWZP qDqsKHDnPoBo9Kn8afewLqRmw8460du0JMexzORXj8g8TNn19JQlmU3tISVsUvQSrayq pK0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698052765; x=1698657565; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OCckZKiavm/5db1JMZXPnnv3QX7n6P10MPj5nZzGxrk=; b=ByE3wv4vbR5Jg7KfzghS0utsUpz7f3J3Onz2ZrsKveF29StYjKQQFitNLjzxWEOSlk ZvAxrdkLXB7WmXfs60hDYO3OD2bSLaIQvnbykMBZmaM598NmI3ZfXC+PB6Ijee0KFauQ /i20J23eqV8/J/h6SogsCXbnUVAU17+ktaqrSxJiS4I667OFgciqgWmpqQPmlKqCEEVH vRhXTmukPvxJioMRw53VMTn5veSVLmvGnyzIKTFo3y0SN4kWpQeU6K5man0vz/E9yByE DloxfC/6DFOh+nLP+xQTQJymGES2DGleHkvALHXK69asBCPLW6AB8RTmDwXkimdWYwhb TL/Q== X-Gm-Message-State: AOJu0YxwLrfWfDi/c3GgTsmo4SJ0z6P/RFTwfGs+GwodUyp/ho5A3v2y beWf6sltmrDDbWvbEv98NNuDrbgOmmbnx8SPNGo= X-Received: by 2002:a17:907:d86:b0:9be:b7da:72d6 with SMTP id go6-20020a1709070d8600b009beb7da72d6mr7079390ejc.63.1698052764885; Mon, 23 Oct 2023 02:19:24 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id y29-20020a170906519d00b009adc5802d08sm6411655ejk.190.2023.10.23.02.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 02:19:24 -0700 (PDT) Date: Mon, 23 Oct 2023 11:19:23 +0200 From: Andrew Jones To: Charlie Jenkins Cc: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , Palmer Dabbelt , Jessica Clarke , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFC] riscv: Script to autogenerate instruction handling code Message-ID: <20231023-aa3f789ccb483afbbdd55b38@orel> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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]); Mon, 23 Oct 2023 02:19:50 -0700 (PDT) On Sun, Sep 24, 2023 at 08:19:35PM -0700, Charlie Jenkins wrote: > 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. Hi Charlie, Sorry for my slow response. I'm glad to see that we're going in a direction where we generate these functions and reuse an existing generator to do it. > > 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. I couldn't find the generated files, not even [3] from your references seems to be present. > > 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. That sounds good to me. (They may hand craft the functions for a single instruction too, by just using the other functions as templates, but even if the script isn't used all the time in the future, the initial conversion of many instructions makes it worth while, IMO.) > > 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. Please send me a pointer to opcodes_config and insn.h. Also, since you're extending riscv-opcodes with variable_field_data.py, have you found a way to verify that all the immediate offsets are correct? Or were the offsets extracted from the spec/tool directly somehow? I.e. was variable_field_data.py mostly generated itself? Thanks, drew > > - 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