2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
2015-05-21 13:28:10 -04:00
|
|
|
package arm
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
import (
|
2015-05-21 13:28:10 -04:00
|
|
|
"cmd/compile/internal/gc"
|
2015-02-13 14:40:36 -05:00
|
|
|
"cmd/internal/obj"
|
|
|
|
|
"cmd/internal/obj/arm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func defframe(ptxt *obj.Prog) {
|
|
|
|
|
// fill in argument size, stack size
|
|
|
|
|
ptxt.To.Type = obj.TYPE_TEXTSIZE
|
|
|
|
|
|
2016-03-28 14:31:57 -07:00
|
|
|
ptxt.To.Val = int32(gc.Rnd(gc.Curfn.Type.ArgWidth(), int64(gc.Widthptr)))
|
2015-02-23 16:07:24 -05:00
|
|
|
frame := uint32(gc.Rnd(gc.Stksize+gc.Maxarg, int64(gc.Widthreg)))
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.To.Offset = int64(frame)
|
|
|
|
|
|
|
|
|
|
// insert code to contain ambiguously live variables
|
|
|
|
|
// so that garbage collector only sees initialized values
|
|
|
|
|
// when it looks for pointers.
|
2015-02-23 16:07:24 -05:00
|
|
|
p := ptxt
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
hi := int64(0)
|
|
|
|
|
lo := hi
|
|
|
|
|
r0 := uint32(0)
|
2016-02-25 10:35:19 -08:00
|
|
|
for _, n := range gc.Curfn.Func.Dcl {
|
2015-05-15 10:02:19 -07:00
|
|
|
if !n.Name.Needzero {
|
2015-02-13 14:40:36 -05:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if n.Class != gc.PAUTO {
|
2015-08-30 23:10:03 +02:00
|
|
|
gc.Fatalf("needzero class %d", n.Class)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if n.Type.Width%int64(gc.Widthptr) != 0 || n.Xoffset%int64(gc.Widthptr) != 0 || n.Type.Width == 0 {
|
2016-09-09 21:08:46 -07:00
|
|
|
gc.Fatalf("var %L has size %d offset %d", n, int(n.Type.Width), int(n.Xoffset))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if lo != hi && n.Xoffset+n.Type.Width >= lo-int64(2*gc.Widthptr) {
|
|
|
|
|
// merge with range we already have
|
|
|
|
|
lo = gc.Rnd(n.Xoffset, int64(gc.Widthptr))
|
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// zero old range
|
|
|
|
|
p = zerorange(p, int64(frame), lo, hi, &r0)
|
|
|
|
|
|
|
|
|
|
// set new range
|
|
|
|
|
hi = n.Xoffset + n.Type.Width
|
|
|
|
|
|
|
|
|
|
lo = n.Xoffset
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// zero final range
|
|
|
|
|
zerorange(p, int64(frame), lo, hi, &r0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, r0 *uint32) *obj.Prog {
|
2015-02-23 16:07:24 -05:00
|
|
|
cnt := hi - lo
|
2015-02-13 14:40:36 -05:00
|
|
|
if cnt == 0 {
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
if *r0 == 0 {
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.AMOVW, obj.TYPE_CONST, 0, 0, obj.TYPE_REG, arm.REG_R0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
*r0 = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cnt < int64(4*gc.Widthptr) {
|
2015-02-23 16:07:24 -05:00
|
|
|
for i := int64(0); i < cnt; i += int64(gc.Widthptr) {
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.AMOVW, obj.TYPE_REG, arm.REG_R0, 0, obj.TYPE_MEM, arm.REGSP, 4+frame+lo+i)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
} else if !gc.Nacl && (cnt <= int64(128*gc.Widthptr)) {
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.AADD, obj.TYPE_CONST, 0, 4+frame+lo, obj.TYPE_REG, arm.REG_R1, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
p.Reg = arm.REGSP
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0)
|
2016-09-29 15:43:10 -07:00
|
|
|
gc.Naddr(&p.To, gc.Sysfunc("duffzero"))
|
2015-02-13 14:40:36 -05:00
|
|
|
p.To.Offset = 4 * (128 - cnt/int64(gc.Widthptr))
|
|
|
|
|
} else {
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.AADD, obj.TYPE_CONST, 0, 4+frame+lo, obj.TYPE_REG, arm.REG_R1, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
p.Reg = arm.REGSP
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.AADD, obj.TYPE_CONST, 0, cnt, obj.TYPE_REG, arm.REG_R2, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
p.Reg = arm.REG_R1
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.AMOVW, obj.TYPE_REG, arm.REG_R0, 0, obj.TYPE_MEM, arm.REG_R1, 4)
|
2015-02-23 16:07:24 -05:00
|
|
|
p1 := p
|
2015-02-13 14:40:36 -05:00
|
|
|
p.Scond |= arm.C_PBIT
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.ACMP, obj.TYPE_REG, arm.REG_R1, 0, obj.TYPE_NONE, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
p.Reg = arm.REG_R2
|
2016-09-15 00:34:35 -07:00
|
|
|
p = gc.Appendpp(p, arm.ABNE, obj.TYPE_NONE, 0, 0, obj.TYPE_BRANCH, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
gc.Patch(p, p1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-18 17:26:36 -04:00
|
|
|
func ginsnop() {
|
2016-09-15 08:07:54 -07:00
|
|
|
p := gc.Prog(arm.AAND)
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = arm.REG_R0
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = arm.REG_R0
|
2015-03-18 17:26:36 -04:00
|
|
|
p.Scond = arm.C_SCOND_EQ
|
|
|
|
|
}
|