9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Risc-v toolchain?
@ 2025-06-22 22:02 flux
       [not found] ` <70234b0721c799a7d8a67f17fc4a8ac9@hamnavoe.com>
  0 siblings, 1 reply; 4+ messages in thread
From: flux @ 2025-06-22 22:02 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 996 bytes --]

Who did this work?  Can I bug you quickly?  I'd like a smidge of documentation on the calling convention.

In particular, I'm wanting to call the sbi, writing the equivalent of this gdb asm, but the calling convention is likely getting in my way of making it work:

> asm_print:
> addi sp, sp, -32
> sd ra, 24(sp) # return address
> sd s0, 16(sp) # frame pointer
> addi s0, sp, 32  # set up our new frame pointer, 32 bytes past our stack
> li a7, 0x4442434E
> li a6, 0x00
> li a2, 0
> # a0 and a1 already have our params
> ecall
> 
> ld ra, 24(sp) # restore return address
> ld s0, 16(sp) # restore return frame pointer
> addi sp, sp, 32 # drop the stack
> ret

Ideally I'd like to call this from C for early bringup debug.

 Thanks,
  Paul
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T48f47cc224c8e8f0-Md907a5232fa1e3e2252f7350
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 5871 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] Risc-v toolchain?
       [not found] ` <70234b0721c799a7d8a67f17fc4a8ac9@hamnavoe.com>
@ 2025-06-23 14:17   ` Paul Lalonde
  2025-06-23 16:30     ` ron minnich
  2025-06-23 16:30     ` Richard Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Lalonde @ 2025-06-23 14:17 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 1033 bytes --]

Thanks Richard - what I'm missing is which registers I'm responsible for
saving.  The standard RiscV ABI uses a mix of caller vs callee saved and
parameters passed in registers.  Our convention differs, but I don't know
how with respect to riscv.

Thanks,
  Paul

On Mon, Jun 23, 2025 at 3:50 AM Richard Miller <9fans@hamnavoe.com> wrote:

> >  I'd like a smidge of documentation on the calling convention.
> 
> As with the other Plan 9 compilers, the '-S' option for ic/jc will
> show you the function call and entry sequences, in a syntax which
> is meant to be acceptable by ia/ja. The '-a' option for il/jl will
> show you the actual machine instructions generated.
> 
> Geoff Collyer's 9k riscv64 port has a wrapper for calling the SBI
> from C, in /sys/src/9k/rv/sbiecall.s
> 

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T48f47cc224c8e8f0-M001208a3f19dd0030134e6e1
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 2367 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] Risc-v toolchain?
  2025-06-23 14:17   ` Paul Lalonde
@ 2025-06-23 16:30     ` ron minnich
  2025-06-23 16:30     ` Richard Miller
  1 sibling, 0 replies; 4+ messages in thread
From: ron minnich @ 2025-06-23 16:30 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 1794 bytes --]

plan 9 is caller-save. When I wrote my version of this in 2015, I did not
save anything. First arg is in RARG, the rest are on the stack.

So the sum total of my "call opensbi" code was to move arguments to
registers and take the trap. I'll assume those rules still apply.



On Mon, Jun 23, 2025 at 8:18 AM Paul Lalonde <paul.a.lalonde@gmail.com>
wrote:

> Thanks Richard - what I'm missing is which registers I'm responsible for
> saving.  The standard RiscV ABI uses a mix of caller vs callee saved and
> parameters passed in registers.  Our convention differs, but I don't know
> how with respect to riscv.
>
> Thanks,
>   Paul
>
> On Mon, Jun 23, 2025 at 3:50 AM Richard Miller <9fans@hamnavoe.com> wrote:
>
>> >  I'd like a smidge of documentation on the calling convention.
>> 
>> As with the other Plan 9 compilers, the '-S' option for ic/jc will
>> show you the function call and entry sequences, in a syntax which
>> is meant to be acceptable by ia/ja. The '-a' option for il/jl will
>> show you the actual machine instructions generated.
>> 
>> Geoff Collyer's 9k riscv64 port has a wrapper for calling the SBI
>> from C, in /sys/src/9k/rv/sbiecall.s
>> 
> *9fans <https://9fans.topicbox.com/latest>* / 9fans / see discussions
> <https://9fans.topicbox.com/groups/9fans> + participants
> <https://9fans.topicbox.com/groups/9fans/members> + delivery options
> <https://9fans.topicbox.com/groups/9fans/subscription> Permalink
> <https://9fans.topicbox.com/groups/9fans/T48f47cc224c8e8f0-M001208a3f19dd0030134e6e1>
>

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T48f47cc224c8e8f0-Mbc1dea28d360517b8d11a49f
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 3199 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] Risc-v toolchain?
  2025-06-23 14:17   ` Paul Lalonde
  2025-06-23 16:30     ` ron minnich
@ 2025-06-23 16:30     ` Richard Miller
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Miller @ 2025-06-23 16:30 UTC (permalink / raw)
  To: 9fans

> Thanks Richard - what I'm missing is which registers I'm responsible for
> saving.

Plan 9 C compilers are always caller-save, so you don't have to save
anything (unless you're using extern registers).

Register usage (REGARG, REGRET, etc) for the Plan 9 riscv compiler is
defined in /sys/src/cmd/ic/i.out.h

Geoff's code has a lot of useful comments about the SBI conventions,
for example that SP has to be 16-byte aligned.


------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T48f47cc224c8e8f0-M0a49303cf10d9648a06fc8da
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-23 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-22 22:02 [9fans] Risc-v toolchain? flux
     [not found] ` <70234b0721c799a7d8a67f17fc4a8ac9@hamnavoe.com>
2025-06-23 14:17   ` Paul Lalonde
2025-06-23 16:30     ` ron minnich
2025-06-23 16:30     ` Richard Miller

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).