1
0
Fork 0
Commit Graph

42 Commits

Author SHA1 Message Date
Ekaitz Zarraga 8baadb3b55 riscv: asm: implement `j offset` 2024-04-25 15:13:21 +02:00
Ekaitz Zarraga 159776304f riscv: asm: Add branch to label 2024-04-24 00:54:51 +02:00
Ekaitz Zarraga 671d03f944 riscv: Add full `fence` instruction support
This commit adds support for `fence`'s predecessor and successor
arguments.
2024-04-23 15:10:08 +02:00
Ekaitz Zarraga c994068175 riscv: asm: Add load-reserved and store-conditional
Add Atomic instructions `ld` and `sc` in their 32 bit and 64 bit
versions.
2024-04-23 12:05:05 +02:00
Ekaitz Zarraga 0703df1a6a Fix Extended Asm ignored constraints
This commit fixes the case where the register of for the Extended Asm
input or output is known. Before this commit, the following case:

  register long __a0 asm ("a0") = one;
  asm volatile (
       "ecall\n\t"
       : "+r" (__a0) // NOTE the +r here
  );

Didn't treat `a0` as an input+output register (+ contraint) as the code
skipped the constraint processing when the register was already chosen
(instead of allocated later).

This issue comes from f081acbfba, that was
taken as a reference in every other Extended Assembler implementation.
2024-04-16 02:47:56 +02:00
herman ten brugge 4944f509c3 riscv: Avoid some compiler warnings 2024-04-13 16:26:12 +02:00
Ekaitz Zarraga 6b3cfdd025 riscv: Add extended assembly support
NOTE: In order to be able to deal with general-purpose vs floating-point
registers, this commit adds a flag in the 6th bit of the register. If
set, it means the register is a floating-point one. This affects all the
assembler.
2024-04-09 00:19:41 +02:00
Ekaitz Zarraga e02eec6bde riscv: fix jal: fix reloc and parsing 2024-03-27 11:50:02 +01:00
Ekaitz Zarraga e2d8eb3d1c riscv: jal: Add pseudo instruction support 2024-03-21 13:33:27 +01:00
Ekaitz Zarraga 409007c9d5 riscv: jalr: implement pseudo and parse like GAS 2024-03-21 13:33:27 +01:00
Ekaitz Zarraga 8bfef6ab18 riscv: Add pseudoinstructions
call, tail, jump, jr, mv, not, neg, negw, seqz, snez, sltz, sgtz, bnez,
beqz, blez, bgez, bltz, bgtz, li
2024-03-21 13:33:25 +01:00
Ekaitz Zarraga 8cbbd2b88a riscv: Use GAS syntax for loads/stores:
Before:
    ld rd, rs, imm
    sd rs1, rs2, imm

Now:
    ld rd, imm(rs)
    sd rs2, imm(rs1)

NOTES: Just as in GAS:
    - In stores the register order is swapped
    - imm is optional
    - when imm is not included parenthesis can be removed
