@@ -795,38 +795,45 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32) *obj.Prog {
795
795
p .Scond = C_SCOND_NE
796
796
}
797
797
798
- // MOVW.LS R14, R3
799
- p = obj .Appendp (ctxt , p )
800
-
801
- p .As = AMOVW
802
- p .Scond = C_SCOND_LS
803
- p .From .Type = obj .TYPE_REG
804
- p .From .Reg = REGLINK
805
- p .To .Type = obj .TYPE_REG
806
- p .To .Reg = REG_R3
807
-
808
- // BL.LS runtime.morestack(SB) // modifies LR, returns with LO still asserted
809
- p = obj .Appendp (ctxt , p )
798
+ // BLS call-to-morestack
799
+ bls := obj .Appendp (ctxt , p )
800
+ bls .As = ABLS
801
+ bls .To .Type = obj .TYPE_BRANCH
810
802
811
- p .As = ABL
812
- p .Scond = C_SCOND_LS
813
- p .To .Type = obj .TYPE_BRANCH
814
- if ctxt .Cursym .Cfunc != 0 {
815
- p .To .Sym = obj .Linklookup (ctxt , "runtime.morestackc" , 0 )
816
- } else if ctxt .Cursym .Text .From3 .Offset & obj .NEEDCTXT == 0 {
817
- p .To .Sym = obj .Linklookup (ctxt , "runtime.morestack_noctxt" , 0 )
818
- } else {
819
- p .To .Sym = obj .Linklookup (ctxt , "runtime.morestack" , 0 )
803
+ var last * obj.Prog
804
+ for last = ctxt .Cursym .Text ; last .Link != nil ; last = last .Link {
820
805
}
821
806
822
- // BLS start
823
- p = obj .Appendp (ctxt , p )
807
+ // MOVW LR, R3
808
+ movw := obj .Appendp (ctxt , last )
809
+ movw .As = AMOVW
810
+ movw .From .Type = obj .TYPE_REG
811
+ movw .From .Reg = REGLINK
812
+ movw .To .Type = obj .TYPE_REG
813
+ movw .To .Reg = REG_R3
814
+
815
+ bls .Pcond = movw
816
+
817
+ // BL runtime.morestack
818
+ call := obj .Appendp (ctxt , movw )
819
+ call .As = obj .ACALL
820
+ call .To .Type = obj .TYPE_BRANCH
821
+ morestack := "runtime.morestack"
822
+ switch {
823
+ case ctxt .Cursym .Cfunc != 0 :
824
+ morestack = "runtime.morestackc"
825
+ case ctxt .Cursym .Text .From3 .Offset & obj .NEEDCTXT == 0 :
826
+ morestack = "runtime.morestack_noctxt"
827
+ }
828
+ call .To .Sym = obj .Linklookup (ctxt , morestack , 0 )
824
829
825
- p .As = ABLS
826
- p .To .Type = obj .TYPE_BRANCH
827
- p .Pcond = ctxt .Cursym .Text .Link
830
+ // B start
831
+ b := obj .Appendp (ctxt , call )
832
+ b .As = obj .AJMP
833
+ b .To .Type = obj .TYPE_BRANCH
834
+ b .Pcond = ctxt .Cursym .Text .Link
828
835
829
- return p
836
+ return bls
830
837
}
831
838
832
839
func initdiv (ctxt * obj.Link ) {
0 commit comments