From owner-svn-src-head@freebsd.org Tue Jun 11 01:12:38 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 12D8E15CD833 for ; Tue, 11 Jun 2019 01:12:38 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound1a.eu.mailhop.org (outbound1a.eu.mailhop.org [52.58.109.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 799996DC55 for ; Tue, 11 Jun 2019 01:12:37 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1560215548; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=Ym1Tt5yH+EV9Pt1tbG7qPNFNPt7tzbDMchITprVXS5H5tapCXNELmEocyTjNiNLnMbs1HzdQgoJum Blt4+WN6dO0OHYGLcPB1awirfSbTZmaCtjoU9kOp98ksOYLLsJQdFBfvBr0vlSg81IE2U5deUCeGMQ nAStxNEW8JGjJ9Na8Y2XUu2xejAzpNwzlU9enhWwe3TyeDppsnOTPMZB4qIYHmf0RJ8W/IwOf9Xu1H 9TaaHyDwF1ZfNcG/iHHsYb1Rgwpqe+f2CwVmW4yOLFHzuzxK1tLFPzLs7tFGhX8Aypzt5a7ktjjugO 6CTR1xf6CjXGqbMqjD7nWhHVBYmoUyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:dkim-signature:from; bh=RsTgiujJ5CDWSP++YXep9SkfpdIK2wm7aIYbDjroQUU=; b=P7326O/1AMp0B/2/RInfEQNJKs29M8CIkV+vx3WDSbVYTJBTU9n51TZx7nJPR7dN5523i0ZExnlHB C2NcZmTQ4mZBPP2OdFNL4ovYbEQJdwWqVmIv6EaOmv5zU71NhAKBIGawUMeJNX/BQfuWDFQ+SDo0mJ MNM8QNwtlPtKAm1F/TCbcm/M2NifEJXxSVpxZ6/939m6yDFfnX0Ae04EmqDn16fRFqMrrgIptvmufn 9X+UBSP0GO6V+hGhptGOZcktcM4AepfZsrBj0up1ceI8i5NPo8ginPdTF3GYz8YndF59rN4/c53+ZF rHIPr0VhwpXXQXY5HdxSrNdfAjbp02g== ARC-Authentication-Results: i=1; outbound2.eu.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:from; bh=RsTgiujJ5CDWSP++YXep9SkfpdIK2wm7aIYbDjroQUU=; b=Vx4r4fHCrXl7fXwpiVFdy12E8VLDQYovsZ4TZoX88JQ0xrJBOZjeJ1HE+I/S1p1z6SbQVlxzri67F Y/k7H3f6iX8h2OhUhxOIz/IMgj1AmqE/nf1yeeAFv2nTG4uznioELxDSVcGC1hgWhrvq1aOotoFVoT MOJMsSgP+NOEJtJfBGPSpo9qmqwACKWtQroWxOPUh24UBx63dQKCogbDazqM7WuMSH83jUlB15Fkpq A5YObFDCZ62wIv7l5pHM2WqVIxqphKIa5QacLoLg1sQmJDiIPjw4SiQtTxogNEl7gjBGtb6f43p3LT p6NsCSTpgf6Au5VDD9pQoeyV8XvONXw== X-MHO-RoutePath: aGlwcGll X-MHO-User: f8c2858d-8be5-11e9-85c6-c97e5c048ed3 X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 67.177.211.60 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (unknown [67.177.211.60]) by outbound2.eu.mailhop.org (Halon) with ESMTPSA id f8c2858d-8be5-11e9-85c6-c97e5c048ed3; Tue, 11 Jun 2019 01:12:26 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id x5B1COPC086507; Mon, 10 Jun 2019 19:12:24 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: Subject: Re: svn commit: r348886 - in head/sys/riscv: include riscv From: Ian Lepore To: Mitchell Horne , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Date: Mon, 10 Jun 2019 19:12:24 -0600 In-Reply-To: <201906110055.x5B0tsOM089231@repo.freebsd.org> References: <201906110055.x5B0tsOM089231@repo.freebsd.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 799996DC55 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.99 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.986,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jun 2019 01:12:38 -0000 On Tue, 2019-06-11 at 00:55 +0000, Mitchell Horne wrote: > Author: mhorne > Date: Tue Jun 11 00:55:54 2019 > New Revision: 348886 > URL: https://svnweb.freebsd.org/changeset/base/348886 > > Log: > RISC-V: expose extension bits in AT_HWCAP > > AT_HWCAP is a field in the elf auxiliary vector meant to describe > cpu-specific hardware features. For RISC-V we want to use this to > indicate the presence of any standard extensions supported by the > CPU. > This allows userland applications to query the system for supported > extensions using elf_aux_info(3). > > Support for an extension is indicated by the presence of its > corresponding bit in AT_HWCAP -- e.g. systems supporting the 'c' > extension (compressed instructions) will have the second bit set. > > Extensions advertised through AT_HWCAP are only those that are > supported > by all harts in the system. > A word of advice from the arm world (a don't make the mistakes we did kind of thing): If linux has already defined AT_HWCAP values for riscv, life may be better in the long run if our values match theirs as much as possible. It will especially help with ports. -- Ian > Reviewed by: jhb, markj > Approved by: markj (mentor) > MFC after: 2 weeks > Differential Revision: https://reviews.freebsd.org/D20493 > > Modified: > head/sys/riscv/include/elf.h > head/sys/riscv/include/md_var.h > head/sys/riscv/riscv/elf_machdep.c > head/sys/riscv/riscv/identcpu.c > > Modified: head/sys/riscv/include/elf.h > ===================================================================== > ========= > --- head/sys/riscv/include/elf.h Mon Jun 10 23:25:40 2019 (r348 > 885) > +++ head/sys/riscv/include/elf.h Tue Jun 11 00:55:54 2019 (r348 > 886) > @@ -74,4 +74,15 @@ __ElfType(Auxinfo); > /* TODO: set correct value */ > #define ET_DYN_LOAD_ADDR 0x100000 > > +/* Flags passed in AT_HWCAP */ > +#define HWCAP_ISA_BIT(c) (1 << ((c) - 'A')) > +#define HWCAP_ISA_I HWCAP_ISA_BIT('I') > +#define HWCAP_ISA_M HWCAP_ISA_BIT('M') > +#define HWCAP_ISA_A HWCAP_ISA_BIT('A') > +#define HWCAP_ISA_F HWCAP_ISA_BIT('F') > +#define HWCAP_ISA_D HWCAP_ISA_BIT('D') > +#define HWCAP_ISA_C HWCAP_ISA_BIT('C') > +#define HWCAP_ISA_G \ > + (HWCAP_ISA_I | HWCAP_ISA_M | HWCAP_ISA_A | HWCAP_ISA_F | > HWCAP_ISA_D) > + > #endif /* !_MACHINE_ELF_H_ */ > > Modified: head/sys/riscv/include/md_var.h > ===================================================================== > ========= > --- head/sys/riscv/include/md_var.h Mon Jun 10 23:25:40 2019 (r348 > 885) > +++ head/sys/riscv/include/md_var.h Tue Jun 11 00:55:54 2019 (r348 > 886) > @@ -38,6 +38,7 @@ extern char sigcode[]; > extern int szsigcode; > extern uint64_t *vm_page_dump; > extern int vm_page_dump_size; > +extern u_long elf_hwcap; > > struct dumperinfo; > > > Modified: head/sys/riscv/riscv/elf_machdep.c > ===================================================================== > ========= > --- head/sys/riscv/riscv/elf_machdep.c Mon Jun 10 23:25:40 > 2019 (r348885) > +++ head/sys/riscv/riscv/elf_machdep.c Tue Jun 11 00:55:54 > 2019 (r348886) > @@ -58,6 +58,8 @@ __FBSDID("$FreeBSD$"); > #include > #include > > +u_long elf_hwcap; > + > struct sysentvec elf64_freebsd_sysvec = { > .sv_size = SYS_MAXSYSCALL, > .sv_table = sysent, > @@ -90,6 +92,7 @@ struct sysentvec elf64_freebsd_sysvec = { > .sv_schedtail = NULL, > .sv_thread_detach = NULL, > .sv_trap = NULL, > + .sv_hwcap = &elf_hwcap, > }; > INIT_SYSENTVEC(elf64_sysvec, &elf64_freebsd_sysvec); > > > Modified: head/sys/riscv/riscv/identcpu.c > ===================================================================== > ========= > --- head/sys/riscv/riscv/identcpu.c Mon Jun 10 23:25:40 2019 (r348 > 885) > +++ head/sys/riscv/riscv/identcpu.c Tue Jun 11 00:55:54 2019 (r348 > 886) > @@ -32,18 +32,28 @@ > * SUCH DAMAGE. > */ > > +#include "opt_platform.h" > + > #include > __FBSDID("$FreeBSD$"); > > #include > +#include > +#include > #include > #include > -#include > > #include > #include > +#include > +#include > #include > > +#ifdef FDT > +#include > +#include > +#endif > + > char machine[] = "riscv"; > > SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, > @@ -87,6 +97,84 @@ const struct cpu_implementers cpu_implementers[] = > { > { CPU_IMPL_UCB_ROCKET, "UC Berkeley Rocket" }, > CPU_IMPLEMENTER_NONE, > }; > + > +#ifdef FDT > +/* > + * The ISA string is made up of a small prefix (e.g. rv64) and up to > 26 letters > + * indicating the presence of the 26 possible standard extensions. > Therefore 32 > + * characters will be sufficient. > + */ > +#define ISA_NAME_MAXLEN 32 > +#define ISA_PREFIX ("rv" > __XSTRING(__riscv_xlen)) > +#define ISA_PREFIX_LEN (sizeof(ISA_PREFIX) - 1) > + > +static void > +fill_elf_hwcap(void *dummy __unused) > +{ > + u_long caps[256] = {0}; > + char isa[ISA_NAME_MAXLEN]; > + u_long hwcap; > + phandle_t node; > + ssize_t len; > + int i; > + > + caps['i'] = caps['I'] = HWCAP_ISA_I; > + caps['m'] = caps['M'] = HWCAP_ISA_M; > + caps['a'] = caps['A'] = HWCAP_ISA_A; > +#ifdef FPE > + caps['f'] = caps['F'] = HWCAP_ISA_F; > + caps['d'] = caps['D'] = HWCAP_ISA_D; > +#endif > + caps['c'] = caps['C'] = HWCAP_ISA_C; > + > + node = OF_finddevice("/cpus"); > + if (node == -1) { > + if (bootverbose) > + printf("fill_elf_hwcap: Can't find cpus > node\n"); > + return; > + } > + > + /* > + * Iterate through the CPUs and examine their ISA string. While > we > + * could assign elf_hwcap to be whatever the boot CPU supports, > to > + * handle the (unusual) case of running a system with > hetergeneous > + * ISAs, keep only the extension bits that are common to all > harts. > + */ > + for (node = OF_child(node); node > 0; node = OF_peer(node)) { > + if (!fdt_is_compatible_strict(node, "riscv")) { > + if (bootverbose) > + printf("fill_elf_hwcap: Can't find > cpu\n"); > + return; > + } > + > + len = OF_getprop(node, "riscv,isa", isa, sizeof(isa)); > + KASSERT(len <= ISA_NAME_MAXLEN, ("ISA string > truncated")); > + if (len == -1) { > + if (bootverbose) > + printf("fill_elf_hwcap: " > + "Can't find riscv,isa property\n"); > + return; > + } else if (strncmp(isa, ISA_PREFIX, ISA_PREFIX_LEN) != > 0) { > + if (bootverbose) > + printf("fill_elf_hwcap: " > + "Unsupported ISA string: %s\n", > isa); > + return; > + } > + > + hwcap = 0; > + for (i = ISA_PREFIX_LEN; i < len; i++) > + hwcap |= caps[(unsigned char)isa[i]]; > + > + if (elf_hwcap != 0) > + elf_hwcap &= hwcap; > + else > + elf_hwcap = hwcap; > + > + } > +} > + > +SYSINIT(identcpu, SI_SUB_CPU, SI_ORDER_ANY, fill_elf_hwcap, NULL); > +#endif > > void > identify_cpu(void) >