2024-03-19 12:38:21 +01:00
Ekaitz Zarraga 019d10fc12 riscv: Move operand parsing to a separate function 2024-03-19 12:38:21 +01:00
Andrius Štikonas 04365dd4c9 riscv64-asm.c: fix assembly instruction with negative immediate offsets.
This fixes expressions like ld a0, s0, -24 that regressed in
d87801bd50
2024-01-12 21:09:21 +00:00
herman ten brugge 48798969c5 Update riscv64-asm prototypes 2023-12-16 12:28:19 +01:00
noneofyourbusiness ada17a08eb
riscv64-asm.c: add support for calculating addresses of symbols
add some pseudoinstructions
riscv64-tok.h: add pseudoinstructions from tables 25.{2,3}
2023-12-12 09:44:37 +01:00
noneofyourbusiness b390feec6d
riscv64-asm.c: add Zicsr registers 2023-12-10 15:24:25 +01:00
noneofyourbusiness 3b3c9412ac
riscv64-asm.c: implement Zicsr extension 2023-12-09 14:32:14 +01:00
noneofyourbusiness 279dbb94e2
riscv64-asm.c: correct check for 12-bit immediate
asm_emit_cj: correct check for offset size
2023-12-09 01:00:16 +01:00
noneofyourbusiness 275dfbea20
riscv64-asm.c: implement M extension 2023-12-08 22:48:43 +01:00
noneofyourbusiness d87801bd50
riscv64-asm.c: implement C extension
add nop
fix asm_emit_i immediate check (negative offsets were missing)
fix check for IM12S
remove non-existent instructions (example: slli64 is just slli with imm=0)
2023-12-08 17:07:06 +01:00
noneofyourbusiness 81a32ec305
riscv64-asm.c: asm_emit_j: correct check of immediate 2023-12-02 17:08:05 +01:00
noneofyourbusiness 70328621f1
riscv64-asm.c: added asm_emit_j (J-type), changed jal to J-type
additionally added a comment about B-type instruction format
2023-11-27 09:15:32 +01:00
noneofyourbusiness d1c107738b
riscv64-asm.c: add jal/jalr
this implements the base instructions, not the pseudoinstructions

examples
 jal ra, 0
 jalr x0, ra, 0
2023-08-11 10:08:41 +02:00
noneofyourbusiness e70fec871b
riscv64-tok.h: update with more instructions from the spec
defined tokens for C, M, Ziscr extensions.

separate the base RV32 instructions from the RV64, for potential future
re-use in a RV32-only assembler, from which the RV64-tok can #include

scall, sbreak have been renamed (page 7 of spec),
necessitating some renaming in riscv64-asm.c

riscv-spec-20191213.pdf was used,
in which the "V" extension is not yet ratified.
available under https://riscv.org/technical/specifications/

Tables 16.5–16.7 do not list any "scall"
neither does the privileged spec

3 additional tokens not present in the tables were removed

note that this riscv64-asm.c still contains defects, which will
be addressed in another commit
2023-08-10 14:25:03 +02:00
herman ten brugge cd627c6c40 Fix riscv assembler
riscv64-asm.c:
	asm_opcode: add return
	asm_parse_regvar: add abi register names

riscv64-tok.h:
	add abi register names
2022-06-07 20:53:14 +02:00
mingodad 1645616843 Revert "Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64"
This reverts commit af686a796b.
2021-10-22 07:39:54 +02:00
mingodad 2ce2dbcb09 Revert "Fix some errors on arm64-asm.c, rename some variables, fix several code style declarations"
This reverts commit 61537d899a.
2021-10-22 07:39:26 +02:00
mingodad 61537d899a Fix some errors on arm64-asm.c, rename some variables, fix several code style declarations 2021-10-22 07:20:00 +02:00
mingodad af686a796b Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64 2021-10-21 20:09:42 +02:00
Danny Milosavljevic 9b76a64f96 riscv64-asm: Implement asm_clobber 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 468f338e23 riscv64-asm: Optimize gen_le32 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 99189ea707 riscv64-asm: Implement asm_parse_regvar 2021-04-23 20:23:45 +02:00
Danny Milosavljevic b28bf50d2b riscv64-asm: Add beq, bne, blt, bge, bltu, bgeu 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 9c0760a4d4 riscv64-asm: Add lb, lh, lw, lbu, lhu, ld, lwu, sb, sh, sw, sd 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 1e37ec4917 riscv64-asm: Add add, addi, sub, addw, addd, addiw, addid, subw, subd, xor, xori, or, ori, and, andi, slt, slti, sltu, sltiu 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 8b1a89fbdf riscv64-asm: Add sll, slli, srl, srli, sra, srai, sllw, slld, slliw, sllid, srlw, srld, srliw, srlid, sraw, srad, sraiw, sraid 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 0b1cc489e1 riscv64-asm: Add lui, auipc 2021-04-23 20:23:45 +02:00
Danny Milosavljevic e5a898e510 riscv64-asm: Add rdcycle, rdcycleh, rdtime, rdtimeh, rdinstret, rdinstreth 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 4891ab71a0 riscv64-asm: Add fence, fence.i, scall, sbreak, ecall, ebreak, wfi 2021-04-23 20:23:45 +02:00
Danny Milosavljevic 7f3114ebba riscv64-asm: Remove asm_error 2021-04-23 20:23:45 +02:00
herman ten brugge 0b8ee7364a Add bound checking to arm, arm64 and riscv64
Checked on:
- i386/x86_64 (linux/windows)
- arm/arm64 (rapberry pi)
- riscv64 (simulator)
Not tested for arm softfloat because raspberry pi does not support it.

