cpu.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 S390(CPU):
  78. '''IBM S/390.
  79. '''
  80. name = 's390'
  81. bigEndian = True
  82. class SH(CPU):
  83. '''Little endian Renesas SuperH.
  84. '''
  85. name = 'sh'
  86. bigEndian = False
  87. class SHeb(CPU):
  88. '''Big endian Renesas SuperH.
  89. '''
  90. name = 'sheb'
  91. bigEndian = True
  92. class Sparc(CPU):
  93. '''Sun Sparc.
  94. '''
  95. name = 'sparc'
  96. bigEndian = True
  97. class X86(CPU):
  98. '''32-bit x86: Intel Pentium, AMD Athlon etc.
  99. '''
  100. name = 'x86'
  101. bigEndian = False
  102. gccFlags = '-m32',
  103. class X86_64(CPU):
  104. '''64-bit x86. Also known as AMD64 or x64.
  105. '''
  106. name = 'x86_64'
  107. bigEndian = False
  108. gccFlags = '-m64',
  109. # Build a dictionary of CPUs using introspection.
  110. _cpusByName = {
  111. obj.name: obj
  112. for obj in locals().values()
  113. if isinstance(obj, type)
  114. and issubclass(obj, CPU)
  115. and obj is not CPU
  116. }
  117. def getCPU(name):
  118. return _cpusByName[name]