From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RCVD_IN_ZEN_BLOCKED_OPENDNS, URIBL_DBL_BLOCKED_OPENDNS,URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.4 Received: from txout-a4-smtp.messagingengine.com (txout-a4-smtp.messagingengine.com [103.168.172.227]) by inbox.vuxu.org (Postfix) with ESMTP id 53A222F6DE for ; Wed, 7 Jan 2026 22:09:25 +0100 (CET) Received: from localhost.localdomain (phl-topicbox-02.internal [10.202.2.220]) by mailtxout.phl.internal (Postfix) with ESMTP id 342581C02F9 for ; Wed, 7 Jan 2026 16:09:25 -0500 (EST) ARC-Authentication-Results: i=2; topicbox.com; arc=pass; dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=In2DRBKm header.a=rsa-sha256 header.s=20230601 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; spf=pass smtp.mailfrom=rminnich@gmail.com smtp.helo=mail-lf1-f45.google.com; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=mime-version:references:in-reply-to:from:date :message-id:subject:to:content-type:list-help:list-id:list-post :list-subscribe:reply-to:content-transfer-encoding :list-unsubscribe; s=sysmsg-1; t=1767820165; bh=gacCz2qnPgFnBK+l f9r4AK5Qz5WqV3FaZhAI777gi4k=; b=HwS0lGhmb26tbhDF3Ni3ff/jrqYakd8H 6H/gxmWCbPx10PrhpwwC3in2QDtwNgWZ0Z0AhiOEsQ8je7kkzovQsLyow/oAyzAh Bj0DaOTp0fikNLk6E41A+wZDy5hb5yk98Kgv9bWLQwwAuR5SL8qfsUZIqJ0rHm/9 2kS9jQCt6Pw= ARC-Seal: i=2; a=rsa-sha256; cv=pass; d=topicbox.com; s=sysmsg-1; t= 1767820165; b=NYh5RSj24M5Sko8Mq4IZjLXr9PMNFm3Rx+8qp/qJ9m9Zcz86jP Q9iHBxF29IEjZsBwzfmuKhWXKoMN5jj5pqifjmnFsieSrWra5OKA48jRlL1jRzLY p5rMeOPJ16d/TvgVHj4Pn4mDCGDLMhUJTYKqnz1ljNlXHRrUUGDml0pE8= Authentication-Results: topicbox.com; arc=pass; dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=In2DRBKm header.a=rsa-sha256 header.s=20230601 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; spf=pass smtp.mailfrom=rminnich@gmail.com smtp.helo=mail-lf1-f45.google.com; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) X-Received-Authentication-Results: authmilter.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=In2DRBKm header.a=rsa-sha256 header.s=20230601 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; iprev=pass smtp.remote-ip=209.85.167.45 (mail-lf1-f45.google.com); spf=pass smtp.mailfrom=rminnich@gmail.com smtp.helo=mail-lf1-f45.google.com; x-aligned-from=pass (Address match); x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net header.i=@1e100.net header.b=NdIaTmE4; x-me-sender=none; x-ptr=pass smtp.helo=mail-lf1-f45.google.com policy.ptr=mail-lf1-f45.google.com; x-return-mx=pass header.domain=gmail.com policy.is_org=yes (MX Records found: gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com); x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes (MX Records found: gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com); x-tls=pass smtp.version=TLSv1.3 smtp.cipher=TLS_AES_128_GCM_SHA256 smtp.bits=128/128; x-vs=clean score=-100 state=0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=9fans.net; h= mime-version:references:in-reply-to:from:date:message-id:subject :to:content-type:list-help:list-id:list-post:list-subscribe :reply-to:content-transfer-encoding:list-unsubscribe; s=dkim-1; t=1767820165; x=1767906565; bh=J3Ii125lSon27FdORiLU5Xow9hF/teF5 dpg7s47GkT8=; b=XaqqPfZaBCF8gGDrGNIr+Ql8+U8ZMOKNBVx0nmYgLLvFZ92T 46EB7fuFCXiSyutxc+xxnxsQyjbRXkY3SMahnzZrh6tmgCN/MtrsQW+6ZY9cI9hI TjXFEN5Ej0oYiPNJy2s79u27Vsud32pw0/uAIKZp8Q/aH7OaaCdsqwLVhMw= Received: from authmilter.topicbox.com (unknown [172.17.0.1]) by mx.topicbox.com (Postfix) with ESMTP id A097135CEA0F for <9fans@9fans.net>; Wed, 7 Jan 2026 16:01:39 -0500 (EST) Received: from mx.topicbox.com (172.17.0.1 [172.17.0.1]) by authmilter.topicbox.com (Authentication Milter) with ESMTP id A77C97FD004; Wed, 7 Jan 2026 16:01:39 -0500 ARC-Seal: i=1; a=rsa-sha256; cv=none; d=topicbox.com; s=arcseal; t= 1767819699; b=tnbc2MrYE8W72BNgO0NuEronNk20LXN8wOt+fmADbFB4C9Hd4/ zPO7JvCYIPCeV24+PzJwiDCW0NOFutt8GjIlj9ctUuklPY8Z9A32o+/okDowKhjJ Jp8F9rQ4pK0xTRRrSpFKfCEkwz0DDPqVmQJfJ+xDTpKu72i0o446W7V6o7NIOCrf t7/F4qKaLBKvBMC6eteafxOwA/efxKKhRtUnqOmZ78a9pA9Q+ldsjXb7V51MGUn8 gmZXR85mJ/jLvkuINm8ybRB5FhEyBuaJ0zgGh7iLu/IkTk7iru4EZV0T65sJf0iH C/BySjRMzh37us97bSjjCva8R/M5CuqYuzPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=mime-version:references:in-reply-to:from:date :message-id:subject:to:content-type; s=arcseal; t=1767819699; bh=0zMty5iZHe3Fl2aLuaiUP7CKD+sMUp1EgfZuPcxlH4A=; b=AfjDeukcuHGW GezOHA9M1tWGxWal9Zmypd1oU2Xz4xlckawQBNyZ0OazTfxKDqMRyLIoqslxKbGz Iu4Lt2qZbAOXtZgyVVqVd/F5n+SIIkzMCs4cE/4EKh9N5XQDU09suCE+CbeQET3j Q7LE8vTbrIwQQOive7DY2A0DMBvFKIbT20bXgQUdn3IDiaDT9PiX1jJeQ3LGBvmO QjXyPB3xGGIm8LxW0y5p9l+J1sl6Z5Ndyvf7+7vOoNJIJnw3bF6PnFufNp9J7Pej YOdilj8irJjXHugNqRa+Xq+vXYXnX9rNSbb3jupPJX19gleXIDjAKjnBJCD6DlIm oij6QocFlQ== ARC-Authentication-Results: i=1; authmilter.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=In2DRBKm header.a=rsa-sha256 header.s=20230601 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; iprev=pass smtp.remote-ip=209.85.167.45 (mail-lf1-f45.google.com); spf=pass smtp.mailfrom=rminnich@gmail.com smtp.helo=mail-lf1-f45.google.com; x-aligned-from=pass (Address match); x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net header.i=@1e100.net header.b=NdIaTmE4; x-me-sender=none; x-ptr=pass smtp.helo=mail-lf1-f45.google.com policy.ptr=mail-lf1-f45.google.com; x-return-mx=pass header.domain=gmail.com policy.is_org=yes (MX Records found: gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com); x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes (MX Records found: gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com); x-tls=pass smtp.version=TLSv1.3 smtp.cipher=TLS_AES_128_GCM_SHA256 smtp.bits=128/128; x-vs=clean score=-100 state=0 X-ME-VSCause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddutdegtdelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepgghfjgfhfffkuffvtgesrgdtreertddtjeen ucfhrhhomheprhhonhcumhhinhhnihgthhcuoehrmhhinhhnihgthhesghhmrghilhdrtg homheqnecuggftrfgrthhtvghrnhephfehteetuedvgedthffhieegfffhjeefjeeiteff ffeiuddvhefhffduiedutdeunecuffhomhgrihhnpehtohhpihgtsghogidrtghomhenuc fkphepvddtledrkeehrdduieejrdegheenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepihhnvghtpedvtdelrdekhedrudeijedrgeehpdhhvghlohepmhgrihhlqdhlfh duqdhfgeehrdhgohhoghhlvgdrtghomhdpmhgrihhlfhhrohhmpeeorhhmihhnnhhitghh sehgmhgrihhlrdgtohhmqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeeolehfrg hnsheslehfrghnshdrnhgvtheq X-ME-VSScore: -100 X-ME-VSCategory: clean Received-SPF: pass (gmail.com ... _spf.google.com: 209.85.167.45 is authorized to use 'rminnich@gmail.com' in 'mfrom' identity (mechanism 'ip4:209.85.128.0/17' matched)) receiver=authmilter.topicbox.com; identity=mailfrom; envelope-from="rminnich@gmail.com"; helo=mail-lf1-f45.google.com; client-ip=209.85.167.45 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx.topicbox.com (Postfix) with ESMTPS for <9fans@9fans.net>; Wed, 7 Jan 2026 16:01:39 -0500 (EST) Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-59911cb8c3cso2821979e87.2 for <9fans@9fans.net>; Wed, 07 Jan 2026 13:01:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767819697; x=1768424497; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0zMty5iZHe3Fl2aLuaiUP7CKD+sMUp1EgfZuPcxlH4A=; b=NdIaTmE45OkIMHWJN/B6xdw5q5Gts4MCL0b4VJC5SkI5I8T/vP0yUwBuANRS8OoEbJ S5Dbq9bBYyAw5r0B/AAxixuHxGu7l7kIcwEY/e3QGwRYV4Sq++eN3iJGbxDiCKs6bM6S MxN7DcJeIDFiabd39Mgh68ctA8L1WC+XU3jVN6OrBk2sdsghe8GtcyAzH8nsJ5ZZCq0H owGg60xhcNUb2Xwy1zWnEKyxWG1zXVlmGW6S/Q/J2O3IQUoqnS+se8bLLVQuA3pDs18x tB814qj/GVLlOZn0UtqP1yCOQspsp0yAEj8whWL8vpXsYVDHxp2k1SoFY44vNkW3UpuI /LiA== X-Gm-Message-State: AOJu0YzZnBDkx3Q/Z5NfapmVcPHRh90iozMvnJI74OpSjxg919N7hnNf j2TBmrYwQFoV8M2n1l2YwrBIqnClZU6UkwFODYKguI+yiD8e3aZwehTELHXO3JdvvcYs2jBEXs5 VDB65GSvP0rPHMwbBp3IQj/5qDszvlpNxdKb6 X-Gm-Gg: AY/fxX4fR1LcHSZQpmukAk7+tdjX0dq6qbHnpxyKKb0nIvhlp0kT35YDSgkTpkQojAO /rEZlsyTidVnRo+TgUbGbF2k7sCnI/cwdiZeJ4AF9vm1sBCWqyI12TIKImbpGr/lisrKgr6tIAd ROM8kzN1niJSz6/5FkNoDCzSt0+Tp2rXzp/yOs93swIuntPdEUAnzD1wJ5V6sfYg1MB4PUrXtqz sNJVs85ZwxMQfBwrBEnMw1x0NSOEI4g5kngemiHrLwE7D3rxZcokprXpwW9PvEef7Nna6Pb X-Google-Smtp-Source: AGHT+IHECCCv0dvGFl3cBf0/Ht4D+hP40YcqenNtBWwrYodypLYxOxF4utkZ0u2TuUo4IZMDh9ayY9fC4AqazQ3GNU0= X-Received: by 2002:a05:6512:2255:b0:598:de13:609a with SMTP id 2adb3069b0e04-59b6f0359fdmr1121828e87.37.1767819696745; Wed, 07 Jan 2026 13:01:36 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: ron minnich Date: Wed, 7 Jan 2026 13:01:23 -0800 X-Gm-Features: AQt7F2rbxgT11mukl9RQDBkRc1w-OMC1HLmFAVIQnaQijf3Q0RBShIrDM_vfnHs Message-ID: Subject: Fwd: [9fans] risc-v memory layout To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=0000000000000d2ee10647d299ec Topicbox-Policy-Reasoning: moderate: sender is a member; group holds all messages Topicbox-Message-UUID: 108b1212-ec0c-11f0-bf05-2b6310c0285f Archived-At: =?UTF-8?B?PGh0dHBzOi8vOWZhbnMudG9waWNib3guY29tL2dyb3Vwcy85?= =?UTF-8?B?ZmFucy9UZjZlMGIxYjNmODBkZjgyMS1NYTdlMTIwMmZjZTQ5MTBkMjA5ZjQ4?= =?UTF-8?B?YjY1Pg==?= List-Help: List-Id: "9fans" <9fans.9fans.net> List-Post: List-Software: Topicbox v0 List-Subscribe: Precedence: list Reply-To: 9fans <9fans@9fans.net> Content-Transfer-Encoding: 7bit List-Unsubscribe: , Topicbox-Delivery-ID: 2:9fans:437d30aa-c441-11e9-8a57-d036212d11b0:522be890-2105-11eb-b15e-8d699134e1fa:Ma7e1202fce4910d209f48b65:1:hy87Lh3tdNIyjWEYJEzCUZoQ69EJefnmmhvqGuyWZ-c --0000000000000d2ee10647d299ec Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable M mode is forced by the architecture, and SBI is essential to making that work. SBI has grown like cancer, to the point that SMP startup now requires SBI, replacing the old lottery system. We discussed M-mode-free SoC in 2014, but in 2025, I can see that's never going to happen. So you have to have SBI. And the kernel and SBI share data, so it would be nice to give them a compatible address range. Consider kmapaddr. With the address space at the top, here is today's version: static void* kmapaddr(uintptr pa) { if(pa < (uintptr)-KZERO) return (void*)(pa + KZERO); if(pa < (VDRAM - KZERO) || pa >=3D (VDRAM - KZERO) + (KMAPEND - KMAP)) panic("kmapaddr: pa=3D%#p pc=3D%#p", pa, getcallerpc(&pa)); return (void*)(pa + KMAP - (VDRAM - KZERO)); } // Note: this panics. I don't know why just yet. 0-based KVA version: static void* kmapaddr(uintptr pa) { if (pa < 1<<62) return (void *)pa; panic("kmapaddr: pa=3D%#p pc=3D%#p", pa, getcallerpc(&pa)); return nil; } That second version I can understand; that first version makes my head hurt. Further, what is KZERO? Well, the answer is, it depends on whether your RISC-V is sv39, sv48, or sv57. It's painful. Looking at things a bit more, UVA already starts at 2M. As a test, I'm going to build the kernel with KZERO =3D 0, start UVA at 1<<31 and see if I get any distance, I'm tired of all this math. (uintptr)-KZERO? bah. ron On Wed, Jan 7, 2026 at 12:12=E2=80=AFPM Richard Miller <9fans@hamnavoe.com>= wrote: > rminnich@gmail.com: > > you can't avoid M mode on riscv, ever. There are several trap cases that > > will drop you in to M mode. >=20 > I thought avoiding M mode was forced on you by the SBI implementation > (firmware), which intercepts M mode traps and delegates them to S mode > (if it feels like it). That's my recollection from working with the > Polarfire Icicle, but it's a few years back. Or are you designing for > a bare metal platform with no SBI? >=20 > Are there any riscv implementations on the market which allow kernel > and user mode to run with different XLEN, and thus enable a 64-bit > kernel to host 32-bit processes? If so, I think that implies that > you would want user address space to start at (or near) zero. >=20 ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/Tf6e0b1b3f80df821-Ma7e12= 02fce4910d209f48b65 Delivery options: https://9fans.topicbox.com/groups/9fans/subscription --0000000000000d2ee10647d299ec Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
M mode is forced by the architecture, and SBI = is essential to making that work. SBI has grown like cancer, to the point t= hat SMP startup now requires SBI, replacing the old lottery system. We disc= ussed M-mode-free SoC in 2014, but in 2025, I can see that's never goin= g to happen.

