Skip to content

Commit 2888e49

Browse files
committed
riscv64-gen: implement gen_clear_cache
Emit fence + fence.i (Zifencei extension) for I/D cache synchronization, needed for tcc -run mode on RISC-V. Zifencei is required by the RISC-V Linux ABI and present on all Linux-capable cores, though technically not part of the RV64G base ISA.
1 parent c77339a commit 2888e49

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

riscv64-gen.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,4 +1456,12 @@ ST_FUNC void gen_vla_alloc(CType *type, int align)
14561456
}
14571457
#endif
14581458
}
1459+
1460+
ST_FUNC void gen_clear_cache(void)
1461+
{
1462+
/* Zifencei extension: fence + fence.i for I/D synchronization.
1463+
Required by RISC-V Linux ABI, present on all Linux-capable cores. */
1464+
o(0x0ff0000f); // fence iorw, iorw
1465+
o(0x0000100f); // fence.i
1466+
}
14591467
#endif

tccelf.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,14 +2857,15 @@ static void create_riscv_attribute_section(TCCState *s1)
28572857
{
28582858
static const unsigned char riscv_attr[] = {
28592859
0x41, /* 'A' */
2860-
0x3c, 0x00, 0x00, 0x00, /* total_len = 60 */
2860+
0x49, 0x00, 0x00, 0x00, /* total_len = 73 */
28612861
'r', 'i', 's', 'c', 'v', 0x00, /* "riscv\0" */
2862-
0x2d, 0x00, 0x00, 0x00, /* file_len = 45 */
2862+
0x3a, 0x00, 0x00, 0x00, /* file_len = 58 */
28632863
0x05, /* Tag_RISCV_arch */
2864-
0x28, 0x00, 0x00, 0x00, /* isa_len = 40 */
2864+
0x35, 0x00, 0x00, 0x00, /* isa_len = 53 */
28652865
'r','v','6','4','i','2','p','1','_','m','2','p','0','_',
28662866
'a','2','p','1','_','f','2','p','2','_','d','2','p','2','_',
2867-
'c','2','p','0','_','z','i','c','s','r','2','p','0', 0x00,
2867+
'c','2','p','0','_','z','i','c','s','r','2','p','0','_',
2868+
'z','i','f','e','n','c','e','i','2','p','0', 0x00,
28682869
};
28692870
Section *attr = new_section(s1, ".riscv.attributes", SHT_RISCV_ATTRIBUTES, 0);
28702871
unsigned char *ptr = section_ptr_add(attr, sizeof(riscv_attr));

0 commit comments

Comments
 (0)