1 // cmd/7l/noop.c, cmd/7l/obj.c, cmd/ld/pass.c from Vita Nuova.
2 // https://code.google.com/p/ken-cc/source/browse/
4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
6 // Portions Copyright © 1997-1999 Vita Nuova Limited
7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
8 // Portions Copyright © 2004,2006 Bruce Ellis
9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
11 // Portions Copyright © 2009 The Go Authors. All rights reserved.
13 // Permission is hereby granted, free of charge, to any person obtaining a copy
14 // of this software and associated documentation files (the "Software"), to deal
15 // in the Software without restriction, including without limitation the rights
16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 // copies of the Software, and to permit persons to whom the Software is
18 // furnished to do so, subject to the following conditions:
20 // The above copyright notice and this permission notice shall be included in
21 // all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43 var complements = []obj.As{
50 // zrReplace is the set of instructions for which $0 in the From operand
51 // should be replaced with REGZERO.
52 var zrReplace = map[obj.As]bool{
73 func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
74 if c.ctxt.Flag_maymorestack != "" {
75 p = c.cursym.Func().SpillRegisterArgs(p, c.newprog)
77 // Save LR and make room for FP, REGCTXT. Leave room
78 // for caller's saved FP.
80 p = obj.Appendp(p, c.newprog)
82 p.From.Type = obj.TYPE_REG
84 p.To.Type = obj.TYPE_MEM
86 p.To.Offset = -frameSize
91 p = obj.Appendp(p, c.newprog)
93 p.From.Type = obj.TYPE_REG
95 p.To.Type = obj.TYPE_MEM
99 p = obj.Appendp(p, c.newprog)
101 p.From.Type = obj.TYPE_CONST
104 p.To.Type = obj.TYPE_REG
107 // Save REGCTXT (for simplicity we do this whether or
109 p = obj.Appendp(p, c.newprog)
111 p.From.Type = obj.TYPE_REG
113 p.To.Type = obj.TYPE_MEM
118 p = obj.Appendp(p, c.newprog)
120 p.To.Type = obj.TYPE_BRANCH
121 // See ../x86/obj6.go
122 p.To.Sym = c.ctxt.LookupABI(c.ctxt.Flag_maymorestack, c.cursym.ABI())
125 p = obj.Appendp(p, c.newprog)
127 p.From.Type = obj.TYPE_MEM
130 p.To.Type = obj.TYPE_REG
134 p = obj.Appendp(p, c.newprog)
136 p.From.Type = obj.TYPE_MEM
139 p.To.Type = obj.TYPE_REG
142 // Restore LR and SP.
143 p = obj.Appendp(p, c.newprog)
145 p.From.Type = obj.TYPE_MEM
147 p.From.Offset = frameSize
149 p.To.Type = obj.TYPE_REG
153 p = c.cursym.Func().UnspillRegisterArgs(p, c.newprog)
156 // Jump back to here after morestack returns.
159 // MOV g_stackguard(g), RT1
160 p = obj.Appendp(p, c.newprog)
163 p.From.Type = obj.TYPE_MEM
165 p.From.Offset = 2 * int64(c.ctxt.Arch.PtrSize) // G.stackguard0
166 if c.cursym.CFunc() {
167 p.From.Offset = 3 * int64(c.ctxt.Arch.PtrSize) // G.stackguard1
169 p.To.Type = obj.TYPE_REG
172 // Mark the stack bound check and morestack call async nonpreemptible.
173 // If we get preempted here, when resumed the preemption request is
174 // cleared, but we'll still call morestack, which will double the stack
175 // unnecessarily. See issue #35470.
176 p = c.ctxt.StartUnsafePoint(p, c.newprog)
178 q := (*obj.Prog)(nil)
179 if framesize <= objabi.StackSmall {
180 // small stack: SP < stackguard
181 // CMP stackguard, SP
183 p = obj.Appendp(p, c.newprog)
185 p.From.Type = obj.TYPE_REG
188 } else if framesize <= objabi.StackBig {
189 // large stack: SP-framesize < stackguard-StackSmall
190 // SUB $(framesize-StackSmall), SP, RT2
191 // CMP stackguard, RT2
192 p = obj.Appendp(p, c.newprog)
195 p.From.Type = obj.TYPE_CONST
196 p.From.Offset = int64(framesize) - objabi.StackSmall
198 p.To.Type = obj.TYPE_REG
201 p = obj.Appendp(p, c.newprog)
203 p.From.Type = obj.TYPE_REG
207 // Such a large stack we need to protect against underflow.
208 // The runtime guarantees SP > objabi.StackBig, but
209 // framesize is large enough that SP-framesize may
210 // underflow, causing a direct comparison with the
211 // stack guard to incorrectly succeed. We explicitly
212 // guard against underflow.
214 // SUBS $(framesize-StackSmall), SP, RT2
215 // // On underflow, jump to morestack
216 // BLO label_of_call_to_morestack
217 // CMP stackguard, RT2
219 p = obj.Appendp(p, c.newprog)
221 p.From.Type = obj.TYPE_CONST
222 p.From.Offset = int64(framesize) - objabi.StackSmall
224 p.To.Type = obj.TYPE_REG
227 p = obj.Appendp(p, c.newprog)
230 p.To.Type = obj.TYPE_BRANCH
232 p = obj.Appendp(p, c.newprog)
234 p.From.Type = obj.TYPE_REG
240 bls := obj.Appendp(p, c.newprog)
242 bls.To.Type = obj.TYPE_BRANCH
244 end := c.ctxt.EndUnsafePoint(bls, c.newprog, -1)
247 for last = c.cursym.Func().Text; last.Link != nil; last = last.Link {
250 // Now we are at the end of the function, but logically
251 // we are still in function prologue. We need to fix the
252 // SP data and PCDATA.
253 spfix := obj.Appendp(last, c.newprog)
255 spfix.Spadj = -framesize
257 pcdata := c.ctxt.EmitEntryStackMap(c.cursym, spfix, c.newprog)
258 pcdata = c.ctxt.StartUnsafePoint(pcdata, c.newprog)
261 q.To.SetTarget(pcdata)
263 bls.To.SetTarget(pcdata)
265 spill := c.cursym.Func().SpillRegisterArgs(pcdata, c.newprog)
268 movlr := obj.Appendp(spill, c.newprog)
270 movlr.From.Type = obj.TYPE_REG
271 movlr.From.Reg = REGLINK
272 movlr.To.Type = obj.TYPE_REG
273 movlr.To.Reg = REG_R3
277 debug = obj.Appendp(debug, c.newprog)
279 debug.From.Type = obj.TYPE_CONST
280 debug.From.Offset = int64(framesize)
281 debug.To.Type = obj.TYPE_REG
282 debug.To.Reg = REGTMP
285 // BL runtime.morestack(SB)
286 call := obj.Appendp(debug, c.newprog)
288 call.To.Type = obj.TYPE_BRANCH
289 morestack := "runtime.morestack"
291 case c.cursym.CFunc():
292 morestack = "runtime.morestackc"
293 case !c.cursym.Func().Text.From.Sym.NeedCtxt():
294 morestack = "runtime.morestack_noctxt"
296 call.To.Sym = c.ctxt.Lookup(morestack)
298 unspill := c.cursym.Func().UnspillRegisterArgs(call, c.newprog)
299 pcdata = c.ctxt.EndUnsafePoint(unspill, c.newprog, -1)
302 jmp := obj.Appendp(pcdata, c.newprog)
304 jmp.To.Type = obj.TYPE_BRANCH
305 jmp.To.SetTarget(startPred.Link)
306 jmp.Spadj = +framesize
311 func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
312 c := ctxt7{ctxt: ctxt, newprog: newprog}
317 // Previously we rewrote $0 to ZR, but we have now removed this change.
318 // In order to be compatible with some previous legal instruction formats,
319 // reserve the previous conversion for some specific instructions.
320 if p.From.Type == obj.TYPE_CONST && p.From.Offset == 0 && zrReplace[p.As] {
321 p.From.Type = obj.TYPE_REG
325 // Rewrite BR/BL to symbol as TYPE_BRANCH.
333 p.To.Type = obj.TYPE_BRANCH
338 // Rewrite float constants to values stored in memory.
341 if p.From.Type == obj.TYPE_FCONST {
342 f64 := p.From.Val.(float64)
344 if c.chipfloat7(f64) > 0 {
347 if math.Float32bits(f32) == 0 {
348 p.From.Type = obj.TYPE_REG
352 p.From.Type = obj.TYPE_MEM
353 p.From.Sym = c.ctxt.Float32Sym(f32)
354 p.From.Name = obj.NAME_EXTERN
359 if p.From.Type == obj.TYPE_FCONST {
360 f64 := p.From.Val.(float64)
361 if c.chipfloat7(f64) > 0 {
364 if math.Float64bits(f64) == 0 {
365 p.From.Type = obj.TYPE_REG
369 p.From.Type = obj.TYPE_MEM
370 p.From.Sym = c.ctxt.Float64Sym(f64)
371 p.From.Name = obj.NAME_EXTERN
378 // Rewrite negative immediates as positive immediates with
379 // complementary instruction.
382 if p.From.Type == obj.TYPE_CONST && p.From.Offset < 0 && p.From.Offset != -1<<63 {
383 p.From.Offset = -p.From.Offset
384 p.As = complements[p.As]
387 if p.From.Type == obj.TYPE_CONST && p.From.Offset < 0 && int32(p.From.Offset) != -1<<31 {
388 p.From.Offset = -p.From.Offset
389 p.As = complements[p.As]
393 if c.ctxt.Flag_dynlink {
398 // Rewrite p, if necessary, to access global data via the global offset table.
399 func (c *ctxt7) rewriteToUseGot(p *obj.Prog) {
400 if p.As == obj.ADUFFCOPY || p.As == obj.ADUFFZERO {
403 // MOVD runtime.duffxxx@GOT, REGTMP
404 // ADD $offset, REGTMP
407 if p.As == obj.ADUFFZERO {
408 sym = c.ctxt.LookupABI("runtime.duffzero", obj.ABIInternal)
410 sym = c.ctxt.LookupABI("runtime.duffcopy", obj.ABIInternal)
412 offset := p.To.Offset
414 p.From.Type = obj.TYPE_MEM
415 p.From.Name = obj.NAME_GOTREF
417 p.To.Type = obj.TYPE_REG
419 p.To.Name = obj.NAME_NONE
422 p1 := obj.Appendp(p, c.newprog)
424 p1.From.Type = obj.TYPE_CONST
425 p1.From.Offset = offset
426 p1.To.Type = obj.TYPE_REG
428 p2 := obj.Appendp(p1, c.newprog)
430 p2.To.Type = obj.TYPE_REG
434 // We only care about global data: NAME_EXTERN means a global
435 // symbol in the Go sense, and p.Sym.Local is true for a few
436 // internally defined symbols.
437 if p.From.Type == obj.TYPE_ADDR && p.From.Name == obj.NAME_EXTERN && !p.From.Sym.Local() {
438 // MOVD $sym, Rx becomes MOVD sym@GOT, Rx
439 // MOVD $sym+<off>, Rx becomes MOVD sym@GOT, Rx; ADD <off>, Rx
441 c.ctxt.Diag("do not know how to handle TYPE_ADDR in %v with -dynlink", p)
443 if p.To.Type != obj.TYPE_REG {
444 c.ctxt.Diag("do not know how to handle LEAQ-type insn to non-register in %v with -dynlink", p)
446 p.From.Type = obj.TYPE_MEM
447 p.From.Name = obj.NAME_GOTREF
448 if p.From.Offset != 0 {
449 q := obj.Appendp(p, c.newprog)
451 q.From.Type = obj.TYPE_CONST
452 q.From.Offset = p.From.Offset
457 if p.GetFrom3() != nil && p.GetFrom3().Name == obj.NAME_EXTERN {
458 c.ctxt.Diag("don't know how to handle %v with -dynlink", p)
461 // MOVx sym, Ry becomes MOVD sym@GOT, REGTMP; MOVx (REGTMP), Ry
462 // MOVx Ry, sym becomes MOVD sym@GOT, REGTMP; MOVD Ry, (REGTMP)
463 // An addition may be inserted between the two MOVs if there is an offset.
464 if p.From.Name == obj.NAME_EXTERN && !p.From.Sym.Local() {
465 if p.To.Name == obj.NAME_EXTERN && !p.To.Sym.Local() {
466 c.ctxt.Diag("cannot handle NAME_EXTERN on both sides in %v with -dynlink", p)
469 } else if p.To.Name == obj.NAME_EXTERN && !p.To.Sym.Local() {
474 if p.As == obj.ATEXT || p.As == obj.AFUNCDATA || p.As == obj.ACALL || p.As == obj.ARET || p.As == obj.AJMP {
477 if source.Sym.Type == objabi.STLSBSS {
480 if source.Type != obj.TYPE_MEM {
481 c.ctxt.Diag("don't know how to handle %v with -dynlink", p)
483 p1 := obj.Appendp(p, c.newprog)
484 p2 := obj.Appendp(p1, c.newprog)
486 p1.From.Type = obj.TYPE_MEM
487 p1.From.Sym = source.Sym
488 p1.From.Name = obj.NAME_GOTREF
489 p1.To.Type = obj.TYPE_REG
495 if p.From.Name == obj.NAME_EXTERN {
497 p2.From.Name = obj.NAME_NONE
499 } else if p.To.Name == obj.NAME_EXTERN {
501 p2.To.Name = obj.NAME_NONE
509 func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
510 if cursym.Func().Text == nil || cursym.Func().Text.Link == nil {
514 c := ctxt7{ctxt: ctxt, newprog: newprog, cursym: cursym}
516 p := c.cursym.Func().Text
517 textstksiz := p.To.Offset
518 if textstksiz == -8 {
519 // Historical way to mark NOFRAME.
520 p.From.Sym.Set(obj.AttrNoFrame, true)
524 c.ctxt.Diag("negative frame size %d - did you mean NOFRAME?", textstksiz)
526 if p.From.Sym.NoFrame() {
528 c.ctxt.Diag("NOFRAME functions must have a frame size of 0, not %d", textstksiz)
532 c.cursym.Func().Args = p.To.Val.(int32)
533 c.cursym.Func().Locals = int32(textstksiz)
536 * find leaf subroutines
538 for p := c.cursym.Func().Text; p != nil; p = p.Link {
546 c.cursym.Func().Text.Mark &^= LEAF
553 for p := c.cursym.Func().Text; p != nil; p = p.Link {
557 c.cursym.Func().Text = p
558 c.autosize = int32(textstksiz)
560 if p.Mark&LEAF != 0 && c.autosize == 0 {
561 // A leaf function with no locals has no frame.
562 p.From.Sym.Set(obj.AttrNoFrame, true)
565 if !p.From.Sym.NoFrame() {
566 // If there is a stack frame at all, it includes
567 // space to save the LR.
572 extrasize := int32(0)
573 if c.autosize%16 == 8 {
574 // Allocate extra 8 bytes on the frame top to save FP
576 } else if c.autosize&(16-1) == 0 {
577 // Allocate extra 16 bytes to save FP for the old frame whose size is 8 mod 16
580 c.ctxt.Diag("%v: unaligned frame size %d - must be 16 aligned", p, c.autosize-8)
582 c.autosize += extrasize
583 c.cursym.Func().Locals += extrasize
585 // low 32 bits for autosize
586 // high 32 bits for extrasize
587 p.To.Offset = int64(c.autosize) | int64(extrasize)<<32
593 if c.autosize == 0 && c.cursym.Func().Text.Mark&LEAF == 0 {
594 if c.ctxt.Debugvlog {
595 c.ctxt.Logf("save suppressed in: %s\n", c.cursym.Func().Text.From.Sym.Name)
597 c.cursym.Func().Text.Mark |= LEAF
600 if cursym.Func().Text.Mark&LEAF != 0 {
601 cursym.Set(obj.AttrLeaf, true)
602 if p.From.Sym.NoFrame() {
607 if p.Mark&LEAF != 0 && c.autosize < objabi.StackSmall {
608 // A leaf function with a small stack can be marked
609 // NOSPLIT, avoiding a stack check.
610 p.From.Sym.Set(obj.AttrNoSplit, true)
613 if !p.From.Sym.NoSplit() {
614 p = c.stacksplit(p, c.autosize) // emit split check
617 var prologueEnd *obj.Prog
619 aoffset := c.autosize
621 // MOVD.W offset variant range is -0x100 to 0xf8, SP should be 16-byte aligned.
622 // so the maximum aoffset value is 0xf0.
626 // Frame is non-empty. Make sure to save link register, even if
627 // it is a leaf function, so that traceback works.
629 if c.autosize > aoffset {
630 // Frame size is too large for a MOVD.W instruction. Store the frame pointer
631 // register and link register before decrementing SP, so if a signal comes
632 // during the execution of the function prologue, the traceback code will
633 // not see a half-updated stack frame.
635 // SUB $autosize, RSP, R20
636 q1 = obj.Appendp(q, c.newprog)
639 q1.From.Type = obj.TYPE_CONST
640 q1.From.Offset = int64(c.autosize)
642 q1.To.Type = obj.TYPE_REG
647 // STP (R29, R30), -8(R20)
648 q1 = obj.Appendp(q1, c.newprog)
651 q1.From.Type = obj.TYPE_REGREG
653 q1.From.Offset = REGLINK
654 q1.To.Type = obj.TYPE_MEM
658 // This is not async preemptible, as if we open a frame
659 // at the current SP, it will clobber the saved LR.
660 q1 = c.ctxt.StartUnsafePoint(q1, c.newprog)
663 q1 = obj.Appendp(q1, c.newprog)
666 q1.From.Type = obj.TYPE_REG
667 q1.From.Reg = REG_R20
668 q1.To.Type = obj.TYPE_REG
670 q1.Spadj = c.autosize
672 q1 = c.ctxt.EndUnsafePoint(q1, c.newprog, -1)
674 if buildcfg.GOOS == "ios" {
675 // iOS does not support SA_ONSTACK. We will run the signal handler
676 // on the G stack. If we write below SP, it may be clobbered by
677 // the signal handler. So we save FP and LR after decrementing SP.
678 // STP (R29, R30), -8(RSP)
679 q1 = obj.Appendp(q1, c.newprog)
682 q1.From.Type = obj.TYPE_REGREG
684 q1.From.Offset = REGLINK
685 q1.To.Type = obj.TYPE_MEM
690 // small frame, update SP and save LR in a single MOVD.W instruction.
691 // So if a signal comes during the execution of the function prologue,
692 // the traceback code will not see a half-updated stack frame.
693 // Also, on Linux, in a cgo binary we may get a SIGSETXID signal
694 // early on before the signal stack is set, as glibc doesn't allow
695 // us to block SIGSETXID. So it is important that we don't write below
696 // the SP until the signal stack is set.
697 // Luckily, all the functions from thread entry to setting the signal
698 // stack have small frames.
699 q1 = obj.Appendp(q, c.newprog)
702 q1.From.Type = obj.TYPE_REG
703 q1.From.Reg = REGLINK
704 q1.To.Type = obj.TYPE_MEM
706 q1.To.Offset = int64(-aoffset)
713 q1 = obj.Appendp(q1, c.newprog)
716 q1.From.Type = obj.TYPE_REG
718 q1.To.Type = obj.TYPE_MEM
723 prologueEnd.Pos = prologueEnd.Pos.WithXlogue(src.PosPrologueEnd)
725 q1 = obj.Appendp(q1, c.newprog)
728 q1.From.Type = obj.TYPE_CONST
731 q1.To.Type = obj.TYPE_REG
734 if c.cursym.Func().Text.From.Sym.Wrapper() {
735 // if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
737 // MOV g_panic(g), RT1
741 // ... function body ...
743 // MOV panic_argp(RT1), RT2
744 // ADD $(autosize+8), RSP, R20
748 // MOVD R20, panic_argp(RT1)
751 // The NOP is needed to give the jumps somewhere to land.
752 // It is a liblink NOP, not an ARM64 NOP: it encodes to 0 instruction bytes.
755 // MOV g_panic(g), RT1
756 q = obj.Appendp(q, c.newprog)
758 q.From.Type = obj.TYPE_MEM
760 q.From.Offset = 4 * int64(c.ctxt.Arch.PtrSize) // G.panic
761 q.To.Type = obj.TYPE_REG
764 // CBNZ RT1, checkargp
765 cbnz := obj.Appendp(q, c.newprog)
767 cbnz.From.Type = obj.TYPE_REG
768 cbnz.From.Reg = REGRT1
769 cbnz.To.Type = obj.TYPE_BRANCH
771 // Empty branch target at the top of the function body
772 end := obj.Appendp(cbnz, c.newprog)
775 // find the end of the function
777 for last = end; last.Link != nil; last = last.Link {
780 // MOV panic_argp(RT1), RT2
781 mov := obj.Appendp(last, c.newprog)
783 mov.From.Type = obj.TYPE_MEM
784 mov.From.Reg = REGRT1
785 mov.From.Offset = 0 // Panic.argp
786 mov.To.Type = obj.TYPE_REG
789 // CBNZ branches to the MOV above
790 cbnz.To.SetTarget(mov)
792 // ADD $(autosize+8), SP, R20
793 q = obj.Appendp(mov, c.newprog)
795 q.From.Type = obj.TYPE_CONST
796 q.From.Offset = int64(c.autosize) + 8
798 q.To.Type = obj.TYPE_REG
802 q = obj.Appendp(q, c.newprog)
804 q.From.Type = obj.TYPE_REG
809 q = obj.Appendp(q, c.newprog)
811 q.To.Type = obj.TYPE_BRANCH
815 q = obj.Appendp(q, c.newprog)
817 q.From.Type = obj.TYPE_CONST
820 q.To.Type = obj.TYPE_REG
823 // MOV R20, panic_argp(RT1)
824 q = obj.Appendp(q, c.newprog)
826 q.From.Type = obj.TYPE_REG
828 q.To.Type = obj.TYPE_MEM
830 q.To.Offset = 0 // Panic.argp
833 q = obj.Appendp(q, c.newprog)
835 q.To.Type = obj.TYPE_BRANCH
841 if p.From.Type == obj.TYPE_CONST {
842 c.ctxt.Diag("using BECOME (%v) is not supported!", p)
848 if c.cursym.Func().Text.Mark&LEAF != 0 {
851 p.From.Type = obj.TYPE_CONST
852 p.From.Offset = int64(c.autosize)
853 p.To.Type = obj.TYPE_REG
855 p.Spadj = -c.autosize
858 p = obj.Appendp(p, c.newprog)
860 p.From.Type = obj.TYPE_CONST
863 p.To.Type = obj.TYPE_REG
867 aoffset := c.autosize
868 // LDP -8(RSP), (R29, R30)
870 p.From.Type = obj.TYPE_MEM
873 p.To.Type = obj.TYPE_REGREG
875 p.To.Offset = REGLINK
877 // ADD $aoffset, RSP, RSP
880 q.From.Type = obj.TYPE_CONST
881 q.From.Offset = int64(aoffset)
882 q.To.Type = obj.TYPE_REG
891 // If enabled, this code emits 'MOV PC, R27' before every 'MOV LR, PC',
892 // so that if you are debugging a low-level crash where PC and LR are zero,
893 // you can look at R27 to see what jumped to the zero.
894 // This is useful when bringing up Go on a new system.
895 // (There is similar code in ../ppc64/obj9.go:/if.false.)
896 const debugRETZERO = false
898 if p.As != obj.ARET {
906 p.From.Type = obj.TYPE_BRANCH
908 p.To.Type = obj.TYPE_REG
913 if p.As != obj.ARET {
921 if retjmp != nil { // retjmp
923 p.To.Type = obj.TYPE_BRANCH
925 p.Spadj = +c.autosize
930 p.To.Type = obj.TYPE_MEM
933 p.Spadj = +c.autosize
936 if p.To.Type == obj.TYPE_REG && p.To.Reg == REGSP && p.From.Type == obj.TYPE_CONST {
938 p.Spadj = int32(-p.From.Offset)
940 p.Spadj = int32(+p.From.Offset)
944 case obj.AGETCALLERPC:
948 p.From.Type = obj.TYPE_REG
953 p.From.Type = obj.TYPE_MEM
959 // STP (FP, R27), -24(SP)
966 // copy DUFFCOPY from q1 to q4
967 q4 := obj.Appendp(p, c.newprog)
969 q4.As = obj.ADUFFCOPY
973 q1.From.Type = obj.TYPE_BRANCH
974 q1.To.Type = obj.TYPE_REG
977 q2 := obj.Appendp(q1, c.newprog)
980 q2.From.Type = obj.TYPE_REGREG
982 q2.From.Offset = int64(REG_R27)
983 q2.To.Type = obj.TYPE_MEM
987 // maintain FP for DUFFCOPY
988 q3 := obj.Appendp(q2, c.newprog)
991 q3.From.Type = obj.TYPE_CONST
994 q3.To.Type = obj.TYPE_REG
997 q5 := obj.Appendp(q4, c.newprog)
1000 q5.From.Type = obj.TYPE_CONST
1003 q5.To.Type = obj.TYPE_REG
1005 q1.From.SetTarget(q5)
1009 // ADR ret_addr, R27
1010 // STP (FP, R27), -24(SP)
1017 // copy DUFFZERO from q1 to q4
1018 q4 := obj.Appendp(p, c.newprog)
1020 q4.As = obj.ADUFFZERO
1024 q1.From.Type = obj.TYPE_BRANCH
1025 q1.To.Type = obj.TYPE_REG
1028 q2 := obj.Appendp(q1, c.newprog)
1031 q2.From.Type = obj.TYPE_REGREG
1033 q2.From.Offset = int64(REG_R27)
1034 q2.To.Type = obj.TYPE_MEM
1038 // maintain FP for DUFFZERO
1039 q3 := obj.Appendp(q2, c.newprog)
1042 q3.From.Type = obj.TYPE_CONST
1045 q3.To.Type = obj.TYPE_REG
1048 q5 := obj.Appendp(q4, c.newprog)
1051 q5.From.Type = obj.TYPE_CONST
1054 q5.To.Type = obj.TYPE_REG
1056 q1.From.SetTarget(q5)
1060 if p.To.Type == obj.TYPE_REG && p.To.Reg == REGSP && p.Spadj == 0 {
1061 f := c.cursym.Func()
1062 if f.FuncFlag&objabi.FuncFlag_SPWRITE == 0 {
1063 c.cursym.Func().FuncFlag |= objabi.FuncFlag_SPWRITE
1064 if ctxt.Debugvlog || !ctxt.IsAsm {
1065 ctxt.Logf("auto-SPWRITE: %s %v\n", c.cursym.Name, p)
1067 ctxt.Diag("invalid auto-SPWRITE in non-assembly")
1069 log.Fatalf("bad SPWRITE")
1074 if p.From.Type == obj.TYPE_SHIFT && (p.To.Reg == REG_RSP || p.Reg == REG_RSP) {
1075 offset := p.From.Offset
1076 op := offset & (3 << 22)
1078 ctxt.Diag("illegal combination: %v", p)
1080 r := (offset >> 16) & 31
1081 shift := (offset >> 10) & 63
1083 // the shift amount is out of range, in order to avoid repeated error
1084 // reportings, don't call ctxt.Diag, because asmout case 27 has the
1088 p.From.Type = obj.TYPE_REG
1089 p.From.Reg = int16(REG_LSL + r + (shift&7)<<5)
1095 func nocache(p *obj.Prog) {
1101 var unaryDst = map[obj.As]bool{
1109 var Linkarm64 = obj.LinkArch{
1110 Arch: sys.ArchARM64,
1112 Preprocess: preprocess,
1116 DWARFRegisters: ARM64DWARFRegisters,