-
Notifications
You must be signed in to change notification settings - Fork 7
/
riscv_2.patch
97 lines (91 loc) · 3.61 KB
/
riscv_2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Subject: [PATCH] BaseTools GenFw: Add support for R_RISCV_PCREL_LO12_S relocation
From: Sunil V L <[email protected]>
Date: 2021.07.10, 07:31
CC: [email protected], Sunil V L <[email protected]>, Liming Gao <[email protected]>, Bob Feng <[email protected]>, Yuwei Chen <[email protected]>, Pete Batard <[email protected]>, Abner Chang <[email protected]>, Daniel Schaefer <[email protected]>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3459
This patch adds support for R_RISCV_PCREL_LO12_S relocation type.
The logic is same as existing R_RISCV_PCREL_LO12_I relocation
except the difference between load vs store instruction formats.
Signed-off-by: Sunil V L <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Bob Feng <[email protected]>
Cc: Yuwei Chen <[email protected]>
Cc: Pete Batard <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Daniel Schaefer <[email protected]>
---
BaseTools/Source/C/GenFw/Elf64Convert.c | 55 +++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
index 3d7e20aaff..0bb3ead228 100644
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -557,6 +557,60 @@ WriteSectionRiscV64 (
Value = (UINT32)(RV_X(*(UINT32 *)mRiscVPass1Targ, 12, 20));
break;
+ case R_RISCV_PCREL_LO12_S:
+ if (mRiscVPass1Targ != NULL && mRiscVPass1Sym != NULL && mRiscVPass1SymSecIndex != 0) {
+ int i;
+ Value2 = (UINT32)(RV_X(*(UINT32 *)mRiscVPass1Targ, 12, 20));
+
+ Value = ((UINT32)(RV_X(*(UINT32 *)Targ, 25, 7)) << 5);
+ Value = (Value | (UINT32)(RV_X(*(UINT32 *)Targ, 7, 5)));
+
+ if(Value & (RISCV_IMM_REACH/2)) {
+ Value |= ~(RISCV_IMM_REACH-1);
+ }
+ Value = Value - (UINT32)mRiscVPass1Sym->sh_addr + mCoffSectionsOffset[mRiscVPass1SymSecIndex];
+
+ if(-2048 > (INT32)Value) {
+ i = (((INT32)Value * -1) / 4096);
+ Value2 -= i;
+ Value += 4096 * i;
+ if(-2048 > (INT32)Value) {
+ Value2 -= 1;
+ Value += 4096;
+ }
+ }
+ else if( 2047 < (INT32)Value) {
+ i = (Value / 4096);
+ Value2 += i;
+ Value -= 4096 * i;
+ if(2047 < (INT32)Value) {
+ Value2 += 1;
+ Value -= 4096;
+ }
+ }
+
+ // Update the IMM of SD instruction
+ //
+ // |31 25|24 20|19 15|14 12 |11 7|6 0|
+ // |-------------------------------------------|-------|
+ // |imm[11:5] | rs2 | rs1 | funct3 |imm[4:0] | opcode|
+ // ---------------------------------------------------
+
+ // First Zero out current IMM
+ *(UINT32 *)Targ &= ~0xfe000f80;
+
+ // Update with new IMM
+ *(UINT32 *)Targ |= (RV_X(Value, 5, 7) << 25);
+ *(UINT32 *)Targ |= (RV_X(Value, 0, 5) << 7);
+
+ // Update previous instruction
+ *(UINT32 *)mRiscVPass1Targ = (RV_X(Value2, 0, 20)<<12) | (RV_X(*(UINT32 *)mRiscVPass1Targ, 0, 12));
+ }
+ mRiscVPass1Sym = NULL;
+ mRiscVPass1Targ = NULL;
+ mRiscVPass1SymSecIndex = 0;
+ break;
+
case R_RISCV_PCREL_LO12_I:
if (mRiscVPass1Targ != NULL && mRiscVPass1Sym != NULL && mRiscVPass1SymSecIndex != 0) {
int i;
@@ -1587,6 +1641,7 @@ WriteRelocations64 (
case R_RISCV_PCREL_HI20:
case R_RISCV_GOT_HI20:
case R_RISCV_PCREL_LO12_I:
+ case R_RISCV_PCREL_LO12_S:
break;
default:
-- 2.32.0