cpu.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. class CPU(object):
  2. '''Abstract base class for CPU families.
  3. '''
  4. # String that we use to identify this CPU type.
  5. name = None
  6. # Big (True) or little (False) endian?
  7. # Note that some CPUs can do both; if both settings are used in practice
  8. # we treat them like different CPUs (see MIPS/MIPSel).
  9. bigEndian = None
  10. # GCC flags to pass to the compile and link commands.
  11. gccFlags = ()
  12. class Alpha(CPU):
  13. '''DEC Alpha.
  14. '''
  15. name = 'alpha'
  16. bigEndian = False
  17. class ARM(CPU):
  18. '''ARM.
  19. '''
  20. name = 'arm'
  21. bigEndian = False
  22. class ARM64(CPU):
  23. '''ARM 64-bit, little endian mode.
  24. '''
  25. name = 'aarch64'
  26. bigEndian = False
  27. class ARM64BE(CPU):
  28. '''ARM 64-bit, big endian mode.
  29. '''
  30. name = 'aarch64_be'
  31. bigEndian = True
  32. class AVR32(CPU):
  33. '''Atmel AVR32, an embedded RISC CPU.
  34. '''
  35. name = 'avr32'
  36. bigEndian = True
  37. class HPPA(CPU):
  38. '''HP PA-RISC.
  39. '''
  40. name = 'hppa'
  41. bigEndian = True
  42. class IA64(CPU):
  43. '''Intel Itanium.
  44. '''
  45. name = 'ia64'
  46. bigEndian = False
  47. class M68k(CPU):
  48. '''Motorola 680x0.
  49. '''
  50. name = 'm68k'
  51. bigEndian = True
  52. class MIPS(CPU):
  53. '''Big endian MIPS.
  54. '''
  55. name = 'mips'
  56. bigEndian = True
  57. class MIPSel(MIPS):
  58. '''Little endian MIPS.
  59. '''
  60. name = 'mipsel'
  61. bigEndian = False
  62. class PPC(CPU):
  63. '''32-bit Power PC.
  64. '''
  65. name = 'ppc'
  66. bigEndian = True
  67. class PPC64(CPU):
  68. '''64-bit Power PC.
  69. '''
  70. name = 'ppc64'
  71. bigEndian = True
  72. class PPC64LE(CPU):
  73. '''64-bit Power PC LE.
  74. '''
  75. name = 'ppc64le'
  76. bigEndian = False
  77. class RISCV64(CPU):
  78. '''64-bit RISC-V.
  79. '''
  80. name = 'riscv64'
  81. bigEndian = False
  82. class S390(CPU):
  83. '''IBM S/390.
  84. '''
  85. name = 's390'
  86. bigEndian = True
  87. class SH(CPU):
  88. '''Little endian Renesas SuperH.
  89. '''
  90. name = 'sh'
  91. bigEndian = False
  92. class SHeb(CPU):
  93. '''Big endian Renesas SuperH.
  94. '''
  95. name = 'sheb'
  96. bigEndian = True
  97. class Sparc(CPU):
  98. '''Sun Sparc.
  99. '''
  100. name = 'sparc'
  101. bigEndian = True
  102. class X86(CPU):
  103. '''32-bit x86: Intel Pentium, AMD Athlon etc.
  104. '''
  105. name = 'x86'
  106. bigEndian = False
  107. gccFlags = '-m32',
  108. class X86_64(CPU):
  109. '''64-bit x86. Also known as AMD64 or x64.
  110. '''
  111. name = 'x86_64'
  112. bigEndian = False
  113. gccFlags = '-m64',
  114. # Build a dictionary of CPUs using introspection.
  115. _cpusByName = {
  116. obj.name: obj
  117. for obj in locals().values()
  118. if isinstance(obj, type)
  119. and issubclass(obj, CPU)
  120. and obj is not CPU
  121. }
  122. def getCPU(name):
  123. return _cpusByName[name]