Skip to content

Commit ded625e

Browse files
huthMichael Tokarev
authored andcommitted
trivial: Simplify the spots that use TARGET_BIG_ENDIAN as a numeric value
TARGET_BIG_ENDIAN is *always* defined, either as 0 for little endian targets or as 1 for big endian targets. So we can use this as a value directly in places that need such a 0 or 1 for some reason, instead of taking a detour through an additional local variable or something similar. Suggested-by: Peter Maydell <[email protected]> Signed-off-by: Thomas Huth <[email protected]> Reviewed-by: Peter Maydell <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Michael Tokarev <[email protected]>
1 parent d417e22 commit ded625e

File tree

9 files changed

+18
-75
lines changed

9 files changed

+18
-75
lines changed

cpu.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
420420

421421
bool target_words_bigendian(void)
422422
{
423-
#if TARGET_BIG_ENDIAN
424-
return true;
425-
#else
426-
return false;
427-
#endif
423+
return TARGET_BIG_ENDIAN;
428424
}
429425

430426
const char *target_name(void)

hw/microblaze/boot.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,17 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,
140140
int kernel_size;
141141
uint64_t entry, high;
142142
uint32_t base32;
143-
int big_endian = 0;
144-
145-
#if TARGET_BIG_ENDIAN
146-
big_endian = 1;
147-
#endif
148143

149144
/* Boots a kernel elf binary. */
150145
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
151146
&entry, NULL, &high, NULL,
152-
big_endian, EM_MICROBLAZE, 0, 0);
147+
TARGET_BIG_ENDIAN, EM_MICROBLAZE, 0, 0);
153148
base32 = entry;
154149
if (base32 == 0xc0000000) {
155150
kernel_size = load_elf(kernel_filename, NULL,
156151
translate_kernel_address, NULL,
157152
&entry, NULL, NULL, NULL,
158-
big_endian, EM_MICROBLAZE, 0, 0);
153+
TARGET_BIG_ENDIAN, EM_MICROBLAZE, 0, 0);
159154
}
160155
/* Always boot into physical ram. */
161156
boot_info.bootstrap_pc = (uint32_t)entry;

