cpu.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. # Allow unaligned memory accesses?
  11. unalignedMemoryAccess = False
  12. # GCC flags to pass to the compile and link commands.
  13. gccFlags = ()
  14. class Alpha(CPU):
  15. '''DEC Alpha.
  16. '''
  17. name = 'alpha'
  18. bigEndian = False
  19. class ARM(CPU):
  20. '''ARM.
  21. '''
  22. name = 'arm'
  23. bigEndian = False
  24. class ARM64(CPU):
  25. '''ARM 64-bit, little endian mode.
  26. '''
  27. name = 'aarch64'
  28. bigEndian = False
  29. class ARM64BE(CPU):
  30. '''ARM 64-bit, big endian mode.
  31. '''
  32. name = 'aarch64_be'
  33. bigEndian = True
  34. class AVR32(CPU):
  35. '''Atmel AVR32, an embedded RISC CPU.
  36. '''
  37. name = 'avr32'
  38. bigEndian = True
  39. class HPPA(CPU):
  40. '''HP PA-RISC.
  41. '''
  42. name = 'hppa'
  43. bigEndian = True
  44. class IA64(CPU):
  45. '''Intel Itanium.
  46. '''
  47. name = 'ia64'
  48. bigEndian = False
  49. class M68k(CPU):
  50. '''Motorola 680x0.
  51. '''
  52. name = 'm68k'
  53. bigEndian = True
  54. class MIPS(CPU):
  55. '''Big endian MIPS.
  56. '''
  57. name = 'mips'
  58. bigEndian = True
  59. class MIPSel(MIPS):
  60. '''Little endian MIPS.
  61. '''
  62. name = 'mipsel'
  63. bigEndian = False
  64. class PPC(CPU):
  65. '''32-bit Power PC.
  66. '''
  67. name = 'ppc'
  68. bigEndian = True
  69. class PPC64(CPU):
  70. '''64-bit Power PC.
  71. '''
  72. name = 'ppc64'
  73. bigEndian = True
  74. class S390(CPU):
  75. '''IBM S/390.
  76. '''
  77. name = 's390'
  78. bigEndian = True
  79. class SH(CPU):
  80. '''Little endian Renesas SuperH.
  81. '''
  82. name = 'sh'
  83. bigEndian = False
  84. class SHeb(CPU):
  85. '''Big endian Renesas SuperH.
  86. '''
  87. name = 'sheb'
  88. bigEndian = True
  89. class Sparc(CPU):
  90. '''Sun Sparc.
  91. '''
  92. name = 'sparc'
  93. bigEndian = True
  94. class X86(CPU):
  95. '''32-bit x86: Intel Pentium, AMD Athlon etc.
  96. '''
  97. name = 'x86'
  98. bigEndian = False
  99. unalignedMemoryAccess = True
  100. gccFlags = '-m32',
  101. class X86_64(CPU):
  102. '''64-bit x86. Also known as AMD64 or x64.
  103. '''
  104. name = 'x86_64'
  105. bigEndian = False
  106. unalignedMemoryAccess = True
  107. gccFlags = '-m64',
  108. # Build a dictionary of CPUs using introspection.
  109. def _discoverCPUs(localObjects):
  110. for obj in localObjects:
  111. if isinstance(obj, type) and issubclass(obj, CPU):
  112. if not (obj is CPU):
  113. yield obj.name, obj
  114. _cpusByName = dict(_discoverCPUs(locals().itervalues()))
  115. def getCPU(name):
  116. return _cpusByName[name]