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{
54 // noZRreplace is the set of instructions for which $0 in the To operand
55 // should NOT be replaced with REGZERO.
56 var noZRreplace = map[obj.As]bool{
60 func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
61 if c.ctxt.Flag_maymorestack != "" {
62 p = c.cursym.Func().SpillRegisterArgs(p, c.newprog)
64 // Save LR and make room for FP, REGCTXT. Leave room
65 // for caller's saved FP.
67 p = obj.Appendp(p, c.newprog)
69 p.From.Type = obj.TYPE_REG
71 p.To.Type = obj.TYPE_MEM
73 p.To.Offset = -frameSize
78 p = obj.Appendp(p, c.newprog)
80 p.From.Type = obj.TYPE_REG
82 p.To.Type = obj.TYPE_MEM
86 p = obj.Appendp(p, c.newprog)
88 p.From.Type = obj.TYPE_CONST
91 p.To.Type = obj.TYPE_REG
94 // Save REGCTXT (for simplicity we do this whether or
96 p = obj.Appendp(p, c.newprog)
98 p.From.Type = obj.TYPE_REG
100 p.To.Type = obj.TYPE_MEM
105 p = obj.Appendp(p, c.newprog)
107 p.To.Type = obj.TYPE_BRANCH
108 // See ../x86/obj6.go
109 p.To.Sym = c.ctxt.LookupABI(c.ctxt.Flag_maymorestack, c.cursym.ABI())
112 p = obj.Appendp(p, c.newprog)
114 p.From.Type = obj.TYPE_MEM
117 p.To.Type = obj.TYPE_REG
121 p = obj.Appendp(p, c.newprog)
123 p.From.Type = obj.TYPE_MEM
126 p.To.Type = obj.TYPE_REG
129 // Restore LR and SP.
130 p = obj.Appendp(p, c.newprog)
132 p.From.Type = obj.TYPE_MEM
134 p.From.Offset = frameSize
136 p.To.Type = obj.TYPE_REG
140 p = c.cursym.Func().UnspillRegisterArgs(p, c.newprog)
143 // Jump back to here after morestack returns.
146 // MOV g_stackguard(g), RT1
147 p = obj.Appendp(p, c.newprog)
150 p.From.Type = obj.TYPE_MEM
152 p.From.Offset = 2 * int64(c.ctxt.Arch.PtrSize) // G.stackguard0
153 if c.cursym.CFunc() {
154 p.From.Offset = 3 * int64(c.ctxt.Arch.PtrSize) // G.stackguard1
156 p.To.Type = obj.TYPE_REG
159 // Mark the stack bound check and morestack call async nonpreemptible.
160 // If we get preempted here, when resumed the preemption request is
161 // cleared, but we'll still call morestack, which will double the stack
162 // unnecessarily. See issue #35470.
163 p = c.ctxt.StartUnsafePoint(p, c.newprog)
165 q := (*obj.Prog)(nil)
166 if framesize <= objabi.StackSmall {
167 // small stack: SP < stackguard
168 // CMP stackguard, SP
170 p = obj.Appendp(p, c.newprog)
172 p.From.Type = obj.TYPE_REG
175 } else if framesize <= objabi.StackBig {
176 // large stack: SP-framesize < stackguard-StackSmall
177 // SUB $(framesize-StackSmall), SP, RT2
178 // CMP stackguard, RT2
179 p = obj.Appendp(p, c.newprog)
182 p.From.Type = obj.TYPE_CONST
183 p.From.Offset = int64(framesize) - objabi.StackSmall
185 p.To.Type = obj.TYPE_REG
188 p = obj.Appendp(p, c.newprog)
190 p.From.Type = obj.TYPE_REG
194 // Such a large stack we need to protect against underflow.
195 // The runtime guarantees SP > objabi.StackBig, but
196 // framesize is large enough that SP-framesize may
197 // underflow, causing a direct comparison with the
198 // stack guard to incorrectly succeed. We explicitly
199 // guard against underflow.
201 // SUBS $(framesize-StackSmall), SP, RT2
202 // // On underflow, jump to morestack
203 // BLO label_of_call_to_morestack
204 // CMP stackguard, RT2
206 p = obj.Appendp(p, c.newprog)
208 p.From.Type = obj.TYPE_CONST
209 p.From.Offset = int64(framesize) - objabi.StackSmall
211 p.To.Type = obj.TYPE_REG
214 p = obj.Appendp(p, c.newprog)
217 p.To.Type = obj.TYPE_BRANCH
219 p = obj.Appendp(p, c.newprog)
221 p.From.Type = obj.TYPE_REG
227 bls := obj.Appendp(p, c.newprog)
229 bls.To.Type = obj.TYPE_BRANCH
231 end := c.ctxt.EndUnsafePoint(bls, c.newprog, -1)
234 for last = c.cursym.Func().Text; last.Link != nil; last = last.Link {
237 // Now we are at the end of the function, but logically
238 // we are still in function prologue. We need to fix the
239 // SP data and PCDATA.
240 spfix := obj.Appendp(last, c.newprog)
242 spfix.Spadj = -framesize
244 pcdata := c.ctxt.EmitEntryStackMap(c.cursym, spfix, c.newprog)
245 pcdata = c.ctxt.StartUnsafePoint(pcdata, c.newprog)
248 q.To.SetTarget(pcdata)
250 bls.To.SetTarget(pcdata)
252 spill := c.cursym.Func().SpillRegisterArgs(pcdata, c.newprog)
255 movlr := obj.Appendp(spill, c.newprog)
257 movlr.From.Type = obj.TYPE_REG
258 movlr.From.Reg = REGLINK
259 movlr.To.Type = obj.TYPE_REG
260 movlr.To.Reg = REG_R3
264 debug = obj.Appendp(debug, c.newprog)
266 debug.From.Type = obj.TYPE_CONST
267 debug.From.Offset = int64(framesize)
268 debug.To.Type = obj.TYPE_REG
269 debug.To.Reg = REGTMP
272 // BL runtime.morestack(SB)
273 call := obj.Appendp(debug, c.newprog)
275 call.To.Type = obj.TYPE_BRANCH
276 morestack := "runtime.morestack"
278 case c.cursym.CFunc():
279 morestack = "runtime.morestackc"
280 case !c.cursym.Func().Text.From.Sym.NeedCtxt():
281 morestack = "runtime.morestack_noctxt"
283 call.To.Sym = c.ctxt.Lookup(morestack)
285 unspill := c.cursym.Func().UnspillRegisterArgs(call, c.newprog)
286 pcdata = c.ctxt.EndUnsafePoint(unspill, c.newprog, -1)
289 jmp := obj.Appendp(pcdata, c.newprog)
291 jmp.To.Type = obj.TYPE_BRANCH
292 jmp.To.SetTarget(startPred.Link)
293 jmp.Spadj = +framesize
298 func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
299 c := ctxt7{ctxt: ctxt, newprog: newprog}
304 // $0 results in C_ZCON, which matches both C_REG and various
305 // C_xCON, however the C_REG cases in asmout don't expect a
306 // constant, so they will use the register fields and assemble
307 // a R0. To prevent that, rewrite $0 as ZR.
308 if p.From.Type == obj.TYPE_CONST && p.From.Offset == 0 {
309 p.From.Type = obj.TYPE_REG
312 if p.To.Type == obj.TYPE_CONST && p.To.Offset == 0 && !noZRreplace[p.As] {
313 p.To.Type = obj.TYPE_REG
317 // Rewrite BR/BL to symbol as TYPE_BRANCH.
325 p.To.Type = obj.TYPE_BRANCH
330 // Rewrite float constants to values stored in memory.
333 if p.From.Type == obj.TYPE_FCONST {
334 f64 := p.From.Val.(float64)
336 if c.chipfloat7(f64) > 0 {
339 if math.Float32bits(f32) == 0 {
340 p.From.Type = obj.TYPE_REG
344 p.From.Type = obj.TYPE_MEM
345 p.From.Sym = c.ctxt.Float32Sym(f32)
346 p.From.Name = obj.NAME_EXTERN
351 if p.From.Type == obj.TYPE_FCONST {
352 f64 := p.From.Val.(float64)
353 if c.chipfloat7(f64) > 0 {
356 if math.Float64bits(f64) == 0 {
357 p.From.Type = obj.TYPE_REG
361 p.From.Type = obj.TYPE_MEM
362 p.From.Sym = c.ctxt.Float64Sym(f64)
363 p.From.Name = obj.NAME_EXTERN
370 // Rewrite negative immediates as positive immediates with
371 // complementary instruction.
373 case AADD, ASUB, ACMP, ACMN:
374 if p.From.Type == obj.TYPE_CONST && p.From.Offset < 0 && p.From.Offset != -1<<63 {
375 p.From.Offset = -p.From.Offset
376 p.As = complements[p.As]
378 case AADDW, ASUBW, ACMPW, ACMNW:
379 if p.From.Type == obj.TYPE_CONST && p.From.Offset < 0 && int32(p.From.Offset) != -1<<31 {
380 p.From.Offset = -p.From.Offset
381 p.As = complements[p.As]
385 // For 32-bit instruction with constant, rewrite
386 // the high 32-bit to be a repetition of the low
387 // 32-bit, so that the BITCON test can be shared
388 // for both 32-bit and 64-bit. 32-bit ops will
389 // zero the high 32-bit of the destination register
391 // For MOVW, the destination register can't be ZR,
392 // so don't bother rewriting it in this situation.
393 if (isANDWop(p.As) || isADDWop(p.As) || p.As == AMOVW && p.To.Reg != REGZERO) && p.From.Type == obj.TYPE_CONST {
394 v := p.From.Offset & 0xffffffff
395 p.From.Offset = v | v<<32
398 if c.ctxt.Flag_dynlink {
403 // Rewrite p, if necessary, to access global data via the global offset table.
404 func (c *ctxt7) rewriteToUseGot(p *obj.Prog) {
405 if p.As == obj.ADUFFCOPY || p.As == obj.ADUFFZERO {
408 // MOVD runtime.duffxxx@GOT, REGTMP
409 // ADD $offset, REGTMP
412 if p.As == obj.ADUFFZERO {
413 sym = c.ctxt.LookupABI("runtime.duffzero", obj.ABIInternal)
415 sym = c.ctxt.LookupABI("runtime.duffcopy", obj.ABIInternal)
417 offset := p.To.Offset
419 p.From.Type = obj.TYPE_MEM
420 p.From.Name = obj.NAME_GOTREF
422 p.To.Type = obj.TYPE_REG
424 p.To.Name = obj.NAME_NONE
427 p1 := obj.Appendp(p, c.newprog)
429 p1.From.Type = obj.TYPE_CONST
430 p1.From.Offset = offset
431 p1.To.Type = obj.TYPE_REG
433 p2 := obj.Appendp(p1, c.newprog)
435 p2.To.Type = obj.TYPE_REG
439 // We only care about global data: NAME_EXTERN means a global
440 // symbol in the Go sense, and p.Sym.Local is true for a few
441 // internally defined symbols.
442 if p.From.Type == obj.TYPE_ADDR && p.From.Name == obj.NAME_EXTERN && !p.From.Sym.Local() {
443 // MOVD $sym, Rx becomes MOVD sym@GOT, Rx
444 // MOVD $sym+<off>, Rx becomes MOVD sym@GOT, Rx; ADD <off>, Rx
446 c.ctxt.Diag("do not know how to handle TYPE_ADDR in %v with -dynlink", p)
448 if p.To.Type != obj.TYPE_REG {
449 c.ctxt.Diag("do not know how to handle LEAQ-type insn to non-register in %v with -dynlink", p)
451 p.From.Type = obj.TYPE_MEM
452 p.From.Name = obj.NAME_GOTREF
453 if p.From.Offset != 0 {
454 q := obj.Appendp(p, c.newprog)
456 q.From.Type = obj.TYPE_CONST
457 q.From.Offset = p.From.Offset
462 if p.GetFrom3() != nil && p.GetFrom3().Name == obj.NAME_EXTERN {
463 c.ctxt.Diag("don't know how to handle %v with -dynlink", p)
466 // MOVx sym, Ry becomes MOVD sym@GOT, REGTMP; MOVx (REGTMP), Ry
467 // MOVx Ry, sym becomes MOVD sym@GOT, REGTMP; MOVD Ry, (REGTMP)
468 // An addition may be inserted between the two MOVs if there is an offset.
469 if p.From.Name == obj.NAME_EXTERN && !p.From.Sym.Local() {
470 if p.To.Name == obj.NAME_EXTERN && !p.To.Sym.Local() {
471 c.ctxt.Diag("cannot handle NAME_EXTERN on both sides in %v with -dynlink", p)
474 } else if p.To.Name == obj.NAME_EXTERN && !p.To.Sym.Local() {
479 if p.As == obj.ATEXT || p.As == obj.AFUNCDATA || p.As == obj.ACALL || p.As == obj.ARET || p.As == obj.AJMP {
482 if source.Sym.Type == objabi.STLSBSS {
485 if source.Type != obj.TYPE_MEM {
486 c.ctxt.Diag("don't know how to handle %v with -dynlink", p)
488 p1 := obj.Appendp(p, c.newprog)
489 p2 := obj.Appendp(p1, c.newprog)
491 p1.From.Type = obj.TYPE_MEM
492 p1.From.Sym = source.Sym
493 p1.From.Name = obj.NAME_GOTREF
494 p1.To.Type = obj.TYPE_REG
500 if p.From.Name == obj.NAME_EXTERN {
502 p2.From.Name = obj.NAME_NONE
504 } else if p.To.Name == obj.NAME_EXTERN {
506 p2.To.Name = obj.NAME_NONE
514 func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
515 if cursym.Func().Text == nil || cursym.Func().Text.Link == nil {
519 c := ctxt7{ctxt: ctxt, newprog: newprog, cursym: cursym}
521 p := c.cursym.Func().Text
522 textstksiz := p.To.Offset
523 if textstksiz == -8 {
524 // Historical way to mark NOFRAME.
525 p.From.Sym.Set(obj.AttrNoFrame, true)
529 c.ctxt.Diag("negative frame size %d - did you mean NOFRAME?", textstksiz)
531 if p.From.Sym.NoFrame() {
533 c.ctxt.Diag("NOFRAME functions must have a frame size of 0, not %d", textstksiz)
537 c.cursym.Func().Args = p.To.Val.(int32)
538 c.cursym.Func().Locals = int32(textstksiz)
541 * find leaf subroutines
543 for p := c.cursym.Func().Text; p != nil; p = p.Link {
551 c.cursym.Func().Text.Mark &^= LEAF
558 for p := c.cursym.Func().Text; p != nil; p = p.Link {
562 c.cursym.Func().Text = p
563 c.autosize = int32(textstksiz)
565 if p.Mark&LEAF != 0 && c.autosize == 0 {
566 // A leaf function with no locals has no frame.
567 p.From.Sym.Set(obj.AttrNoFrame, true)
570 if !p.From.Sym.NoFrame() {
571 // If there is a stack frame at all, it includes
572 // space to save the LR.
577 extrasize := int32(0)
578 if c.autosize%16 == 8 {
579 // Allocate extra 8 bytes on the frame top to save FP
581 } else if c.autosize&(16-1) == 0 {
582 // Allocate extra 16 bytes to save FP for the old frame whose size is 8 mod 16
585 c.ctxt.Diag("%v: unaligned frame size %d - must be 16 aligned", p, c.autosize-8)
587 c.autosize += extrasize
588 c.cursym.Func().Locals += extrasize
590 // low 32 bits for autosize
591 // high 32 bits for extrasize
592 p.To.Offset = int64(c.autosize) | int64(extrasize)<<32
598 if c.autosize == 0 && c.cursym.Func().Text.Mark&LEAF == 0 {
599 if c.ctxt.Debugvlog {
600 c.ctxt.Logf("save suppressed in: %s\n", c.cursym.Func().Text.From.Sym.Name)
602 c.cursym.Func().Text.Mark |= LEAF
605 if cursym.Func().Text.Mark&LEAF != 0 {
606 cursym.Set(obj.AttrLeaf, true)
607 if p.From.Sym.NoFrame() {
612 if p.Mark&LEAF != 0 && c.autosize < objabi.StackSmall {
613 // A leaf function with a small stack can be marked
614 // NOSPLIT, avoiding a stack check.
615 p.From.Sym.Set(obj.AttrNoSplit, true)
618 if !p.From.Sym.NoSplit() {
619 p = c.stacksplit(p, c.autosize) // emit split check
622 var prologueEnd *obj.Prog
624 aoffset := c.autosize
629 // Frame is non-empty. Make sure to save link register, even if
630 // it is a leaf function, so that traceback works.
632 if c.autosize > aoffset {
633 // Frame size is too large for a MOVD.W instruction.
634 // Store link register before decrementing SP, so if a signal comes
635 // during the execution of the function prologue, the traceback
636 // code will not see a half-updated stack frame.
637 // This sequence is not async preemptible, as if we open a frame
638 // at the current SP, it will clobber the saved LR.
639 q = c.ctxt.StartUnsafePoint(q, c.newprog)
641 q = obj.Appendp(q, c.newprog)
644 q.From.Type = obj.TYPE_CONST
645 q.From.Offset = int64(c.autosize)
647 q.To.Type = obj.TYPE_REG
652 q = obj.Appendp(q, c.newprog)
655 q.From.Type = obj.TYPE_REG
657 q.To.Type = obj.TYPE_MEM
660 q1 = obj.Appendp(q, c.newprog)
663 q1.From.Type = obj.TYPE_REG
665 q1.To.Type = obj.TYPE_REG
667 q1.Spadj = c.autosize
669 if buildcfg.GOOS == "ios" {
670 // iOS does not support SA_ONSTACK. We will run the signal handler
671 // on the G stack. If we write below SP, it may be clobbered by
672 // the signal handler. So we save LR after decrementing SP.
673 q1 = obj.Appendp(q1, c.newprog)
676 q1.From.Type = obj.TYPE_REG
677 q1.From.Reg = REGLINK
678 q1.To.Type = obj.TYPE_MEM
682 q1 = c.ctxt.EndUnsafePoint(q1, c.newprog, -1)
684 // small frame, update SP and save LR in a single MOVD.W instruction
685 q1 = obj.Appendp(q, c.newprog)
688 q1.From.Type = obj.TYPE_REG
689 q1.From.Reg = REGLINK
690 q1.To.Type = obj.TYPE_MEM
692 q1.To.Offset = int64(-aoffset)
699 prologueEnd.Pos = prologueEnd.Pos.WithXlogue(src.PosPrologueEnd)
702 q1 = obj.Appendp(q1, c.newprog)
705 q1.From.Type = obj.TYPE_REG
707 q1.To.Type = obj.TYPE_MEM
711 q1 = obj.Appendp(q1, c.newprog)
714 q1.From.Type = obj.TYPE_CONST
717 q1.To.Type = obj.TYPE_REG
720 if c.cursym.Func().Text.From.Sym.Wrapper() {
721 // if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
723 // MOV g_panic(g), RT1
727 // ... function body ...
729 // MOV panic_argp(RT1), RT2
730 // ADD $(autosize+8), RSP, R20
734 // MOVD R20, panic_argp(RT1)
737 // The NOP is needed to give the jumps somewhere to land.
738 // It is a liblink NOP, not an ARM64 NOP: it encodes to 0 instruction bytes.
741 // MOV g_panic(g), RT1
742 q = obj.Appendp(q, c.newprog)
744 q.From.Type = obj.TYPE_MEM
746 q.From.Offset = 4 * int64(c.ctxt.Arch.PtrSize) // G.panic
747 q.To.Type = obj.TYPE_REG
750 // CBNZ RT1, checkargp
751 cbnz := obj.Appendp(q, c.newprog)
753 cbnz.From.Type = obj.TYPE_REG
754 cbnz.From.Reg = REGRT1
755 cbnz.To.Type = obj.TYPE_BRANCH
757 // Empty branch target at the top of the function body
758 end := obj.Appendp(cbnz, c.newprog)
761 // find the end of the function
763 for last = end; last.Link != nil; last = last.Link {
766 // MOV panic_argp(RT1), RT2
767 mov := obj.Appendp(last, c.newprog)
769 mov.From.Type = obj.TYPE_MEM
770 mov.From.Reg = REGRT1
771 mov.From.Offset = 0 // Panic.argp
772 mov.To.Type = obj.TYPE_REG
775 // CBNZ branches to the MOV above
776 cbnz.To.SetTarget(mov)
778 // ADD $(autosize+8), SP, R20
779 q = obj.Appendp(mov, c.newprog)
781 q.From.Type = obj.TYPE_CONST
782 q.From.Offset = int64(c.autosize) + 8
784 q.To.Type = obj.TYPE_REG
788 q = obj.Appendp(q, c.newprog)
790 q.From.Type = obj.TYPE_REG
795 q = obj.Appendp(q, c.newprog)
797 q.To.Type = obj.TYPE_BRANCH
801 q = obj.Appendp(q, c.newprog)
803 q.From.Type = obj.TYPE_CONST
806 q.To.Type = obj.TYPE_REG
809 // MOV R20, panic_argp(RT1)
810 q = obj.Appendp(q, c.newprog)
812 q.From.Type = obj.TYPE_REG
814 q.To.Type = obj.TYPE_MEM
816 q.To.Offset = 0 // Panic.argp
819 q = obj.Appendp(q, c.newprog)
821 q.To.Type = obj.TYPE_BRANCH
827 if p.From.Type == obj.TYPE_CONST {
828 c.ctxt.Diag("using BECOME (%v) is not supported!", p)
834 if c.cursym.Func().Text.Mark&LEAF != 0 {
837 p.From.Type = obj.TYPE_CONST
838 p.From.Offset = int64(c.autosize)
839 p.To.Type = obj.TYPE_REG
841 p.Spadj = -c.autosize
844 p = obj.Appendp(p, c.newprog)
846 p.From.Type = obj.TYPE_CONST
849 p.To.Type = obj.TYPE_REG
853 /* want write-back pre-indexed SP+autosize -> SP, loading REGLINK*/
857 p.From.Type = obj.TYPE_MEM
860 p.To.Type = obj.TYPE_REG
862 p = obj.Appendp(p, c.newprog)
864 aoffset := c.autosize
868 p.From.Type = obj.TYPE_MEM
870 p.From.Offset = int64(aoffset)
872 p.To.Type = obj.TYPE_REG
877 p.From.Type = obj.TYPE_MEM
880 p.To.Type = obj.TYPE_REG
885 q.From.Type = obj.TYPE_CONST
886 q.From.Offset = int64(aoffset)
887 q.To.Type = obj.TYPE_REG
890 q.Spadj = int32(-q.From.Offset)
897 // If enabled, this code emits 'MOV PC, R27' before every 'MOV LR, PC',
898 // so that if you are debugging a low-level crash where PC and LR are zero,
899 // you can look at R27 to see what jumped to the zero.
900 // This is useful when bringing up Go on a new system.
901 // (There is similar code in ../ppc64/obj9.go:/if.false.)
902 const debugRETZERO = false
904 if p.As != obj.ARET {
912 p.From.Type = obj.TYPE_BRANCH
914 p.To.Type = obj.TYPE_REG
919 if p.As != obj.ARET {
927 if retjmp != nil { // retjmp
929 p.To.Type = obj.TYPE_BRANCH
931 p.Spadj = +c.autosize
936 p.To.Type = obj.TYPE_MEM
939 p.Spadj = +c.autosize
942 if p.To.Type == obj.TYPE_REG && p.To.Reg == REGSP && p.From.Type == obj.TYPE_CONST {
944 p.Spadj = int32(-p.From.Offset)
946 p.Spadj = int32(+p.From.Offset)
950 case obj.AGETCALLERPC:
954 p.From.Type = obj.TYPE_REG
959 p.From.Type = obj.TYPE_MEM
965 // STP (FP, R27), -24(SP)
972 // copy DUFFCOPY from q1 to q4
973 q4 := obj.Appendp(p, c.newprog)
975 q4.As = obj.ADUFFCOPY
979 q1.From.Type = obj.TYPE_BRANCH
980 q1.To.Type = obj.TYPE_REG
983 q2 := obj.Appendp(q1, c.newprog)
986 q2.From.Type = obj.TYPE_REGREG
988 q2.From.Offset = int64(REG_R27)
989 q2.To.Type = obj.TYPE_MEM
993 // maintain FP for DUFFCOPY
994 q3 := obj.Appendp(q2, c.newprog)
997 q3.From.Type = obj.TYPE_CONST
1000 q3.To.Type = obj.TYPE_REG
1003 q5 := obj.Appendp(q4, c.newprog)
1006 q5.From.Type = obj.TYPE_CONST
1009 q5.To.Type = obj.TYPE_REG
1011 q1.From.SetTarget(q5)
1015 // ADR ret_addr, R27
1016 // STP (FP, R27), -24(SP)
1023 // copy DUFFZERO from q1 to q4
1024 q4 := obj.Appendp(p, c.newprog)
1026 q4.As = obj.ADUFFZERO
1030 q1.From.Type = obj.TYPE_BRANCH
1031 q1.To.Type = obj.TYPE_REG
1034 q2 := obj.Appendp(q1, c.newprog)
1037 q2.From.Type = obj.TYPE_REGREG
1039 q2.From.Offset = int64(REG_R27)
1040 q2.To.Type = obj.TYPE_MEM
1044 // maintain FP for DUFFZERO
1045 q3 := obj.Appendp(q2, c.newprog)
1048 q3.From.Type = obj.TYPE_CONST
1051 q3.To.Type = obj.TYPE_REG
1054 q5 := obj.Appendp(q4, c.newprog)
1057 q5.From.Type = obj.TYPE_CONST
1060 q5.To.Type = obj.TYPE_REG
1062 q1.From.SetTarget(q5)
1066 if p.To.Type == obj.TYPE_REG && p.To.Reg == REGSP && p.Spadj == 0 {
1067 f := c.cursym.Func()
1068 if f.FuncFlag&objabi.FuncFlag_SPWRITE == 0 {
1069 c.cursym.Func().FuncFlag |= objabi.FuncFlag_SPWRITE
1070 if ctxt.Debugvlog || !ctxt.IsAsm {
1071 ctxt.Logf("auto-SPWRITE: %s %v\n", c.cursym.Name, p)
1073 ctxt.Diag("invalid auto-SPWRITE in non-assembly")
1075 log.Fatalf("bad SPWRITE")
1083 func nocache(p *obj.Prog) {
1089 var unaryDst = map[obj.As]bool{
1097 var Linkarm64 = obj.LinkArch{
1098 Arch: sys.ArchARM64,
1100 Preprocess: preprocess,
1104 DWARFRegisters: ARM64DWARFRegisters,