hw/mips: Code simplifications
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
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
@@ -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
@@ -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
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_pointaddress. Remove this unnecessary code.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/mips/mipssim.c | 6 +----- hw/mips/r4k.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-)
r~
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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_MASKdefinition, use the simplerINITRD_PAGE_SIZEone which allows us to simplify the code by using directly the self-explicitROUND_UP()macro.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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~
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 usingROUND_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(-)
Philippe Mathieu-Daudé
AppliedQuoted 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 usingROUND_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.