hw/mips: Evaluate TARGET_BIG_ENDIAN at compile time

Rather than evaluating TARGET_BIG_ENDIAN at preprocessing
time via #ifdef'ry, do it in C at compile time

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250417131004.47205-7-philmd@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé 2025-04-16 14:33:06 +02:00
parent 770f2e64b6
commit 1b079a6eeb
3 changed files with 14 additions and 29 deletions

View file

@ -59,12 +59,6 @@ enum jazz_model_e {
JAZZ_PICA61, JAZZ_PICA61,
}; };
#if TARGET_BIG_ENDIAN
#define BIOS_FILENAME "mips_bios.bin"
#else
#define BIOS_FILENAME "mipsel_bios.bin"
#endif
static void main_cpu_reset(void *opaque) static void main_cpu_reset(void *opaque)
{ {
MIPSCPU *cpu = opaque; MIPSCPU *cpu = opaque;
@ -168,6 +162,8 @@ static void mips_jazz_init_net(IOMMUMemoryRegion *rc4030_dma_mr,
static void mips_jazz_init(MachineState *machine, static void mips_jazz_init(MachineState *machine,
enum jazz_model_e jazz_model) enum jazz_model_e jazz_model)
{ {
const char *bios_name = TARGET_BIG_ENDIAN ? "mips_bios.bin"
: "mipsel_bios.bin";
MemoryRegion *address_space = get_system_memory(); MemoryRegion *address_space = get_system_memory();
char *filename; char *filename;
int bios_size, n; int bios_size, n;
@ -245,7 +241,8 @@ static void mips_jazz_init(MachineState *machine,
memory_region_add_subregion(address_space, 0xfff00000LL, bios2); memory_region_add_subregion(address_space, 0xfff00000LL, bios2);
/* load the BIOS image. */ /* load the BIOS image. */
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, machine->firmware ?: BIOS_FILENAME); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
machine->firmware ?: bios_name);
if (filename) { if (filename) {
bios_size = load_image_targphys(filename, 0xfff00000LL, bios_size = load_image_targphys(filename, 0xfff00000LL,
MAGNUM_BIOS_SIZE); MAGNUM_BIOS_SIZE);

View file

@ -94,12 +94,6 @@ typedef struct {
bool display_inited; bool display_inited;
} MaltaFPGAState; } MaltaFPGAState;
#if TARGET_BIG_ENDIAN
#define BIOS_FILENAME "mips_bios.bin"
#else
#define BIOS_FILENAME "mipsel_bios.bin"
#endif
#define TYPE_MIPS_MALTA "mips-malta" #define TYPE_MIPS_MALTA "mips-malta"
OBJECT_DECLARE_SIMPLE_TYPE(MaltaState, MIPS_MALTA) OBJECT_DECLARE_SIMPLE_TYPE(MaltaState, MIPS_MALTA)
@ -383,11 +377,7 @@ static uint64_t malta_fpga_read(void *opaque, hwaddr addr,
/* STATUS Register */ /* STATUS Register */
case 0x00208: case 0x00208:
#if TARGET_BIG_ENDIAN val = TARGET_BIG_ENDIAN ? 0x00000012 : 0x00000010;
val = 0x00000012;
#else
val = 0x00000010;
#endif
break; break;
/* JMPRS Register */ /* JMPRS Register */
@ -1177,9 +1167,12 @@ void mips_malta_init(MachineState *machine)
target_long bios_size = FLASH_SIZE; target_long bios_size = FLASH_SIZE;
/* Load firmware from flash. */ /* Load firmware from flash. */
if (!dinfo) { if (!dinfo) {
const char *bios_name = TARGET_BIG_ENDIAN ? "mips_bios.bin"
: "mipsel_bios.bin";
/* Load a BIOS image. */ /* Load a BIOS image. */
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
machine->firmware ?: BIOS_FILENAME); machine->firmware ?: bios_name);
if (filename) { if (filename) {
bios_size = load_image_targphys(filename, FLASH_ADDRESS, bios_size = load_image_targphys(filename, FLASH_ADDRESS,
BIOS_SIZE); BIOS_SIZE);
@ -1197,8 +1190,7 @@ void mips_malta_init(MachineState *machine)
* In little endian mode the 32bit words in the bios are swapped, * In little endian mode the 32bit words in the bios are swapped,
* a neat trick which allows bi-endian firmware. * a neat trick which allows bi-endian firmware.
*/ */
#if !TARGET_BIG_ENDIAN if (!TARGET_BIG_ENDIAN) {
{
uint32_t *end, *addr; uint32_t *end, *addr;
const size_t swapsize = MIN(bios_size, 0x3e0000); const size_t swapsize = MIN(bios_size, 0x3e0000);
addr = rom_ptr(FLASH_ADDRESS, swapsize); addr = rom_ptr(FLASH_ADDRESS, swapsize);
@ -1211,7 +1203,6 @@ void mips_malta_init(MachineState *machine)
addr++; addr++;
} }
} }
#endif
} }
/* /*

View file

@ -46,12 +46,6 @@
#define BIOS_SIZE (4 * MiB) #define BIOS_SIZE (4 * MiB)
#if TARGET_BIG_ENDIAN
#define BIOS_FILENAME "mips_bios.bin"
#else
#define BIOS_FILENAME "mipsel_bios.bin"
#endif
static struct _loaderparams { static struct _loaderparams {
int ram_size; int ram_size;
const char *kernel_filename; const char *kernel_filename;
@ -143,6 +137,8 @@ mips_mipssim_init(MachineState *machine)
const char *kernel_filename = machine->kernel_filename; const char *kernel_filename = machine->kernel_filename;
const char *kernel_cmdline = machine->kernel_cmdline; const char *kernel_cmdline = machine->kernel_cmdline;
const char *initrd_filename = machine->initrd_filename; const char *initrd_filename = machine->initrd_filename;
const char *bios_name = TARGET_BIG_ENDIAN ? "mips_bios.bin"
: "mipsel_bios.bin";
char *filename; char *filename;
MemoryRegion *address_space_mem = get_system_memory(); MemoryRegion *address_space_mem = get_system_memory();
MemoryRegion *isa = g_new(MemoryRegion, 1); MemoryRegion *isa = g_new(MemoryRegion, 1);
@ -179,7 +175,8 @@ mips_mipssim_init(MachineState *machine)
/* Map the BIOS / boot exception handler. */ /* Map the BIOS / boot exception handler. */
memory_region_add_subregion(address_space_mem, 0x1fc00000LL, bios); memory_region_add_subregion(address_space_mem, 0x1fc00000LL, bios);
/* Load a BIOS / boot exception handler image. */ /* Load a BIOS / boot exception handler image. */
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, machine->firmware ?: BIOS_FILENAME); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
machine->firmware ?: bios_name);
if (filename) { if (filename) {
bios_size = load_image_targphys(filename, 0x1fc00000LL, BIOS_SIZE); bios_size = load_image_targphys(filename, 0x1fc00000LL, BIOS_SIZE);
g_free(filename); g_free(filename);