Running program which has custom instruction in SPIKE simulator results error

Hi,

Currently i could successfully add a custom instruction to my gnu assembler and able to reproduce object file which has my new instruction “mod” which has opcode "02e787eb " . Now i also added same custom instruction to spike simulator also as per this below article

the section “Adding the custom instruction to spike ISA simulator” .I tried to run small program with inline assembly (which has embedded custom instruction which i created).

#include <stdio.h>

int main()
{
int a, b, c;
a = 5;
b = 2;
asm volatile
(
“mod %[z], %[x ], %[y]\n\t”
: [z] “=r” ©
: [x ] “r” (a), [y] “r” (b)
);

if ( c != 1 ){
printf("\n[[FAILED]]\n");
}

printf("\n[[PASSED]]\n");

return 0;
}

Here is the definition of my new opcode in riscvc-opcodes/opcodes

mod rd rs1 rs2 31…25=1 14…12=0 6…2=0x1A 1…0=3

Now when i run the program with spike i got following error.
bbl loader
z 00000000 ra 00000000 sp 7fbecd70 gp 00000000
tp 00000000 t0 00000000 t1 00000000 t2 00000000
s0 00000000 s1 00000000 a0 00000000 a1 00000000
a2 00000000 a3 00000000 a4 00000000 a5 00000000
a6 00000000 a7 00000000 s2 00000000 s3 00000000
s4 00000000 s5 00000000 s6 00000000 s7 00000000
s8 00000000 s9 00000000 sA 00000000 sB 00000000
t3 00000000 t4 00000000 t5 00000000 t6 00000000
pc 00000000 va 00000000 insn ffffffff sr 80046020
User fetch segfault @ 0x00000000

What is going wrong here ?. I tried another program which has add instruction with embedded inline assembly. Add is standard instruction anyhow. Still same error i see when i run through spike.

Here is the assembly dump of my mod program (mod.o)

00000000 :
0: fe010113 addi sp,sp,-32
4: 00112e23 sw ra,28(sp)
8: 00812c23 sw s0,24(sp)
c: 02010413 addi s0,sp,32
10: 00500793 li a5,5
14: fef42623 sw a5,-20(s0)
18: 00200793 li a5,2
1c: fef42423 sw a5,-24(s0)
20: fec42783 lw a5,-20(s0)
24: fe842703 lw a4,-24(s0)
28: 02e787eb mod a5,a5,a4
2c: fef42223 sw a5,-28(s0)
30: fe442703 lw a4,-28(s0)
34: 00100793 li a5,1
38: 00f70a63 beq a4,a5,4c <.L2>
3c: 000007b7 lui a5,0x0
40: 00078513 mv a0,a5
44: 00000097 auipc ra,0x0
48: 000080e7 jalr ra # 44 <main+0x44>

0000004c <.L2>:
4c: 000007b7 lui a5,0x0
50: 00078513 mv a0,a5
54: 00000097 auipc ra,0x0
58: 000080e7 jalr ra # 54 <.L2+0x8>
5c: 00000793 li a5,0
60: 00078513 mv a0,a5
64: 01c12083 lw ra,28(sp)
68: 01812403 lw s0,24(sp)
6c: 02010113 addi sp,sp,32
70: 00008067 ret

here we can see mod instruction .

Can u give some hints why i get segmentation fault?

Hi,

I could resolve this problem…it was my mistake. i was using gcc command in wrong way , so it produced the binary with main function address 0x00000000 which is wrong.