Skip to contentSkip to conversation

riscv: Add support for HI20 PE relocations

PATCH Applied Alexander Graf 2 participants 5 messages Jun 5, 2018 – Jun 12, 2018 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: Add support for HI20 PE relocations

The PE standard allows for HI20/LOW12 relocations. Within the efi_loader target we always know that our relocation target is 4k aligned, so we don't need to worry about the LOW12 part.

This patch adds support for the respective relocations. With this and a few grub patches I have cooking in parallel I'm able to run grub on RISC-V.

---
 include/pe.h                      |  3 +++
 lib/efi_loader/efi_image_loader.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
include/pe.h +3 -0
index d73eb142cb..36e1908b7e 100644
@@ -201,10 +201,13 @@ typedef struct _IMAGE_RELOCATION
 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
 #define IMAGE_REL_BASED_ARM_MOV32A              5 /* yes, 5 too */
 #define IMAGE_REL_BASED_ARM_MOV32               5 /* yes, 5 too */
+#define IMAGE_REL_BASED_RISCV_HI20		5 /* yes, 5 too */
 #define IMAGE_REL_BASED_SECTION                 6
 #define IMAGE_REL_BASED_REL                     7
 #define IMAGE_REL_BASED_ARM_MOV32T              7 /* yes, 7 too */
 #define IMAGE_REL_BASED_THUMB_MOV32             7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12I		7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12S		8
 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
 #define IMAGE_REL_BASED_DIR64                   10
lib/efi_loader/efi_image_loader.c +14 -0
index 3cffe9ef46..6892171ccd 100644
@@ -126,6 +126,20 @@ static efi_status_t efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
 			case IMAGE_REL_BASED_DIR64:
 				*x64 += (uint64_t)delta;
 				break;
+#ifdef __riscv
+			case IMAGE_REL_BASED_RISCV_HI20:
+				*x32 = ((*x32 & 0xfffff000) + (uint32_t)delta) |
+				        (*x32 & 0x00000fff);
+				break;
+			case IMAGE_REL_BASED_RISCV_LOW12I:
+			case IMAGE_REL_BASED_RISCV_LOW12S:
+				/* We know that we're 4k aligned */
+				if (delta & 0xfff) {
+					printf("Unsupported reloc offset\n");
+					return EFI_LOAD_ERROR;
+				}
+				break;
+#endif
 			default:
 				printf("Unknown Relocation off %x type %x\n",
 				       offset, type);
Signature · 1 line
2.12.3

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 1/1 riscv: Add support for HI20 PE relocations

Quoted 63 lines

-----Original Message-----
From: Alexander Graf [mailto:agraf at suse.de]
Sent: Wednesday, June 06, 2018 1:21 AM
To: u-boot at lists.denx.de
Cc: Rick Jian-Zhi Chen(陳建志)
Subject: [PATCH] riscv: Add support for HI20 PE relocations

The PE standard allows for HI20/LOW12 relocations. Within the efi_loader target we always know that our relocation target is 4k aligned, so we don't need to worry about the LOW12 part.

This patch adds support for the respective relocations. With this and a few grub patches I have cooking in parallel I'm able to run grub on RISC-V.

---
 include/pe.h                      |  3 +++
 lib/efi_loader/efi_image_loader.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
include/pe.h +3 -0
@@ -201,10 +201,13 @@ typedef struct _IMAGE_RELOCATION
 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
 #define IMAGE_REL_BASED_ARM_MOV32A              5 /* yes, 5 too */
 #define IMAGE_REL_BASED_ARM_MOV32               5 /* yes, 5 too */
+#define IMAGE_REL_BASED_RISCV_HI20           5 /* yes, 5 too */
 #define IMAGE_REL_BASED_SECTION                 6
 #define IMAGE_REL_BASED_REL                     7
 #define IMAGE_REL_BASED_ARM_MOV32T              7 /* yes, 7 too */
 #define IMAGE_REL_BASED_THUMB_MOV32             7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12I         7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12S         8
 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
 #define IMAGE_REL_BASED_DIR64                   10
