From 2969acf50d7415064057b003a0a91be4c757a471 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Thu, 8 Aug 2024 14:34:40 +0100 Subject: [PATCH] RISC-V: add `R_RISCV_32` and `R_RISCV_64` relocations --- src/ArchC-RISCV/R_RISCV_32.class.st | 41 +++++++++++++++++++++++++++++ src/ArchC-RISCV/R_RISCV_64.class.st | 41 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/ArchC-RISCV/R_RISCV_32.class.st create mode 100644 src/ArchC-RISCV/R_RISCV_64.class.st diff --git a/src/ArchC-RISCV/R_RISCV_32.class.st b/src/ArchC-RISCV/R_RISCV_32.class.st new file mode 100644 index 0000000..a46e121 --- /dev/null +++ b/src/ArchC-RISCV/R_RISCV_32.class.st @@ -0,0 +1,41 @@ +Class { + #name : #'R_RISCV_32', + #superclass : #AcRelocation, + #pools : [ + 'AcIntLimits' + ], + #category : #'ArchC-RISCV-Relocations' +} + +{ #category : #queries } +R_RISCV_32 class >> isValidForInstruction: insn [ + ^ insn class == AcInt32 + and: [ insn isa architectureName = 'riscv32' ] +] + +{ #category : #'processing - simplified' } +R_RISCV_32 >> calculateS: s A: a P: p [ + " + https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#relocations + + 32-bit relocation + + " + | v | + + v := s + a. + + (v between: UINT32_MIN and: UINT32_MAX) ifFalse:[ ^ AddressOutOfRange ]. + + ^ v +] + +{ #category : #'processing - simplified' } +R_RISCV_32 >> fixup: memory at: address with: value [ + | addr | + + addr := ByteArray new: 4. + addr unsignedLongAt: 1 put: value. + + memory replaceFrom: address to: address + 4 - 1 with: addr. +] diff --git a/src/ArchC-RISCV/R_RISCV_64.class.st b/src/ArchC-RISCV/R_RISCV_64.class.st new file mode 100644 index 0000000..5b997b2 --- /dev/null +++ b/src/ArchC-RISCV/R_RISCV_64.class.st @@ -0,0 +1,41 @@ +Class { + #name : #'R_RISCV_64', + #superclass : #AcRelocation, + #pools : [ + 'AcIntLimits' + ], + #category : #'ArchC-RISCV-Relocations' +} + +{ #category : #queries } +R_RISCV_64 class >> isValidForInstruction: insn [ + ^ insn class == AcInt64 + and: [ insn isa architectureName = 'riscv64' ] +] + +{ #category : #'processing - simplified' } +R_RISCV_64 >> calculateS: s A: a P: p [ + " + https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#relocations + + 64-bit relocation + + " + | v | + + v := s + a. + + (v between: UINT64_MIN and: UINT64_MAX) ifFalse:[ ^ AddressOutOfRange ]. + + ^ v +] + +{ #category : #'processing - simplified' } +R_RISCV_64 >> fixup: memory at: address with: value [ + | addr | + + addr := ByteArray new: 8. + addr unsignedLongLongAt: 1 put: value. + + memory replaceFrom: address to: address + 8 - 1 with: addr. +]