From: ron minnich <rminnich@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Fwd: [9fans] risc-v memory layout
Date: Wed, 7 Jan 2026 13:01:23 -0800 [thread overview]
Message-ID: <CAP6exYJLCMXniWs1PpKyMMyCpNO68zqt1fdt_7eUBM7BoVtwGA@mail.gmail.com> (raw)
In-Reply-To: <ea359f4c9da90ed3a9a0d90e19442ab2@hamnavoe.com>
[-- Attachment #1: Type: text/plain, Size: 2475 bytes --]
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 >= (VDRAM - KZERO) + (KMAPEND - KMAP))
panic("kmapaddr: pa=%#p pc=%#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=%#p pc=%#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 = 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 PM 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.
>
> 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-Ma7e1202fce4910d209f48b65
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
[-- Attachment #2: Type: text/html, Size: 4247 bytes --]
next prev parent reply other threads:[~2026-01-07 21:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 23:13 [9fans] risc-v memory layout ron minnich
2026-01-07 9:44 ` Richard Miller
2026-01-07 16:58 ` ron minnich
2026-01-07 19:42 ` Richard Miller
2026-01-07 21:01 ` ron minnich [this message]
2026-01-07 17:54 ` tlaronde
2026-01-07 19:28 ` ron minnich
2026-01-08 2:50 ` Dan Cross
2026-01-08 8:08 ` tlaronde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAP6exYJLCMXniWs1PpKyMMyCpNO68zqt1fdt_7eUBM7BoVtwGA@mail.gmail.com \
--to=rminnich@gmail.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).