From owner-svn-src-all@freebsd.org Fri Jan 17 17:03:26 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2E9BD1F4732; Fri, 17 Jan 2020 17:03:26 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47znSt04cZz3JP1; Fri, 17 Jan 2020 17:03:26 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D95CDC307; Fri, 17 Jan 2020 17:03:25 +0000 (UTC) (envelope-from mhorne@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00HH3PwJ055182; Fri, 17 Jan 2020 17:03:25 GMT (envelope-from mhorne@FreeBSD.org) Received: (from mhorne@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00HH3P52055181; Fri, 17 Jan 2020 17:03:25 GMT (envelope-from mhorne@FreeBSD.org) Message-Id: <202001171703.00HH3P52055181@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mhorne set sender to mhorne@FreeBSD.org using -f From: Mitchell Horne Date: Fri, 17 Jan 2020 17:03:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356835 - head/sys/riscv/riscv X-SVN-Group: head X-SVN-Commit-Author: mhorne X-SVN-Commit-Paths: head/sys/riscv/riscv X-SVN-Commit-Revision: 356835 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jan 2020 17:03:26 -0000 Author: mhorne Date: Fri Jan 17 17:03:25 2020 New Revision: 356835 URL: https://svnweb.freebsd.org/changeset/base/356835 Log: RISC-V: fix global pointer assignment at boot As part of the RISC-V ABI, the gp register is expected to initialized with the address of __global_pointer$ as early as possible. This allows loads and stores from .sdata to be relaxed based on the value of gp. In locore.S we do this initialization twice, once each for va and mpva. However, in both cases the initialization is preceded by an la instruction, which in theory could be relaxed by the linker. Move the initialization of gp to be slightly earlier (before la cpu_exception_handler), and add an additional gp initialization at the very beginning of _start, before virtual memory is set up. Reported by: jrtc27 Reviewed by: jrtc27 Differential Revision: https://reviews.freebsd.org/D23139 Modified: head/sys/riscv/riscv/locore.S Modified: head/sys/riscv/riscv/locore.S ============================================================================== --- head/sys/riscv/riscv/locore.S Fri Jan 17 16:48:20 2020 (r356834) +++ head/sys/riscv/riscv/locore.S Fri Jan 17 17:03:25 2020 (r356835) @@ -53,6 +53,12 @@ .text .globl _start _start: + /* Set the global pointer */ +.option push +.option norelax + lla gp, __global_pointer$ +.option pop + /* Get the physical address kernel loaded to */ lla t0, virt_map ld t1, 0(t0) @@ -168,6 +174,11 @@ _start: .align 2 va: + /* Set the global pointer again, this time with the virtual address. */ +.option push +.option norelax + lla gp, __global_pointer$ +.option pop /* Setup supervisor trap vector */ la t0, cpu_exception_handler @@ -177,12 +188,6 @@ va: li t0, 0 csrw sscratch, t0 - /* Set the global pointer */ -.option push -.option norelax - la gp, __global_pointer$ -.option pop - /* Initialize stack pointer */ la s3, initstack_end mv sp, s3 @@ -322,6 +327,12 @@ ENTRY(mpentry) .align 2 mpva: + /* Set the global pointer again, this time with the virtual address. */ +.option push +.option norelax + lla gp, __global_pointer$ +.option pop + /* Setup supervisor trap vector */ la t0, cpu_exception_handler csrw stvec, t0 @@ -329,12 +340,6 @@ mpva: /* Ensure sscratch is zero */ li t0, 0 csrw sscratch, t0 - - /* Set the global pointer */ -.option push -.option norelax - la gp, __global_pointer$ -.option pop call init_secondary END(mpentry)