podman
644 строки · 11.1 Кб
1// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
2// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
3// Portions Copyright © 1997-1999 Vita Nuova Limited
4// Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com)
5// Portions Copyright © 2004,2006 Bruce Ellis
6// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
7// Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others
8// Portions Copyright © 2009 The Go Authors. All rights reserved.
9// Portions Copyright © 2019 The Go Authors. All rights reserved.
10//
11// Permission is hereby granted, free of charge, to any person obtaining a copy
12// of this software and associated documentation files (the "Software"), to deal
13// in the Software without restriction, including without limitation the rights
14// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15// copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17//
18// The above copyright notice and this permission notice shall be included in
19// all copies or substantial portions of the Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27// THE SOFTWARE.
28
29package riscv30
31import "github.com/twitchyliquid64/golang-asm/obj"32
33//go:generate go run ../stringer.go -i $GOFILE -o anames.go -p riscv
34
35const (36// Base register numberings.37REG_X0 = obj.RBaseRISCV + iota38REG_X1
39REG_X2
40REG_X3
41REG_X4
42REG_X5
43REG_X6
44REG_X7
45REG_X8
46REG_X9
47REG_X10
48REG_X11
49REG_X12
50REG_X13
51REG_X14
52REG_X15
53REG_X16
54REG_X17
55REG_X18
56REG_X19
57REG_X20
58REG_X21
59REG_X22
60REG_X23
61REG_X24
62REG_X25
63REG_X26
64REG_X27
65REG_X28
66REG_X29
67REG_X30
68REG_X31
69
70// FP register numberings.71REG_F0
72REG_F1
73REG_F2
74REG_F3
75REG_F4
76REG_F5
77REG_F6
78REG_F7
79REG_F8
80REG_F9
81REG_F10
82REG_F11
83REG_F12
84REG_F13
85REG_F14
86REG_F15
87REG_F16
88REG_F17
89REG_F18
90REG_F19
91REG_F20
92REG_F21
93REG_F22
94REG_F23
95REG_F24
96REG_F25
97REG_F26
98REG_F27
99REG_F28
100REG_F29
101REG_F30
102REG_F31
103
104// This marks the end of the register numbering.105REG_END
106
107// General registers reassigned to ABI names.108REG_ZERO = REG_X0109REG_RA = REG_X1 // aka REG_LR110REG_SP = REG_X2111REG_GP = REG_X3 // aka REG_SB112REG_TP = REG_X4 // aka REG_G113REG_T0 = REG_X5114REG_T1 = REG_X6115REG_T2 = REG_X7116REG_S0 = REG_X8117REG_S1 = REG_X9118REG_A0 = REG_X10119REG_A1 = REG_X11120REG_A2 = REG_X12121REG_A3 = REG_X13122REG_A4 = REG_X14123REG_A5 = REG_X15124REG_A6 = REG_X16125REG_A7 = REG_X17126REG_S2 = REG_X18127REG_S3 = REG_X19128REG_S4 = REG_X20 // aka REG_CTXT129REG_S5 = REG_X21130REG_S6 = REG_X22131REG_S7 = REG_X23132REG_S8 = REG_X24133REG_S9 = REG_X25134REG_S10 = REG_X26135REG_S11 = REG_X27136REG_T3 = REG_X28137REG_T4 = REG_X29138REG_T5 = REG_X30139REG_T6 = REG_X31 // aka REG_TMP140
141// Go runtime register names.142REG_G = REG_TP // G pointer.143REG_CTXT = REG_S4 // Context for closures.144REG_LR = REG_RA // Link register.145REG_TMP = REG_T6 // Reserved for assembler use.146
147// ABI names for floating point registers.148REG_FT0 = REG_F0149REG_FT1 = REG_F1150REG_FT2 = REG_F2151REG_FT3 = REG_F3152REG_FT4 = REG_F4153REG_FT5 = REG_F5154REG_FT6 = REG_F6155REG_FT7 = REG_F7156REG_FS0 = REG_F8157REG_FS1 = REG_F9158REG_FA0 = REG_F10159REG_FA1 = REG_F11160REG_FA2 = REG_F12161REG_FA3 = REG_F13162REG_FA4 = REG_F14163REG_FA5 = REG_F15164REG_FA6 = REG_F16165REG_FA7 = REG_F17166REG_FS2 = REG_F18167REG_FS3 = REG_F19168REG_FS4 = REG_F20169REG_FS5 = REG_F21170REG_FS6 = REG_F22171REG_FS7 = REG_F23172REG_FS8 = REG_F24173REG_FS9 = REG_F25174REG_FS10 = REG_F26175REG_FS11 = REG_F27176REG_FT8 = REG_F28177REG_FT9 = REG_F29178REG_FT10 = REG_F30179REG_FT11 = REG_F31180
181// Names generated by the SSA compiler.182REGSP = REG_SP183REGG = REG_G184)
185
186// https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#dwarf-register-numbers
187var RISCV64DWARFRegisters = map[int16]int16{188// Integer Registers.189REG_X0: 0,190REG_X1: 1,191REG_X2: 2,192REG_X3: 3,193REG_X4: 4,194REG_X5: 5,195REG_X6: 6,196REG_X7: 7,197REG_X8: 8,198REG_X9: 9,199REG_X10: 10,200REG_X11: 11,201REG_X12: 12,202REG_X13: 13,203REG_X14: 14,204REG_X15: 15,205REG_X16: 16,206REG_X17: 17,207REG_X18: 18,208REG_X19: 19,209REG_X20: 20,210REG_X21: 21,211REG_X22: 22,212REG_X23: 23,213REG_X24: 24,214REG_X25: 25,215REG_X26: 26,216REG_X27: 27,217REG_X28: 28,218REG_X29: 29,219REG_X30: 30,220REG_X31: 31,221
222// Floating-Point Registers.223REG_F0: 32,224REG_F1: 33,225REG_F2: 34,226REG_F3: 35,227REG_F4: 36,228REG_F5: 37,229REG_F6: 38,230REG_F7: 39,231REG_F8: 40,232REG_F9: 41,233REG_F10: 42,234REG_F11: 43,235REG_F12: 44,236REG_F13: 45,237REG_F14: 46,238REG_F15: 47,239REG_F16: 48,240REG_F17: 49,241REG_F18: 50,242REG_F19: 51,243REG_F20: 52,244REG_F21: 53,245REG_F22: 54,246REG_F23: 55,247REG_F24: 56,248REG_F25: 57,249REG_F26: 58,250REG_F27: 59,251REG_F28: 60,252REG_F29: 61,253REG_F30: 62,254REG_F31: 63,255}
256
257// Prog.Mark flags.
258const (259// NEED_PCREL_ITYPE_RELOC is set on AUIPC instructions to indicate that260// it is the first instruction in an AUIPC + I-type pair that needs a261// R_RISCV_PCREL_ITYPE relocation.262NEED_PCREL_ITYPE_RELOC = 1 << 0263
264// NEED_PCREL_STYPE_RELOC is set on AUIPC instructions to indicate that265// it is the first instruction in an AUIPC + S-type pair that needs a266// R_RISCV_PCREL_STYPE relocation.267NEED_PCREL_STYPE_RELOC = 1 << 1268)
269
270// RISC-V mnemonics, as defined in the "opcodes" and "opcodes-pseudo" files
271// from:
272//
273// https://github.com/riscv/riscv-opcodes
274//
275// As well as some pseudo-mnemonics (e.g. MOV) used only in the assembler.
276//
277// See also "The RISC-V Instruction Set Manual" at:
278//
279// https://riscv.org/specifications/
280//
281// If you modify this table, you MUST run 'go generate' to regenerate anames.go!
282const (283// Unprivileged ISA (Document Version 20190608-Base-Ratified)284
285// 2.4: Integer Computational Instructions286AADDI = obj.ABaseRISCV + obj.A_ARCHSPECIFIC + iota287ASLTI
288ASLTIU
289AANDI
290AORI
291AXORI
292ASLLI
293ASRLI
294ASRAI
295ALUI
296AAUIPC
297AADD
298ASLT
299ASLTU
300AAND
301AOR
302AXOR
303ASLL
304ASRL
305ASUB
306ASRA
307
308// The SLL/SRL/SRA instructions differ slightly between RV32 and RV64,309// hence there are pseudo-opcodes for the RV32 specific versions.310ASLLIRV32
311ASRLIRV32
312ASRAIRV32
313
314// 2.5: Control Transfer Instructions315AJAL
316AJALR
317ABEQ
318ABNE
319ABLT
320ABLTU
321ABGE
322ABGEU
323
324// 2.6: Load and Store Instructions325ALW
326ALWU
327ALH
328ALHU
329ALB
330ALBU
331ASW
332ASH
333ASB
334
335// 2.7: Memory Ordering Instructions336AFENCE
337AFENCEI
338AFENCETSO
339
340// 5.2: Integer Computational Instructions (RV64I)341AADDIW
342ASLLIW
343ASRLIW
344ASRAIW
345AADDW
346ASLLW
347ASRLW
348ASUBW
349ASRAW
350
351// 5.3: Load and Store Instructions (RV64I)352ALD
353ASD
354
355// 7.1: Multiplication Operations356AMUL
357AMULH
358AMULHU
359AMULHSU
360AMULW
361ADIV
362ADIVU
363AREM
364AREMU
365ADIVW
366ADIVUW
367AREMW
368AREMUW
369
370// 8.2: Load-Reserved/Store-Conditional Instructions371ALRD
372ASCD
373ALRW
374ASCW
375
376// 8.3: Atomic Memory Operations377AAMOSWAPD
378AAMOADDD
379AAMOANDD
380AAMOORD
381AAMOXORD
382AAMOMAXD
383AAMOMAXUD
384AAMOMIND
385AAMOMINUD
386AAMOSWAPW
387AAMOADDW
388AAMOANDW
389AAMOORW
390AAMOXORW
391AAMOMAXW
392AAMOMAXUW
393AAMOMINW
394AAMOMINUW
395
396// 10.1: Base Counters and Timers397ARDCYCLE
398ARDCYCLEH
399ARDTIME
400ARDTIMEH
401ARDINSTRET
402ARDINSTRETH
403
404// 11.2: Floating-Point Control and Status Register405AFRCSR
406AFSCSR
407AFRRM
408AFSRM
409AFRFLAGS
410AFSFLAGS
411AFSRMI
412AFSFLAGSI
413
414// 11.5: Single-Precision Load and Store Instructions415AFLW
416AFSW
417
418// 11.6: Single-Precision Floating-Point Computational Instructions419AFADDS
420AFSUBS
421AFMULS
422AFDIVS
423AFMINS
424AFMAXS
425AFSQRTS
426AFMADDS
427AFMSUBS
428AFNMADDS
429AFNMSUBS
430
431// 11.7: Single-Precision Floating-Point Conversion and Move Instructions432AFCVTWS
433AFCVTLS
434AFCVTSW
435AFCVTSL
436AFCVTWUS
437AFCVTLUS
438AFCVTSWU
439AFCVTSLU
440AFSGNJS
441AFSGNJNS
442AFSGNJXS
443AFMVXS
444AFMVSX
445AFMVXW
446AFMVWX
447
448// 11.8: Single-Precision Floating-Point Compare Instructions449AFEQS
450AFLTS
451AFLES
452
453// 11.9: Single-Precision Floating-Point Classify Instruction454AFCLASSS
455
456// 12.3: Double-Precision Load and Store Instructions457AFLD
458AFSD
459
460// 12.4: Double-Precision Floating-Point Computational Instructions461AFADDD
462AFSUBD
463AFMULD
464AFDIVD
465AFMIND
466AFMAXD
467AFSQRTD
468AFMADDD
469AFMSUBD
470AFNMADDD
471AFNMSUBD
472
473// 12.5: Double-Precision Floating-Point Conversion and Move Instructions474AFCVTWD
475AFCVTLD
476AFCVTDW
477AFCVTDL
478AFCVTWUD
479AFCVTLUD
480AFCVTDWU
481AFCVTDLU
482AFCVTSD
483AFCVTDS
484AFSGNJD
485AFSGNJND
486AFSGNJXD
487AFMVXD
488AFMVDX
489
490// 12.6: Double-Precision Floating-Point Compare Instructions491AFEQD
492AFLTD
493AFLED
494
495// 12.7: Double-Precision Floating-Point Classify Instruction496AFCLASSD
497
498// 13.1 Quad-Precision Load and Store Instructions499AFLQ
500AFSQ
501
502// 13.2: Quad-Precision Computational Instructions503AFADDQ
504AFSUBQ
505AFMULQ
506AFDIVQ
507AFMINQ
508AFMAXQ
509AFSQRTQ
510AFMADDQ
511AFMSUBQ
512AFNMADDQ
513AFNMSUBQ
514
515// 13.3 Quad-Precision Convert and Move Instructions516AFCVTWQ
517AFCVTLQ
518AFCVTSQ
519AFCVTDQ
520AFCVTQW
521AFCVTQL
522AFCVTQS
523AFCVTQD
524AFCVTWUQ
525AFCVTLUQ
526AFCVTQWU
527AFCVTQLU
528AFSGNJQ
529AFSGNJNQ
530AFSGNJXQ
531AFMVXQ
532AFMVQX
533
534// 13.4 Quad-Precision Floating-Point Compare Instructions535AFEQQ
536AFLEQ
537AFLTQ
538
539// 13.5 Quad-Precision Floating-Point Classify Instruction540AFCLASSQ
541
542// Privileged ISA (Version 20190608-Priv-MSU-Ratified)543
544// 3.1.9: Instructions to Access CSRs545ACSRRW
546ACSRRS
547ACSRRC
548ACSRRWI
549ACSRRSI
550ACSRRCI
551
552// 3.2.1: Environment Call and Breakpoint553AECALL
554ASCALL
555AEBREAK
556ASBREAK
557
558// 3.2.2: Trap-Return Instructions559AMRET
560ASRET
561AURET
562ADRET
563
564// 3.2.3: Wait for Interrupt565AWFI
566
567// 4.2.1: Supervisor Memory-Management Fence Instruction568ASFENCEVMA
569
570// Hypervisor Memory-Management Instructions571AHFENCEGVMA
572AHFENCEVVMA
573
574// The escape hatch. Inserts a single 32-bit word.575AWORD
576
577// Pseudo-instructions. These get translated by the assembler into other578// instructions, based on their operands.579ABEQZ
580ABGEZ
581ABGT
582ABGTU
583ABGTZ
584ABLE
585ABLEU
586ABLEZ
587ABLTZ
588ABNEZ
589AFNEGD
590AFNEGS
591AFNED
592AFNES
593AMOV
594AMOVB
595AMOVBU
596AMOVF
597AMOVD
598AMOVH
599AMOVHU
600AMOVW
601AMOVWU
602ANEG
603ANEGW
604ANOT
605ASEQZ
606ASNEZ
607
608// End marker609ALAST
610)
611
612// All unary instructions which write to their arguments (as opposed to reading
613// from them) go here. The assembly parser uses this information to populate
614// its AST in a semantically reasonable way.
615//
616// Any instructions not listed here are assumed to either be non-unary or to read
617// from its argument.
618var unaryDst = map[obj.As]bool{619ARDCYCLE: true,620ARDCYCLEH: true,621ARDTIME: true,622ARDTIMEH: true,623ARDINSTRET: true,624ARDINSTRETH: true,625}
626
627// Instruction encoding masks.
628const (629// ITypeImmMask is a mask including only the immediate portion of630// I-type instructions.631ITypeImmMask = 0xfff00000632
633// STypeImmMask is a mask including only the immediate portion of634// S-type instructions.635STypeImmMask = 0xfe000f80636
637// UTypeImmMask is a mask including only the immediate portion of638// U-type instructions.639UTypeImmMask = 0xfffff000640
641// UJTypeImmMask is a mask including only the immediate portion of642// UJ-type instructions.643UJTypeImmMask = UTypeImmMask644)
645