lib/efi_loader/efi_image_loader.c +14 -0
index 3cffe9ef46..6892171ccd 100644
@@ -126,6 +126,20 @@ static efi_status_t efi_loader_relocate(const
 IMAGE_BASE_RELOCATION *rel,
                      case IMAGE_REL_BASED_DIR64:
                              *x64 += (uint64_t)delta;
                              break;
+#ifdef __riscv
+                     case IMAGE_REL_BASED_RISCV_HI20:
+                             *x32 = ((*x32 & 0xfffff000) + (uint32_t)delta) |
+                                     (*x32 & 0x00000fff);
+                             break;
+                     case IMAGE_REL_BASED_RISCV_LOW12I:
+                     case IMAGE_REL_BASED_RISCV_LOW12S:
+                             /* We know that we're 4k aligned */
+                             if (delta & 0xfff) {
+                                     printf("Unsupported reloc offset\n");
+                                     return EFI_LOAD_ERROR;
+                             }
+                             break;
+#endif
                      default:
                              printf("Unknown Relocation off %x type %x\n",
                                     offset, type);
Quoted 2 lines

--
2.12.3

Hi Alex

The title of this patch seems to be as" efi_loader: Add support for HI20 PE relocations for RISC-V "
And I am not sure if it shall belong to efi tree.

Rick

#3 lore raw

PATCH 1/1 riscv: Add support for HI20 PE relocations

Quoted 68 lines · Rick Chen
Quoted 63 lines

-----Original Message-----
From: Alexander Graf [mailto:agraf at suse.de]
Sent: Wednesday, June 06, 2018 1:21 AM
To: u-boot at lists.denx.de
Cc: Rick Jian-Zhi Chen(陳建志)
Subject: [PATCH] riscv: Add support for HI20 PE relocations

The PE standard allows for HI20/LOW12 relocations. Within the efi_loader target we always know that our relocation target is 4k aligned, so we don't need to worry about the LOW12 part.

This patch adds support for the respective relocations. With this and a few grub patches I have cooking in parallel I'm able to run grub on RISC-V.

---
 include/pe.h                      |  3 +++
 lib/efi_loader/efi_image_loader.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
include/pe.h +3 -0
@@ -201,10 +201,13 @@ typedef struct _IMAGE_RELOCATION
 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
 #define IMAGE_REL_BASED_ARM_MOV32A              5 /* yes, 5 too */
 #define IMAGE_REL_BASED_ARM_MOV32               5 /* yes, 5 too */
+#define IMAGE_REL_BASED_RISCV_HI20           5 /* yes, 5 too */
 #define IMAGE_REL_BASED_SECTION                 6
 #define IMAGE_REL_BASED_REL                     7
 #define IMAGE_REL_BASED_ARM_MOV32T              7 /* yes, 7 too */
 #define IMAGE_REL_BASED_THUMB_MOV32             7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12I         7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12S         8
 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
 #define IMAGE_REL_BASED_DIR64                   10
lib/efi_loader/efi_image_loader.c +14 -0
index 3cffe9ef46..6892171ccd 100644
@@ -126,6 +126,20 @@ static efi_status_t efi_loader_relocate(const
 IMAGE_BASE_RELOCATION *rel,
                      case IMAGE_REL_BASED_DIR64:
                              *x64 += (uint64_t)delta;
                              break;
+#ifdef __riscv
+                     case IMAGE_REL_BASED_RISCV_HI20:
+                             *x32 = ((*x32 & 0xfffff000) + (uint32_t)delta) |
+                                     (*x32 & 0x00000fff);
+                             break;
+                     case IMAGE_REL_BASED_RISCV_LOW12I:
+                     case IMAGE_REL_BASED_RISCV_LOW12S:
+                             /* We know that we're 4k aligned */
+                             if (delta & 0xfff) {
+                                     printf("Unsupported reloc offset\n");
+                                     return EFI_LOAD_ERROR;
+                             }
+                             break;
+#endif
                      default:
                              printf("Unknown Relocation off %x type %x\n",
                                     offset, type);
Quoted 2 lines

--
2.12.3

Hi Alex

Quoted 3 lines

The title of this patch seems to be as" efi_loader: Add support for HI20 PE relocations for RISC-V "
And I am not sure if it shall belong to efi tree.

I'll be happy to take it via the efi tree, yes. It only affects the efi PE loader.

Alex

#4 lore raw

PATCH 1/1 riscv: Add support for HI20 PE relocations

2018-06-06 17:18 GMT+08:00 Alexander Graf <[email protected]>:

Quoted 71 lines · Rick Chen
Quoted 68 lines
Quoted 63 lines

-----Original Message-----
From: Alexander Graf [mailto:agraf at suse.de]
Sent: Wednesday, June 06, 2018 1:21 AM
To: u-boot at lists.denx.de
Cc: Rick Jian-Zhi Chen(陳建志)
Subject: [PATCH] riscv: Add support for HI20 PE relocations

The PE standard allows for HI20/LOW12 relocations. Within the efi_loader target we always know that our relocation target is 4k aligned, so we don't need to worry about the LOW12 part.

This patch adds support for the respective relocations. With this and a few grub patches I have cooking in parallel I'm able to run grub on RISC-V.

---
 include/pe.h                      |  3 +++
 lib/efi_loader/efi_image_loader.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
include/pe.h +3 -0
@@ -201,10 +201,13 @@ typedef struct _IMAGE_RELOCATION
 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
 #define IMAGE_REL_BASED_ARM_MOV32A              5 /* yes, 5 too */
 #define IMAGE_REL_BASED_ARM_MOV32               5 /* yes, 5 too */
+#define IMAGE_REL_BASED_RISCV_HI20           5 /* yes, 5 too */
 #define IMAGE_REL_BASED_SECTION                 6
 #define IMAGE_REL_BASED_REL                     7
 #define IMAGE_REL_BASED_ARM_MOV32T              7 /* yes, 7 too */
 #define IMAGE_REL_BASED_THUMB_MOV32             7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12I         7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12S         8
 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
 #define IMAGE_REL_BASED_DIR64                   10
lib/efi_loader/efi_image_loader.c +14 -0
index 3cffe9ef46..6892171ccd 100644
@@ -126,6 +126,20 @@ static efi_status_t efi_loader_relocate(const
 IMAGE_BASE_RELOCATION *rel,
                      case IMAGE_REL_BASED_DIR64:
                              *x64 += (uint64_t)delta;
                              break;
+#ifdef __riscv
+                     case IMAGE_REL_BASED_RISCV_HI20:
+                             *x32 = ((*x32 & 0xfffff000) + (uint32_t)delta) |
+                                     (*x32 & 0x00000fff);
+                             break;
+                     case IMAGE_REL_BASED_RISCV_LOW12I:
+                     case IMAGE_REL_BASED_RISCV_LOW12S:
+                             /* We know that we're 4k aligned */
+                             if (delta & 0xfff) {
+                                     printf("Unsupported reloc offset\n");
+                                     return EFI_LOAD_ERROR;
+                             }
+                             break;
+#endif
                      default:
                              printf("Unknown Relocation off %x type %x\n",
                                     offset, type);
Quoted 2 lines

--
2.12.3

Hi Alex

Quoted 8 lines
Quoted 3 lines

The title of this patch seems to be as" efi_loader: Add support for HI20 PE relocations for RISC-V "
And I am not sure if it shall belong to efi tree.

I'll be happy to take it via the efi tree, yes. It only affects the efi PE loader.

Hi Alex

Thanks a lot. :)

Rick

Quoted 1 line

Alex

author Applied
#5 lore raw
In reply to Alexander Graf
Quoted 8 lines

The PE standard allows for HI20/LOW12 relocations. Within the efi_loader target we always know that our relocation target is 4k aligned, so we don't need to worry about the LOW12 part.

This patch adds support for the respective relocations. With this and a few grub patches I have cooking in parallel I'm able to run grub on RISC-V.

Thanks, applied to efi-next

Alex