Modifications:

Makefile:
  add arm-asm.c to arm64_FILES
  add riscv64-asm.c (new file) to riscv64_FILES

lib/Makefile:
  add fetch_and_add_arm.o(new file) to ARM_O
  add fetch_and_add_arm64.o(new file) to ARM64_O
  add fetch_and_add_riscv64.o(new file) to RISCV64_O
  add $(BCHECK_O) to OBJ-arm/OBJ-arm64/OBJ-riscv64

tcc.h:
  Enable CONFIG_TCC_BCHECK for arm32/arm64/riscv64
  Add arm-asm.c, riscv64-asm.c

tcctok.h:
  for arm use memmove4 instead of memcpy4
  for arm use memmove8 instead of memcpy8

tccgen.c:
  put_extern_sym2: for arm check memcpy/memmove/memset/memmove4/memmove8
                   only use alloca for i386/x86_64
  for arm use memmove4 instead of memcpy4
  for arm use memmove8 instead of memcpy8
  fix builtin_frame_address/builtin_return_address for arm/riscv64

tccrun.c:
  Add riscv64 support
  fix rt_getcontext/rt_get_caller_pc for arm

tccelf.c:
  tcc_load_dll: Print filename for bad architecture

libtcc.c:
  add arm-asm.c/riscv64-asm.c

tcc-doc.texi:
  Add arm, arm64, riscv64 support for bound checking

lib/bcheck.c:
  add __bound___aeabi_memcpy/__bound___aeabi_memmove
      __bound___aeabi_memmove4/__bound___aeabi_memmove8
      __bound___aeabi_memset for arm
  call fetch_and_add_arm/fetch_and_add_arm64/fetch_and_add_riscv64
  __bound_init: Fix type for start/end/ad
  __bound_malloc/__bound_memalign/__bound_realloc/__bound_calloc: Use size + 1

arm-gen.c:
  add bound checking code like i386/x86_64
  assign_regs: only malloc if nb_args != 0
  gen_opi/gen_opf: Fix reload problems

arm-link.c:
  relocate_plt: Fix address calculating

arm64-gen.c:
  add bound checking code like i386/x86_64
  load/store: remove VT_BOUNDED from sv->r
  arm64_hfa_aux/arm64_hfa_aux: Fix array code
  gfunc_prolog: only malloc if n != 0

arm64-link.c:
  code_reloc/gotplt_entry_type/relocate: add R_AARCH64_LDST64_ABS_LO12_NC
  relocate: Use addXXle instead of writeXXle

riscv64-gen.c:
  add bound checking code like i386/x86_64
  add NB_ASM_REGS/CONFIG_TCC_ASM

riscv64-link.c:
  relocate: Use addXXle instead of writeXXle

i386-gen.c/x86_64-gen.c
  gen_bounds_epilog: Fix code (unrelated)

tests/Makefile:
  add $(BTESTS) for arm/arm64/riscv64

tests/tests2/Makefile:
  Use 85 only on i386/x86_64 because of asm code
  Use 113 only on i386/x86_64 because of DLL code
  Add 112/114/115/116 for arm/arm64/riscv64
  Fix FILTER (failed on riscv64)

tests/boundtest.c:
  Only use alloca for i386/x86_64
2020-06-16 07:39:48 +02:00