Skip to contentSkip to conversation

target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63

PATCH Applied Clément Léger 4 participants 7 messages Apr 22, 2024 – Apr 29, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63

The current semihost exception number (16) is a reserved number (range [16-17]). The upcoming double trap specification uses that number for the double trap exception. Since the privileged spec (Table 22) defines ranges for custom uses change the semihosting exception number to 63 which belongs to the range [48-63] in order to avoid any future collisions with reserved exception.

---
 target/riscv/cpu_bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu_bits.h +1 -1
index fc2068ee4d..74318a925c 100644
@@ -670,11 +670,11 @@ typedef enum RISCVException {
     RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
     RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
     RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
-    RISCV_EXCP_SEMIHOST = 0x10,
     RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
     RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
     RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
     RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
+    RISCV_EXCP_SEMIHOST = 0x3f,
 } RISCVException;
 
 #define RISCV_EXCP_INT_FLAG                0x80000000
Signature · 1 line
2.43.0
#1 lore raw

Palmer, Anup,

Quoted 6 lines · Clément Léger

The current semihost exception number (16) is a reserved number (range [16-17]). The upcoming double trap specification uses that number for the double trap exception. Since the privileged spec (Table 22) defines ranges for custom uses change the semihosting exception number to 63 which belongs to the range [48-63] in order to avoid any future collisions with reserved exception.

I didn't find any reference to a number for the SEMIHOST exception here:

https://github.com/riscv-non-isa/riscv-semihosting

Do we have any potential candidates? I would like to avoid, if possible, setting RISCV_EXCP_SEMIHOST to 63 as a band-aid just to replace it later on by the real value.

Thanks,

Daniel

Quoted 24 lines
---
  target/riscv/cpu_bits.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu_bits.h +1 -1
index fc2068ee4d..74318a925c 100644
@@ -670,11 +670,11 @@ typedef enum RISCVException {
      RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
      RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
      RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
-    RISCV_EXCP_SEMIHOST = 0x10,
      RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
      RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
      RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
      RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
+    RISCV_EXCP_SEMIHOST = 0x3f,
  } RISCVException;
 
  #define RISCV_EXCP_INT_FLAG                0x80000000
#2 lore raw
Quoted 14 lines · Daniel Henrique Barboza

Palmer, Anup,

Quoted 6 lines · Clément Léger

The current semihost exception number (16) is a reserved number (range [16-17]). The upcoming double trap specification uses that number for the double trap exception. Since the privileged spec (Table 22) defines ranges for custom uses change the semihosting exception number to 63 which belongs to the range [48-63] in order to avoid any future collisions with reserved exception.

I didn't find any reference to a number for the SEMIHOST exception here:

Quoted 6 lines

https://github.com/riscv-non-isa/riscv-semihosting

Do we have any potential candidates? I would like to avoid, if possible, setting RISCV_EXCP_SEMIHOST to 63 as a band-aid just to replace it later on by the real value.

RISCV_EXCP_SEMIHOST is internal to the qemu implementation and will never be delivered to the guest.

I suggest using a number high in the >64 reserved range which will (likely) never be used by any implementation, including ones that *do* define implementation-specific exceptions.
Which seems more likely than not within the "implementation defined" range.

E.g. target/i386 uses 0x100+n for qemu internal exceptions.

But in any case, the number can be redefined at will and not cause compatibility issues.

r~

#3 lore raw
Quoted 22 lines · Richard Henderson
Quoted 14 lines · Daniel Henrique Barboza

Palmer, Anup,

Quoted 6 lines · Clément Léger

The current semihost exception number (16) is a reserved number (range [16-17]). The upcoming double trap specification uses that number for the double trap exception. Since the privileged spec (Table 22) defines ranges for custom uses change the semihosting exception number to 63 which belongs to the range [48-63] in order to avoid any future collisions with reserved exception.

I didn't find any reference to a number for the SEMIHOST exception here:

Quoted 6 lines

https://github.com/riscv-non-isa/riscv-semihosting

Do we have any potential candidates? I would like to avoid, if possible, setting RISCV_EXCP_SEMIHOST to 63 as a band-aid just to replace it later on by the real value.

Quoted 5 lines

