From owner-svn-src-all@freebsd.org Mon Jun 8 17:51:47 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 2AF083369F0; Mon, 8 Jun 2020 17:51:47 +0000 (UTC) (envelope-from mhorne@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49ggmg0Ncsz47b3; Mon, 8 Jun 2020 17:51:47 +0000 (UTC) (envelope-from mhorne@freebsd.org) Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) (Authenticated sender: mhorne) by smtp.freebsd.org (Postfix) with ESMTPSA id 0802E1DDBF; Mon, 8 Jun 2020 17:51:47 +0000 (UTC) (envelope-from mhorne@freebsd.org) Received: by mail-yb1-f181.google.com with SMTP id t9so9653392ybk.9; Mon, 08 Jun 2020 10:51:47 -0700 (PDT) X-Gm-Message-State: AOAM530cxVTC7CdSAjMfmcdhN8ixfmcvG532L1nmnVhx0sgL3smcROLZ Bzii1dWnaIrRv1yCmsyVEiPe9lmu5kIXUtkFYgA= X-Google-Smtp-Source: ABdhPJyKqb7qZbQknANyaSXA/JJkWO8wSzkj82w5CRQoip5x109lhc7+s/HDCye3nRfNqbTNGDgBMTJDOruntWm4OPw= X-Received: by 2002:a25:b315:: with SMTP id l21mr41470977ybj.214.1591638706459; Mon, 08 Jun 2020 10:51:46 -0700 (PDT) MIME-Version: 1.0 References: <202005281456.04SEuBkO025187@repo.freebsd.org> In-Reply-To: <202005281456.04SEuBkO025187@repo.freebsd.org> From: Mitchell Horne Date: Mon, 8 Jun 2020 14:51:35 -0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r361587 - in head/sys/riscv: include riscv To: src-committers@freebsd.org Cc: svn-src-all@freebsd.org, svn-src-head@freebsd.org, rpokala@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 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: Mon, 08 Jun 2020 17:51:47 -0000 On Thu, May 28, 2020 at 11:56 AM Mitchell Horne wrote: > > Author: mhorne > Date: Thu May 28 14:56:11 2020 > New Revision: 361587 > URL: https://svnweb.freebsd.org/changeset/base/361587 > > Log: > Add macros simplifying the fake preload setup > > This is in preparation for booting via loader(8). Lift these macros from arm64 > so we don't need to worry about the size when inserting new elements. This > could have been done in r359673, but I didn't think I would be returning to > this function so soon. > > Reviewed by: markj > Differential Revision: https://reviews.freebsd.org/D24910 > > Modified: > head/sys/riscv/include/vmparam.h > head/sys/riscv/riscv/machdep.c > > Modified: head/sys/riscv/include/vmparam.h > ============================================================================== > --- head/sys/riscv/include/vmparam.h Thu May 28 13:48:33 2020 (r361586) > +++ head/sys/riscv/include/vmparam.h Thu May 28 14:56:11 2020 (r361587) > @@ -190,8 +190,6 @@ > #define SHAREDPAGE (VM_MAXUSER_ADDRESS - PAGE_SIZE) > #define USRSTACK SHAREDPAGE > > -#define KERNENTRY (0) > - > #define VM_EARLY_DTB_ADDRESS (VM_MAX_KERNEL_ADDRESS - (2 * L2_SIZE)) > > /* > > Modified: head/sys/riscv/riscv/machdep.c > ============================================================================== > --- head/sys/riscv/riscv/machdep.c Thu May 28 13:48:33 2020 (r361586) > +++ head/sys/riscv/riscv/machdep.c Thu May 28 14:56:11 2020 (r361587) > @@ -733,29 +733,36 @@ fake_preload_metadata(struct riscv_bootparams *rvbp) > vm_offset_t zstart = 0, zend = 0; > #endif > vm_offset_t lastaddr; > - size_t dtb_size; > - int i; > + size_t fake_size, dtb_size; > > - i = 0; > +#define PRELOAD_PUSH_VALUE(type, value) do { \ > + *(type *)((char *)fake_preload + fake_size) = (value); \ > + fake_size += sizeof(type); \ > +} while (0) > > - fake_preload[i++] = MODINFO_NAME; > - fake_preload[i++] = strlen("kernel") + 1; > - strcpy((char*)&fake_preload[i++], "kernel"); > - i += 1; > - fake_preload[i++] = MODINFO_TYPE; > - fake_preload[i++] = strlen("elf64 kernel") + 1; > - strcpy((char*)&fake_preload[i++], "elf64 kernel"); > - i += 3; > - fake_preload[i++] = MODINFO_ADDR; > - fake_preload[i++] = sizeof(vm_offset_t); > - *(vm_offset_t *)&fake_preload[i++] = > - (vm_offset_t)(KERNBASE + KERNENTRY); > - i += 1; > - fake_preload[i++] = MODINFO_SIZE; > - fake_preload[i++] = sizeof(vm_offset_t); > - fake_preload[i++] = (vm_offset_t)&end - > - (vm_offset_t)(KERNBASE + KERNENTRY); > - i += 1; > +#define PRELOAD_PUSH_STRING(str) do { \ > + uint32_t ssize; \ > + ssize = strlen(str) + 1; \ > + PRELOAD_PUSH_VALUE(uint32_t, ssize); \ > + strcpy(((char *)fake_preload + fake_size), str); \ > + fake_size += ssize; \ > + fake_size = roundup(fake_size, sizeof(u_long)); \ > +} while (0) > + > + fake_size = 0; > + > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_NAME); > + PRELOAD_PUSH_STRING("kernel"); > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_TYPE); > + PRELOAD_PUSH_STRING("elf kernel"); Note that the type here was unintentionally changed from "elf64 kernel" to "elf kernel". Fortunately, this ends up being more consistent with both loader(8) and the other fake_preload_metadata routines, which set the type as "elf kernel". Thanks to rpokala@ for pointing this out. > + > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_ADDR); > + PRELOAD_PUSH_VALUE(uint32_t, sizeof(vm_offset_t)); > + PRELOAD_PUSH_VALUE(uint64_t, KERNBASE); > + > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_SIZE); > + PRELOAD_PUSH_VALUE(uint32_t, sizeof(size_t)); > + PRELOAD_PUSH_VALUE(uint64_t, (size_t)((vm_offset_t)&end - KERNBASE)); > #ifdef DDB > #if 0 > /* RISCVTODO */ > @@ -777,19 +784,20 @@ fake_preload_metadata(struct riscv_bootparams *rvbp) > > /* Copy the DTB to KVA space. */ > lastaddr = roundup(lastaddr, sizeof(int)); > - fake_preload[i++] = MODINFO_METADATA | MODINFOMD_DTBP; > - fake_preload[i++] = sizeof(vm_offset_t); > - *(vm_offset_t *)&fake_preload[i] = (vm_offset_t)lastaddr; > - i += sizeof(vm_offset_t) / sizeof(uint32_t); > + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_METADATA | MODINFOMD_DTBP); > + PRELOAD_PUSH_VALUE(uint32_t, sizeof(vm_offset_t)); > + PRELOAD_PUSH_VALUE(vm_offset_t, lastaddr); > dtb_size = fdt_totalsize(rvbp->dtbp_virt); > memmove((void *)lastaddr, (const void *)rvbp->dtbp_virt, dtb_size); > lastaddr = roundup(lastaddr + dtb_size, sizeof(int)); > > - fake_preload[i++] = 0; > - fake_preload[i] = 0; > - preload_metadata = (void *)fake_preload; > + /* End marker */ > + PRELOAD_PUSH_VALUE(uint32_t, 0); > + PRELOAD_PUSH_VALUE(uint32_t, 0); > + preload_metadata = (caddr_t)fake_preload; > > - KASSERT(i < nitems(fake_preload), ("Too many fake_preload items")); > + KASSERT(fake_size < sizeof(fake_preload), > + ("Too many fake_preload items")); > > return (lastaddr); > }