Skip to contentSkip to conversation

hw/mips: Code simplifications

PATCH Applied Philippe Mathieu-Daudé 2 participants 7 messages Sep 27, 2020 – Oct 7, 2020

lore
Share & tools
lore
#0 lore raw

cover hw/mips: Code simplifications

Doing housekeeping on old branches older than 1 year. Some patches are still valuable, so post them.

These patches should not introduce logical change, they simply rewrite old style code using more recent API/macros.

Philippe Mathieu-Daudé (2):
hw/mips: Simplify loading 64-bit ELF kernels hw/mips: Simplify code using ROUND_UP(INITRD_PAGE_SIZE)

 include/hw/mips/mips.h | 4 +++-
 hw/mips/fuloong2e.c    | 3 +--
 hw/mips/malta.c        | 6 +++---
 hw/mips/mipssim.c      | 9 ++-------
 hw/mips/r4k.c          | 9 ++-------
 5 files changed, 11 insertions(+), 20 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 hw/mips: Simplify loading 64-bit ELF kernels

Since 82790064116 ("Cast ELF datatypes properly to host 64bit types") we don't need to sign-extend the entry_point address. Remove this unnecessary code.

---
 hw/mips/mipssim.c | 6 +-----
 hw/mips/r4k.c     | 6 +-----
 2 files changed, 2 insertions(+), 10 deletions(-)
hw/mips/mipssim.c +1 -5
index 1b3b7622035..3aeb1207e1a 100644
@@ -76,11 +76,7 @@ static int64_t load_kernel(void)
                            (uint64_t *)&entry, NULL,
                            (uint64_t *)&kernel_high, NULL, big_endian,
                            EM_MIPS, 1, 0);