RISCV_EXCP_SEMIHOST is internal to the qemu implementation and will never be delivered to the guest.

I suggest using a number high in the >64 reserved range which will (likely) never be used by any implementation, including ones that *do* define implementation-specific exceptions.  Which seems more likely than not within the "implementation defined" range.

E.g. target/i386 uses 0x100+n for qemu internal exceptions.

I'm not sure if we have a range for risc-v qemu internal exceptions only. IIRC we don't.

If that's really the case I believe we could use whatever i386/ARM uses. At least we'll have some standardization.

Thanks,

Daniel

Quoted 5 lines

But in any case, the number can be redefined at will and not cause compatibility issues.

r~

#4 lore raw
Quoted 35 lines · Daniel Henrique Barboza
Quoted 32 lines · Richard Henderson
Quoted 14 lines · Daniel Henrique Barboza

Palmer, Anup,

Quoted 6 lines · Clément Léger

The current semihost exception number (16) is a reserved number (range [16-17]). The upcoming double trap specification uses that number for the double trap exception. Since the privileged spec (Table 22) defines ranges for custom uses change the semihosting exception number to 63 which belongs to the range [48-63] in order to avoid any future collisions with reserved exception.

I didn't find any reference to a number for the SEMIHOST exception here:

Quoted 8 lines

https://github.com/riscv-non-isa/riscv-semihosting

Do we have any potential candidates? I would like to avoid, if possible, setting
RISCV_EXCP_SEMIHOST to 63 as a band-aid just to replace it later on by the real
value.

RISCV_EXCP_SEMIHOST is internal to the qemu implementation and will never be delivered to the guest.

I suggest using a number high in the >64 reserved range which will (likely) never be used by any implementation, including ones that *do* define implementation-specific exceptions.  Which seems more likely than not within the "implementation defined" range.

Quoted 8 lines
Quoted 1 line

E.g. target/i386 uses 0x100+n for qemu internal exceptions.

I'm not sure if we have a range for risc-v qemu internal exceptions only. IIRC we don't.

If that's really the case I believe we could use whatever i386/ARM uses. At least we'll have some
standardization.

The spec also states that numbers >= 64 are reserved which is why using a one for custom use was making sense.

Thanks,

Clément

Quoted 12 lines

Thanks,

Daniel

Quoted 6 lines

But in any case, the number can be redefined at will and not cause compatibility issues.

r~

Reviewed-by on v1 1/1
#5 lore raw
In reply to Clément Léger
Quoted 9 lines · Clément Léger

The current semihost exception number (16) is a reserved number (range [16-17]). The upcoming double trap specification uses that number for the double trap exception. Since the privileged spec (Table 22) defines ranges for custom uses change the semihosting exception number to 63 which belongs to the range [48-63] in order to avoid any future collisions with reserved exception.

Alistair

Quoted 26 lines
---
 target/riscv/cpu_bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu_bits.h +1 -2
index fc2068ee4d..74318a925c 100644
@@ -670,11 +670,11 @@ typedef enum RISCVException {
     RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
     RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
     RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
-    RISCV_EXCP_SEMIHOST = 0x10,
     RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
     RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
     RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
     RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
+    RISCV_EXCP_SEMIHOST = 0x3f,
 } RISCVException;
 
 #define RISCV_EXCP_INT_FLAG                0x80000000
--

2.43.0

#6 lore raw
In reply to Clément Léger
Quoted 9 lines · Clément Léger

The current semihost exception number (16) is a reserved number (range [16-17]). The upcoming double trap specification uses that number for the double trap exception. Since the privileged spec (Table 22) defines ranges for custom uses change the semihosting exception number to 63 which belongs to the range [48-63] in order to avoid any future collisions with reserved exception.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 26 lines
---
 target/riscv/cpu_bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu_bits.h +1 -2
index fc2068ee4d..74318a925c 100644
@@ -670,11 +670,11 @@ typedef enum RISCVException {
     RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
     RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
     RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
-    RISCV_EXCP_SEMIHOST = 0x10,
     RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
     RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
     RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
     RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
+    RISCV_EXCP_SEMIHOST = 0x3f,
 } RISCVException;
 
 #define RISCV_EXCP_INT_FLAG                0x80000000
--

2.43.0