hw/mips/jazz.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void mips_jazz_init(MachineState *machine,
125125
{
126126
MemoryRegion *address_space = get_system_memory();
127127
char *filename;
128-
int bios_size, n, big_endian;
128+
int bios_size, n;
129129
Clock *cpuclk;
130130
MIPSCPU *cpu;
131131
MIPSCPUClass *mcc;
@@ -157,12 +157,6 @@ static void mips_jazz_init(MachineState *machine,
157157
[JAZZ_PICA61] = {33333333, 4},
158158
};
159159

160-
#if TARGET_BIG_ENDIAN
161-
big_endian = 1;
162-
#else
163-
big_endian = 0;
164-
#endif
165-
166160
if (machine->ram_size > 256 * MiB) {
167161
error_report("RAM size more than 256Mb is not supported");
168162
exit(EXIT_FAILURE);
@@ -301,7 +295,7 @@ static void mips_jazz_init(MachineState *machine,
301295
dev = qdev_new("dp8393x");
302296
qdev_set_nic_properties(dev, nd);
303297
qdev_prop_set_uint8(dev, "it_shift", 2);
304-
qdev_prop_set_bit(dev, "big_endian", big_endian > 0);
298+
qdev_prop_set_bit(dev, "big_endian", TARGET_BIG_ENDIAN);
305299
object_property_set_link(OBJECT(dev), "dma_mr",
306300
OBJECT(rc4030_dma_mr), &error_abort);
307301
sysbus = SYS_BUS_DEVICE(dev);

hw/mips/malta.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -870,24 +870,17 @@ static uint64_t load_kernel(void)
870870
uint64_t kernel_entry, kernel_high, initrd_size;
871871
long kernel_size;
872872
ram_addr_t initrd_offset;
873-
int big_endian;
874873
uint32_t *prom_buf;
875874
long prom_size;
876875
int prom_index = 0;
877876
uint8_t rng_seed[32];
878877
char rng_seed_hex[sizeof(rng_seed) * 2 + 1];
879878
size_t rng_seed_prom_offset;
880879

881-
#if TARGET_BIG_ENDIAN
882-
big_endian = 1;
883-
#else
884-
big_endian = 0;
885-
#endif
886-
887880
kernel_size = load_elf(loaderparams.kernel_filename, NULL,
888881
cpu_mips_kseg0_to_phys, NULL,
889882
&kernel_entry, NULL,
890-
&kernel_high, NULL, big_endian, EM_MIPS,
883+
&kernel_high, NULL, TARGET_BIG_ENDIAN, EM_MIPS,
891884
1, 0);
892885
if (kernel_size < 0) {
893886
error_report("could not load kernel '%s': %s",
@@ -1107,7 +1100,6 @@ void mips_malta_init(MachineState *machine)
11071100
I2CBus *smbus;
11081101
DriveInfo *dinfo;
11091102
int fl_idx = 0;
1110-
int be;
11111103
MaltaState *s;
11121104
PCIDevice *piix4;
11131105
DeviceState *dev;
@@ -1144,12 +1136,6 @@ void mips_malta_init(MachineState *machine)
11441136
ram_low_postio);
11451137
}
11461138

1147-
#if TARGET_BIG_ENDIAN
1148-
be = 1;
1149-
#else
1150-
be = 0;
1151-
#endif
1152-
11531139
/* FPGA */
11541140

11551141
/* The CBUS UART is attached to the MIPS CPU INT2 pin, ie interrupt 4 */
@@ -1161,7 +1147,8 @@ void mips_malta_init(MachineState *machine)
11611147
FLASH_SIZE,
11621148
dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
11631149
65536,
1164-
4, 0x0000, 0x0000, 0x0000, 0x0000, be);
1150+
4, 0x0000, 0x0000, 0x0000, 0x0000,
1151+
TARGET_BIG_ENDIAN);
11651152
bios = pflash_cfi01_get_memory(fl);
11661153
fl_idx++;
11671154
if (kernel_filename) {
@@ -1245,7 +1232,7 @@ void mips_malta_init(MachineState *machine)
12451232

12461233
/* Northbridge */
12471234
dev = qdev_new("gt64120");
1248-
qdev_prop_set_bit(dev, "cpu-little-endian", !be);
1235+
qdev_prop_set_bit(dev, "cpu-little-endian", !TARGET_BIG_ENDIAN);
12491236
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
12501237
pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci"));
12511238
pci_bus_map_irqs(pci_bus, malta_pci_slot_get_pirq);

hw/mips/mipssim.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,11 @@ static uint64_t load_kernel(void)
6262
uint64_t entry, kernel_high, initrd_size;
6363
long kernel_size;
6464
ram_addr_t initrd_offset;
65-
int big_endian;
66-
67-
#if TARGET_BIG_ENDIAN
68-
big_endian = 1;
69-
#else
70-
big_endian = 0;
71-
#endif
7265

7366
kernel_size = load_elf(loaderparams.kernel_filename, NULL,
7467
cpu_mips_kseg0_to_phys, NULL,
7568
&entry, NULL,
76-
&kernel_high, NULL, big_endian,
69+
&kernel_high, NULL, TARGET_BIG_ENDIAN,
7770
EM_MIPS, 1, 0);
7871
if (kernel_size < 0) {
7972
error_report("could not load kernel '%s': %s",

hw/nios2/boot.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,11 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
148148
if (kernel_filename) {
149149
int kernel_size, fdt_size;
150150
uint64_t entry, high;
151-
int big_endian = 0;
152-
153-
#if TARGET_BIG_ENDIAN
154-
big_endian = 1;
155-
#endif
156151

157152
/* Boots a kernel elf binary. */
158153
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
159154
&entry, NULL, &high, NULL,
160-
big_endian, EM_ALTERA_NIOS2, 0, 0);
155+
TARGET_BIG_ENDIAN, EM_ALTERA_NIOS2, 0, 0);
161156
if ((uint32_t)entry == 0xc0000000) {
162157
/*
163158
* The Nios II processor reference guide documents that the
@@ -168,7 +163,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
168163
kernel_size = load_elf(kernel_filename, NULL,
169164
translate_kernel_address, NULL,
170165
&entry, NULL, NULL, NULL,
171-
big_endian, EM_ALTERA_NIOS2, 0, 0);
166+
TARGET_BIG_ENDIAN, EM_ALTERA_NIOS2, 0, 0);
172167
boot_info.bootstrap_pc = ddr_base + 0xc0000000 +
173168
(entry & 0x07ffffff);
174169
} else {

hw/xtensa/sim.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,11 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
9696
void xtensa_sim_load_kernel(XtensaCPU *cpu, MachineState *machine)
9797
{
9898
const char *kernel_filename = machine->kernel_filename;
99-
#if TARGET_BIG_ENDIAN
100-
int big_endian = true;
101-
#else
102-
int big_endian = false;
103-
#endif
10499

105100
if (kernel_filename) {
106101
uint64_t elf_entry;
107102
int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
108-
&elf_entry, NULL, NULL, NULL, big_endian,
103+
&elf_entry, NULL, NULL, NULL, TARGET_BIG_ENDIAN,
109104
EM_XTENSA, 0, 0);
110105

111106
if (success > 0) {

hw/xtensa/xtfpga.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ static const MemoryRegionOps xtfpga_io_ops = {
219219

220220
static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
221221
{
222-
#if TARGET_BIG_ENDIAN
223-
int be = 1;
224-
#else
225-
int be = 0;
226-
#endif
227222
MemoryRegion *system_memory = get_system_memory();
228223
XtensaCPU *cpu = NULL;
229224
CPUXtensaState *env = NULL;
@@ -316,7 +311,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
316311

317312
dinfo = drive_get(IF_PFLASH, 0, 0);
318313
if (dinfo) {
319-
flash = xtfpga_flash_init(system_io, board, dinfo, be);
314+
flash = xtfpga_flash_init(system_io, board, dinfo, TARGET_BIG_ENDIAN);
320315
}
321316

322317
/* Use presence of kernel file name as 'boot from SRAM' switch. */
@@ -412,7 +407,8 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
412407

413408
uint64_t elf_entry;
414409
int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
415-
&elf_entry, NULL, NULL, NULL, be, EM_XTENSA, 0, 0);
410+
&elf_entry, NULL, NULL, NULL, TARGET_BIG_ENDIAN,
411+
EM_XTENSA, 0, 0);
416412
if (success > 0) {
417413
entry_point = elf_entry;
418414
} else {

target/arm/cpu.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,11 +3208,7 @@ static inline bool bswap_code(bool sctlr_b)
32083208
* The invalid combination SCTLR.B=1/CPSR.E=1/TARGET_BIG_ENDIAN=0
32093209
* would also end up as a mixed-endian mode with BE code, LE data.
32103210
*/
3211-
return
3212-
#if TARGET_BIG_ENDIAN
3213-
1 ^
3214-
#endif
3215-
sctlr_b;
3211+
return TARGET_BIG_ENDIAN ^ sctlr_b;
32163212
#else
32173213
/* All code access in ARM is little endian, and there are no loaders
32183214
* doing swaps that need to be reversed
@@ -3224,11 +3220,7 @@ static inline bool bswap_code(bool sctlr_b)
32243220
#ifdef CONFIG_USER_ONLY
32253221
static inline bool arm_cpu_bswap_data(CPUARMState *env)
32263222
{
3227-
return
3228-
#if TARGET_BIG_ENDIAN
3229-
1 ^
3230-
#endif
3231-
arm_cpu_data_is_big_endian(env);
3223+
return TARGET_BIG_ENDIAN ^ arm_cpu_data_is_big_endian(env);
32323224
}
32333225
#endif
32343226

0 commit comments

Comments
 (0)