a.out.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. // cmd/9c/9.out.h from Vita Nuova.
  2. //
  3. // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
  4. // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
  5. // Portions Copyright © 1997-1999 Vita Nuova Limited
  6. // Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com)
  7. // Portions Copyright © 2004,2006 Bruce Ellis
  8. // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
  9. // Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others
  10. // Portions Copyright © 2009 The Go Authors. All rights reserved.
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining a copy
  13. // of this software and associated documentation files (the "Software"), to deal
  14. // in the Software without restriction, including without limitation the rights
  15. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. // copies of the Software, and to permit persons to whom the Software is
  17. // furnished to do so, subject to the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be included in
  20. // all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. // THE SOFTWARE.
  29. package mips
  30. import (
  31. "github.com/twitchyliquid64/golang-asm/obj"
  32. )
  33. //go:generate go run ../stringer.go -i $GOFILE -o anames.go -p mips
  34. /*
  35. * mips 64
  36. */
  37. const (
  38. NSNAME = 8
  39. NSYM = 50
  40. NREG = 32 /* number of general registers */
  41. NFREG = 32 /* number of floating point registers */
  42. NWREG = 32 /* number of MSA registers */
  43. )
  44. const (
  45. REG_R0 = obj.RBaseMIPS + iota // must be a multiple of 32
  46. REG_R1
  47. REG_R2
  48. REG_R3
  49. REG_R4
  50. REG_R5
  51. REG_R6
  52. REG_R7
  53. REG_R8
  54. REG_R9
  55. REG_R10
  56. REG_R11
  57. REG_R12
  58. REG_R13
  59. REG_R14
  60. REG_R15
  61. REG_R16
  62. REG_R17
  63. REG_R18
  64. REG_R19
  65. REG_R20
  66. REG_R21
  67. REG_R22
  68. REG_R23
  69. REG_R24
  70. REG_R25
  71. REG_R26
  72. REG_R27
  73. REG_R28
  74. REG_R29
  75. REG_R30
  76. REG_R31
  77. REG_F0 // must be a multiple of 32
  78. REG_F1
  79. REG_F2
  80. REG_F3
  81. REG_F4
  82. REG_F5
  83. REG_F6
  84. REG_F7
  85. REG_F8
  86. REG_F9
  87. REG_F10
  88. REG_F11
  89. REG_F12
  90. REG_F13
  91. REG_F14
  92. REG_F15
  93. REG_F16
  94. REG_F17
  95. REG_F18
  96. REG_F19
  97. REG_F20
  98. REG_F21
  99. REG_F22
  100. REG_F23
  101. REG_F24
  102. REG_F25
  103. REG_F26
  104. REG_F27
  105. REG_F28
  106. REG_F29
  107. REG_F30
  108. REG_F31
  109. // co-processor 0 control registers
  110. REG_M0 // must be a multiple of 32
  111. REG_M1
  112. REG_M2
  113. REG_M3
  114. REG_M4
  115. REG_M5
  116. REG_M6
  117. REG_M7
  118. REG_M8
  119. REG_M9
  120. REG_M10
  121. REG_M11
  122. REG_M12
  123. REG_M13
  124. REG_M14
  125. REG_M15
  126. REG_M16
  127. REG_M17
  128. REG_M18
  129. REG_M19
  130. REG_M20
  131. REG_M21
  132. REG_M22
  133. REG_M23
  134. REG_M24
  135. REG_M25
  136. REG_M26
  137. REG_M27
  138. REG_M28
  139. REG_M29
  140. REG_M30
  141. REG_M31
  142. // FPU control registers
  143. REG_FCR0 // must be a multiple of 32
  144. REG_FCR1
  145. REG_FCR2
  146. REG_FCR3
  147. REG_FCR4
  148. REG_FCR5
  149. REG_FCR6
  150. REG_FCR7
  151. REG_FCR8
  152. REG_FCR9
  153. REG_FCR10
  154. REG_FCR11
  155. REG_FCR12
  156. REG_FCR13
  157. REG_FCR14
  158. REG_FCR15
  159. REG_FCR16
  160. REG_FCR17
  161. REG_FCR18
  162. REG_FCR19
  163. REG_FCR20
  164. REG_FCR21
  165. REG_FCR22
  166. REG_FCR23
  167. REG_FCR24
  168. REG_FCR25
  169. REG_FCR26
  170. REG_FCR27
  171. REG_FCR28
  172. REG_FCR29
  173. REG_FCR30
  174. REG_FCR31
  175. // MSA registers
  176. // The lower bits of W registers are alias to F registers
  177. REG_W0 // must be a multiple of 32
  178. REG_W1
  179. REG_W2
  180. REG_W3
  181. REG_W4
  182. REG_W5
  183. REG_W6
  184. REG_W7
  185. REG_W8
  186. REG_W9
  187. REG_W10
  188. REG_W11
  189. REG_W12
  190. REG_W13
  191. REG_W14
  192. REG_W15
  193. REG_W16
  194. REG_W17
  195. REG_W18
  196. REG_W19
  197. REG_W20
  198. REG_W21
  199. REG_W22
  200. REG_W23
  201. REG_W24
  202. REG_W25
  203. REG_W26
  204. REG_W27
  205. REG_W28
  206. REG_W29
  207. REG_W30
  208. REG_W31
  209. REG_HI
  210. REG_LO
  211. REG_LAST = REG_LO // the last defined register
  212. REG_SPECIAL = REG_M0
  213. REGZERO = REG_R0 /* set to zero */
  214. REGSP = REG_R29
  215. REGSB = REG_R28
  216. REGLINK = REG_R31
  217. REGRET = REG_R1
  218. REGARG = -1 /* -1 disables passing the first argument in register */
  219. REGRT1 = REG_R1 /* reserved for runtime, duffzero and duffcopy */
  220. REGRT2 = REG_R2 /* reserved for runtime, duffcopy */
  221. REGCTXT = REG_R22 /* context for closures */
  222. REGG = REG_R30 /* G */
  223. REGTMP = REG_R23 /* used by the linker */
  224. FREGRET = REG_F0
  225. )
  226. // https://llvm.org/svn/llvm-project/llvm/trunk/lib/Target/Mips/MipsRegisterInfo.td search for DwarfRegNum
  227. // https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/mips/mips.c?view=co&revision=258099&content-type=text%2Fplain search for mips_dwarf_regno
  228. // For now, this is adequate for both 32 and 64 bit.
  229. var MIPSDWARFRegisters = map[int16]int16{}
  230. func init() {
  231. // f assigns dwarfregisters[from:to] = (base):(to-from+base)
  232. f := func(from, to, base int16) {
  233. for r := int16(from); r <= to; r++ {
  234. MIPSDWARFRegisters[r] = (r - from) + base
  235. }
  236. }
  237. f(REG_R0, REG_R31, 0)
  238. f(REG_F0, REG_F31, 32) // For 32-bit MIPS, compiler only uses even numbered registers -- see cmd/compile/internal/ssa/gen/MIPSOps.go
  239. MIPSDWARFRegisters[REG_HI] = 64
  240. MIPSDWARFRegisters[REG_LO] = 65
  241. // The lower bits of W registers are alias to F registers
  242. f(REG_W0, REG_W31, 32)
  243. }
  244. const (
  245. BIG = 32766
  246. )
  247. const (
  248. /* mark flags */
  249. FOLL = 1 << 0
  250. LABEL = 1 << 1
  251. LEAF = 1 << 2
  252. SYNC = 1 << 3
  253. BRANCH = 1 << 4
  254. LOAD = 1 << 5
  255. FCMP = 1 << 6
  256. NOSCHED = 1 << 7
  257. NSCHED = 20
  258. )
  259. const (
  260. C_NONE = iota
  261. C_REG
  262. C_FREG
  263. C_FCREG
  264. C_MREG /* special processor register */
  265. C_WREG /* MSA registers */
  266. C_HI
  267. C_LO
  268. C_ZCON
  269. C_SCON /* 16 bit signed */
  270. C_UCON /* 32 bit signed, low 16 bits 0 */
  271. C_ADD0CON
  272. C_AND0CON
  273. C_ADDCON /* -0x8000 <= v < 0 */
  274. C_ANDCON /* 0 < v <= 0xFFFF */
  275. C_LCON /* other 32 */
  276. C_DCON /* other 64 (could subdivide further) */
  277. C_SACON /* $n(REG) where n <= int16 */
  278. C_SECON
  279. C_LACON /* $n(REG) where int16 < n <= int32 */
  280. C_LECON
  281. C_DACON /* $n(REG) where int32 < n */
  282. C_STCON /* $tlsvar */
  283. C_SBRA
  284. C_LBRA
  285. C_SAUTO
  286. C_LAUTO
  287. C_SEXT
  288. C_LEXT
  289. C_ZOREG
  290. C_SOREG
  291. C_LOREG
  292. C_GOK
  293. C_ADDR
  294. C_TLS
  295. C_TEXTSIZE
  296. C_NCLASS /* must be the last */
  297. )
  298. const (
  299. AABSD = obj.ABaseMIPS + obj.A_ARCHSPECIFIC + iota
  300. AABSF
  301. AABSW
  302. AADD
  303. AADDD
  304. AADDF
  305. AADDU
  306. AADDW
  307. AAND
  308. ABEQ
  309. ABFPF
  310. ABFPT
  311. ABGEZ
  312. ABGEZAL
  313. ABGTZ
  314. ABLEZ
  315. ABLTZ
  316. ABLTZAL
  317. ABNE
  318. ABREAK
  319. ACLO
  320. ACLZ
  321. ACMOVF
  322. ACMOVN
  323. ACMOVT
  324. ACMOVZ
  325. ACMPEQD
  326. ACMPEQF
  327. ACMPGED
  328. ACMPGEF
  329. ACMPGTD
  330. ACMPGTF
  331. ADIV
  332. ADIVD
  333. ADIVF
  334. ADIVU
  335. ADIVW
  336. AGOK
  337. ALL
  338. ALLV
  339. ALUI
  340. AMADD
  341. AMOVB
  342. AMOVBU
  343. AMOVD
  344. AMOVDF
  345. AMOVDW
  346. AMOVF
  347. AMOVFD
  348. AMOVFW
  349. AMOVH
  350. AMOVHU
  351. AMOVW
  352. AMOVWD
  353. AMOVWF
  354. AMOVWL
  355. AMOVWR
  356. AMSUB
  357. AMUL
  358. AMULD
  359. AMULF
  360. AMULU
  361. AMULW
  362. ANEGD
  363. ANEGF
  364. ANEGW
  365. ANEGV
  366. ANOOP // hardware nop
  367. ANOR
  368. AOR
  369. AREM
  370. AREMU
  371. ARFE
  372. ASC
  373. ASCV
  374. ASGT
  375. ASGTU
  376. ASLL
  377. ASQRTD
  378. ASQRTF
  379. ASRA
  380. ASRL
  381. ASUB
  382. ASUBD
  383. ASUBF
  384. ASUBU
  385. ASUBW
  386. ASYNC
  387. ASYSCALL
  388. ATEQ
  389. ATLBP
  390. ATLBR
  391. ATLBWI
  392. ATLBWR
  393. ATNE
  394. AWORD
  395. AXOR
  396. /* 64-bit */
  397. AMOVV
  398. AMOVVL
  399. AMOVVR
  400. ASLLV
  401. ASRAV
  402. ASRLV
  403. ADIVV
  404. ADIVVU
  405. AREMV
  406. AREMVU
  407. AMULV
  408. AMULVU
  409. AADDV
  410. AADDVU
  411. ASUBV
  412. ASUBVU
  413. /* 64-bit FP */
  414. ATRUNCFV
  415. ATRUNCDV
  416. ATRUNCFW
  417. ATRUNCDW
  418. AMOVWU
  419. AMOVFV
  420. AMOVDV
  421. AMOVVF
  422. AMOVVD
  423. /* MSA */
  424. AVMOVB
  425. AVMOVH
  426. AVMOVW
  427. AVMOVD
  428. ALAST
  429. // aliases
  430. AJMP = obj.AJMP
  431. AJAL = obj.ACALL
  432. ARET = obj.ARET
  433. )
  434. func init() {
  435. // The asm encoder generally assumes that the lowest 5 bits of the
  436. // REG_XX constants match the machine instruction encoding, i.e.
  437. // the lowest 5 bits is the register number.
  438. // Check this here.
  439. if REG_R0%32 != 0 {
  440. panic("REG_R0 is not a multiple of 32")
  441. }
  442. if REG_F0%32 != 0 {
  443. panic("REG_F0 is not a multiple of 32")
  444. }
  445. if REG_M0%32 != 0 {
  446. panic("REG_M0 is not a multiple of 32")
  447. }
  448. if REG_FCR0%32 != 0 {
  449. panic("REG_FCR0 is not a multiple of 32")
  450. }
  451. if REG_W0%32 != 0 {
  452. panic("REG_W0 is not a multiple of 32")
  453. }
  454. }