So you have to have SBI. And the kernel&n= bsp;and SBI share data, so it would be nice to give them a compatible = address range.

Consider kmapaddr. With the addre= ss space at the  top, here is today's version:
static vo= id*
kmapaddr(uintptr pa)
{
if(pa < (uintptr)-KZERO)
return (void*)(pa + KZERO);
if(pa < (VDRAM - KZERO) || pa >= =3D (VDRAM - KZERO) + (KMAPEND - KMAP))
panic("kmapaddr: pa=3D%= #p pc=3D%#p", pa, getcallerpc(&pa));
return (void*)(pa + KMA= P - (VDRAM - KZERO));
}
// Note: this panics. I don= 9;t know why just yet.

0-based KVA version:

static void*
kmapaddr(uintptr pa)
{
<= div> if (pa < 1<<62) return (void *)pa;
panic("km= apaddr: pa=3D%#p pc=3D%#p", pa, getcallerpc(&pa));
return nil= ;
}

That second version I can underst= and; that first version makes my head hurt. Further, what is KZERO? Well, t= he answer is, it depends on whether your RISC-V is sv39, sv48, or sv57. It&= #39;s painful.

Looking at things a bit more, UVA= already starts at 2M. As a test, I'm going to build the kernel with KZ= ERO =3D 0, start UVA at 1<<31 and see if I get any distance,

I'm tired of all this math. (uintptr)-KZERO? bah.

ron

On Wed, Jan 7, 20= 26 at 12:12 PM Richard Miller <9fans@hamnavoe.com> wrote:
rminnich@gmail.com: > you can't avoid M mode on riscv, ever. There are several trap case= s that
> will drop you in to M mode.

I thought avoiding M mode was forced on you by the SBI implementation
(firmware), which intercepts M mode traps and delegates them to S mode
(if it feels like it). That's my recollection from working with the
Polarfire Icicle, but it's a few years back. Or are you designing for a bare metal platform with no SBI?

Are there any riscv implementations on the market which allow kernel
and user mode to run with different XLEN, and thus enable a 64-bit
kernel to host 32-bit processes? If so, I think that implies that
you would want user address space to start at (or near) zero.

------------------------------------------
9fans: 9fans
Permalink: https:= //9fans.topicbox.com/groups/9fans/Tf6e0b1b3f80df821-M5ca44f21c31403b6dd2a80= b0
Delivery options: https://9fans.topicbox.com/gro= ups/9fans/subscription
= --0000000000000d2ee10647d299ec--