qemu/target-info: Add target_endian_mode()

target_endian_mode() returns the default endianness (QAPI type)
of a target.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250708215320.70426-5-philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Philippe Mathieu-Daudé 2025-07-08 23:53:15 +02:00 committed by Michael S. Tsirkin
parent 536613be40
commit a37aec2e7d
4 changed files with 16 additions and 0 deletions

View File

@ -22,6 +22,8 @@ typedef struct TargetInfo {
const char *cpu_type; const char *cpu_type;
/* QOM typename machines for this binary must implement */ /* QOM typename machines for this binary must implement */
const char *machine_typename; const char *machine_typename;
/* related to TARGET_BIG_ENDIAN definition */
EndianMode endianness;
} TargetInfo; } TargetInfo;
/** /**

View File

@ -9,6 +9,7 @@
#ifndef QEMU_TARGET_INFO_EXTRA_H #ifndef QEMU_TARGET_INFO_EXTRA_H
#define QEMU_TARGET_INFO_EXTRA_H #define QEMU_TARGET_INFO_EXTRA_H
#include "qapi/qapi-types-common.h"
#include "qapi/qapi-types-machine.h" #include "qapi/qapi-types-machine.h"
/** /**
@ -18,4 +19,11 @@
*/ */
SysEmuTarget target_arch(void); SysEmuTarget target_arch(void);
/**
* target_endian_mode:
*
* Returns: QAPI EndianMode enum (e.g. ENDIAN_MODE_LITTLE).
*/
EndianMode target_endian_mode(void);
#endif #endif

View File

@ -18,6 +18,7 @@ static const TargetInfo target_info_stub = {
.long_bits = TARGET_LONG_BITS, .long_bits = TARGET_LONG_BITS,
.cpu_type = CPU_RESOLVING_TYPE, .cpu_type = CPU_RESOLVING_TYPE,
.machine_typename = TYPE_MACHINE, .machine_typename = TYPE_MACHINE,
.endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
}; };
const TargetInfo *target_info(void) const TargetInfo *target_info(void)

View File

@ -42,3 +42,8 @@ const char *target_machine_typename(void)
{ {
return target_info()->machine_typename; return target_info()->machine_typename;
} }
EndianMode target_endian_mode(void)
{
return target_info()->endianness;
}