-    if (kernel_size >= 0) {
-        if ((entry & ~0x7fffffffULL) == 0x80000000) {
-            entry = (int32_t)entry;
-        }
-    } else {
+    if (kernel_size < 0) {
         error_report("could not load kernel '%s': %s",
                      loaderparams.kernel_filename,
                      load_elf_strerror(kernel_size));
hw/mips/r4k.c +1 -5
index 3487013a4a1..74f916a3982 100644
@@ -101,11 +101,7 @@ static int64_t load_kernel(void)
                            (uint64_t *)&entry, NULL,
                            (uint64_t *)&kernel_high, NULL, big_endian,
                            EM_MIPS, 1, 0);
-    if (kernel_size >= 0) {
-        if ((entry & ~0x7fffffffULL) == 0x80000000) {
-            entry = (int32_t)entry;
-        }
-    } else {
+    if (kernel_size < 0) {
         error_report("could not load kernel '%s': %s",
                      loaderparams.kernel_filename,
                      load_elf_strerror(kernel_size));
Signature · 1 line
2.26.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] hw/mips: Simplify loading 64-bit ELF kernels

Quoted 9 lines · Philippe Mathieu-Daudé

Since 82790064116 ("Cast ELF datatypes properly to host 64bit types") we don't need to sign-extend the entry_point address. Remove this unnecessary code.

---
 hw/mips/mipssim.c | 6 +-----
 hw/mips/r4k.c     | 6 +-----
 2 files changed, 2 insertions(+), 10 deletions(-)

r~

#3 lore raw

PATCH 2/2 hw/mips: Simplify code using ROUND_UP(INITRD_PAGE_SIZE)

In reply to Philippe Mathieu-Daudé

Instead of using a INITRD_PAGE_MASK definition, use the simpler INITRD_PAGE_SIZE one which allows us to simplify the code by using directly the self-explicit ROUND_UP() macro.

---
 include/hw/mips/mips.h | 4 +++-
 hw/mips/fuloong2e.c    | 3 +--
 hw/mips/malta.c        | 6 +++---
 hw/mips/mipssim.c      | 3 +--
 hw/mips/r4k.c          | 3 +--
 5 files changed, 9 insertions(+), 10 deletions(-)
include/hw/mips/mips.h +3 -1
index 0af4c3d5d74..6c9c8805f3f 100644
@@ -2,8 +2,10 @@
 #define HW_MIPS_H
 /* Definitions for mips board emulation.  */
 
+#include "qemu/units.h"
+
 /* Kernels can be configured with 64KB pages */
-#define INITRD_PAGE_MASK (~((1 << 16) - 1))
+#define INITRD_PAGE_SIZE (64 * KiB)
 
 #include "exec/memory.h"
 
hw/mips/fuloong2e.c +1 -2
index f28609976bf..ef5dbe97b7d 100644
@@ -132,8 +132,7 @@ static int64_t load_kernel(CPUMIPSState *env)
     if (loaderparams.initrd_filename) {
         initrd_size = get_image_size(loaderparams.initrd_filename);
         if (initrd_size > 0) {
-            initrd_offset = (kernel_high + ~INITRD_PAGE_MASK) &
-                            INITRD_PAGE_MASK;
+            initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE);
             if (initrd_offset + initrd_size > ram_size) {
                 error_report("memory too small for initial ram disk '%s'",
                              loaderparams.initrd_filename);
hw/mips/malta.c +3 -3
index 4019c9dc1a8..5de5cb152eb 100644
@@ -1074,9 +1074,9 @@ static int64_t load_kernel(void)
              * the initrd.  It takes at most 128kiB for 2GB RAM and 4kiB
              * pages.
              */
-            initrd_offset = (loaderparams.ram_low_size - initrd_size
-                             - (128 * KiB)
-                             - ~INITRD_PAGE_MASK) & INITRD_PAGE_MASK;
+            initrd_offset = ROUND_UP(loaderparams.ram_low_size
+                                     - (initrd_size + 128 * KiB),
+                                     INITRD_PAGE_SIZE);
             if (kernel_high >= initrd_offset) {
                 error_report("memory too small for initial ram disk '%s'",
                              loaderparams.initrd_filename);
hw/mips/mipssim.c +1 -2
index 3aeb1207e1a..1862eeda396 100644
@@ -89,8 +89,7 @@ static int64_t load_kernel(void)
     if (loaderparams.initrd_filename) {
         initrd_size = get_image_size(loaderparams.initrd_filename);
         if (initrd_size > 0) {
-            initrd_offset = (kernel_high + ~INITRD_PAGE_MASK) &
-                            INITRD_PAGE_MASK;
+            initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE);
             if (initrd_offset + initrd_size > loaderparams.ram_size) {
                 error_report("memory too small for initial ram disk '%s'",
                              loaderparams.initrd_filename);
hw/mips/r4k.c +1 -2
index 74f916a3982..24cee357f34 100644
@@ -114,8 +114,7 @@ static int64_t load_kernel(void)
     if (loaderparams.initrd_filename) {
         initrd_size = get_image_size(loaderparams.initrd_filename);
         if (initrd_size > 0) {
-            initrd_offset = (kernel_high + ~INITRD_PAGE_MASK) &
-                             INITRD_PAGE_MASK;
+            initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE);
             if (initrd_offset + initrd_size > ram_size) {
                 error_report("memory too small for initial ram disk '%s'",
                              loaderparams.initrd_filename);
Signature · 1 line
2.26.2
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] hw/mips: Simplify code using ROUND_UP(INITRD_PAGE_SIZE)

Quoted 5 lines · Philippe Mathieu-Daudé

Instead of using a INITRD_PAGE_MASK definition, use the simpler INITRD_PAGE_SIZE one which allows us to simplify the code by using directly the self-explicit ROUND_UP() macro.

Quoted 8 lines
---
 include/hw/mips/mips.h | 4 +++-
 hw/mips/fuloong2e.c    | 3 +--
 hw/mips/malta.c        | 6 +++---
 hw/mips/mipssim.c      | 3 +--
 hw/mips/r4k.c          | 3 +--
 5 files changed, 9 insertions(+), 10 deletions(-)

r~

#5 lore raw
In reply to Philippe Mathieu-Daudé

ping?

Quoted 18 lines · Philippe Mathieu-Daudé

Doing housekeeping on old branches older than 1 year. Some patches are still valuable, so post them.

These patches should not introduce logical change, they simply rewrite old style code using more recent API/macros.

Philippe Mathieu-Daudé (2):
hw/mips: Simplify loading 64-bit ELF kernels hw/mips: Simplify code using ROUND_UP(INITRD_PAGE_SIZE)

 include/hw/mips/mips.h | 4 +++-
 hw/mips/fuloong2e.c    | 3 +--
 hw/mips/malta.c        | 6 +++---
 hw/mips/mipssim.c      | 9 ++-------
 hw/mips/r4k.c          | 9 ++-------
 5 files changed, 11 insertions(+), 20 deletions(-)
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Doing housekeeping on old branches older than 1 year. Some patches are still valuable, so post them.

These patches should not introduce logical change, they simply rewrite old style code using more recent API/macros.

Philippe Mathieu-Daudé (2):
hw/mips: Simplify loading 64-bit ELF kernels hw/mips: Simplify code using ROUND_UP(INITRD_PAGE_SIZE)

Quoted 6 lines
 include/hw/mips/mips.h | 4 +++-
 hw/mips/fuloong2e.c    | 3 +--
 hw/mips/malta.c        | 6 +++---
 hw/mips/mipssim.c      | 9 ++-------
 hw/mips/r4k.c          | 9 ++-------
 5 files changed, 11 insertions(+), 20 deletions(-)

Thanks, applied to mips-hw-next.