1 /*
2  * virarch.h: architecture handling
3  *
4  * Copyright (C) 2012 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #pragma once
23 
24 #include "internal.h"
25 
26 typedef enum {
27     VIR_ARCH_NONE,
28     VIR_ARCH_ALPHA,        /* Alpha       64 BE https://en.wikipedia.org/wiki/DEC_Alpha */
29     VIR_ARCH_ARMV6L,       /* ARMv6       32 LE https://en.wikipedia.org/wiki/ARM_architecture */
30     VIR_ARCH_ARMV7L,       /* ARMv7       32 LE https://en.wikipedia.org/wiki/ARM_architecture */
31     VIR_ARCH_ARMV7B,       /* ARMv7       32 BE https://en.wikipedia.org/wiki/ARM_architecture */
32 
33     VIR_ARCH_AARCH64,      /* ARMv8       64 LE https://en.wikipedia.org/wiki/ARM_architecture */
34     VIR_ARCH_CRIS,         /* ETRAX       32 LE https://en.wikipedia.org/wiki/ETRAX_CRIS */
35     VIR_ARCH_I686,         /* x86         32 LE https://en.wikipedia.org/wiki/X86 */
36     VIR_ARCH_ITANIUM,      /* Itanium     64 LE https://en.wikipedia.org/wiki/Itanium */
37     VIR_ARCH_LM32,         /* MilkyMist   32 BE https://en.wikipedia.org/wiki/Milkymist */
38 
39     VIR_ARCH_M68K,         /* m68k        32 BE https://en.wikipedia.org/wiki/Motorola_68000_family */
40     VIR_ARCH_MICROBLAZE,   /* Microblaze  32 BE https://en.wikipedia.org/wiki/MicroBlaze */
41     VIR_ARCH_MICROBLAZEEL, /* Microblaze  32 LE https://en.wikipedia.org/wiki/MicroBlaze */
42     VIR_ARCH_MIPS,         /* MIPS        32 BE https://en.wikipedia.org/wiki/MIPS_architecture */
43     VIR_ARCH_MIPSEL,       /* MIPS        32 LE https://en.wikipedia.org/wiki/MIPS_architecture */
44 
45     VIR_ARCH_MIPS64,       /* MIPS        64 BE https://en.wikipedia.org/wiki/MIPS_architecture */
46     VIR_ARCH_MIPS64EL,     /* MIPS        64 LE https://en.wikipedia.org/wiki/MIPS_architecture */
47     VIR_ARCH_OR32,         /* OpenRisc    32 BE https://en.wikipedia.org/wiki/OpenRISC#QEMU_support */
48     VIR_ARCH_PARISC,       /* PA-Risc     32 BE https://en.wikipedia.org/wiki/PA-RISC */
49     VIR_ARCH_PARISC64,     /* PA-Risc     64 BE https://en.wikipedia.org/wiki/PA-RISC */
50 
51     VIR_ARCH_PPC,          /* PowerPC     32 BE https://en.wikipedia.org/wiki/PowerPC */
52     VIR_ARCH_PPCLE,        /* PowerPC     32 LE https://en.wikipedia.org/wiki/PowerPC */
53     VIR_ARCH_PPC64,        /* PowerPC     64 BE https://en.wikipedia.org/wiki/PowerPC */
54     VIR_ARCH_PPC64LE,      /* PowerPC     64 LE https://en.wikipedia.org/wiki/PowerPC */
55     VIR_ARCH_PPCEMB,       /* PowerPC     32 BE https://en.wikipedia.org/wiki/PowerPC */
56 
57     VIR_ARCH_RISCV32,      /* RISC-V      32 LE https://en.wikipedia.org/wiki/RISC-V */
58     VIR_ARCH_RISCV64,      /* RISC-V      64 LE https://en.wikipedia.org/wiki/RISC-V */
59     VIR_ARCH_S390,         /* S390        32 BE https://en.wikipedia.org/wiki/S390 */
60     VIR_ARCH_S390X,        /* S390        64 BE https://en.wikipedia.org/wiki/S390x */
61     VIR_ARCH_SH4,          /* SuperH4     32 LE https://en.wikipedia.org/wiki/SuperH */
62 
63     VIR_ARCH_SH4EB,        /* SuperH4     32 BE https://en.wikipedia.org/wiki/SuperH */
64     VIR_ARCH_SPARC,        /* Sparc       32 BE https://en.wikipedia.org/wiki/Sparc */
65     VIR_ARCH_SPARC64,      /* Sparc       64 BE https://en.wikipedia.org/wiki/Sparc */
66     VIR_ARCH_UNICORE32,    /* UniCore     32 LE https://en.wikipedia.org/wiki/Unicore */
67     VIR_ARCH_X86_64,       /* x86         64 LE https://en.wikipedia.org/wiki/X86 */
68 
69     VIR_ARCH_XTENSA,       /* XTensa      32 LE https://en.wikipedia.org/wiki/Xtensa#Processor_Cores */
70     VIR_ARCH_XTENSAEB,     /* XTensa      32 BE https://en.wikipedia.org/wiki/Xtensa#Processor_Cores */
71 
72     VIR_ARCH_LAST,
73 } virArch;
74 
75 #define ARCH_IS_X86(arch)  ((arch) == VIR_ARCH_X86_64 ||\
76                             (arch) == VIR_ARCH_I686)
77 
78 #define ARCH_IS_PPC(arch)  ((arch) == VIR_ARCH_PPC ||\
79                             (arch) == VIR_ARCH_PPCLE ||\
80                             (arch) == VIR_ARCH_PPC64 ||\
81                             (arch) == VIR_ARCH_PPC64LE ||\
82                             (arch) == VIR_ARCH_PPCEMB)
83 
84 #define ARCH_IS_PPC64(arch)  ((arch) == VIR_ARCH_PPC64 ||\
85                               (arch) == VIR_ARCH_PPC64LE)
86 
87 #define ARCH_IS_ARM(arch)  ((arch) == VIR_ARCH_ARMV6L ||\
88                             (arch) == VIR_ARCH_ARMV7L ||\
89                             (arch) == VIR_ARCH_ARMV7B ||\
90                             (arch) == VIR_ARCH_AARCH64)
91 
92 #define ARCH_IS_RISCV(arch) ((arch) == VIR_ARCH_RISCV32 ||\
93                              (arch) == VIR_ARCH_RISCV64)
94 
95 #define ARCH_IS_S390(arch) ((arch) == VIR_ARCH_S390 ||\
96                             (arch) == VIR_ARCH_S390X)
97 
98 #define ARCH_IS_MIPS64(arch) ((arch) == VIR_ARCH_MIPS64 ||\
99                               (arch) == VIR_ARCH_MIPS64EL)
100 
101 typedef enum {
102     VIR_ARCH_LITTLE_ENDIAN,
103     VIR_ARCH_BIG_ENDIAN,
104 } virArchEndian;
105 
106 unsigned int virArchGetWordSize(virArch arch);
107 virArchEndian virArchGetEndian(virArch arch);
108 const char *virArchToString(virArch arch);
109 virArch virArchFromString(const char *name);
110 
111 virArch virArchFromHost(void);
112