summaryrefslogtreecommitdiff
path: root/src/arch/arm/isa/insts/ldr.isa
blob: 4c8bfd6127beb66701eb505bb27871e05bebce01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// -*- mode:c++ -*-

// Copyright (c) 2010 ARM Limited
// All rights reserved
//
// The license below extends only to copyright in the software and shall
// not be construed as granting a license to any other intellectual
// property including but not limited to intellectual property relating
// to a hardware implementation of the functionality of the software
// licensed hereunder.  You may use the software subject to the license
// terms below provided that you ensure that this notice is replicated
// unmodified and in its entirety in all distributions of the software,
// modified or unmodified, in source code or in binary form.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met: redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer;
// redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution;
// neither the name of the copyright holders nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Authors: Gabe Black

let {{

    header_output = ""
    decoder_output = ""
    exec_output = ""

    class LoadInst(LoadStoreInst):
        execBase = 'Load'

        def __init__(self, mnem, post, add, writeback,
                     size=4, sign=False, user=False, flavor="normal"):
            super(LoadInst, self).__init__()

            self.name = mnem
            self.post = post
            self.add = add
            self.writeback = writeback
            self.size = size
            self.sign = sign
            self.user = user
            self.flavor = flavor
            self.rasPop = False

            if self.add:
                self.op = " +"
            else:
                self.op = " -"

            self.memFlags = ["ArmISA::TLB::MustBeOne"]
            self.codeBlobs = {"postacc_code" : ""}

        def emitHelper(self, base = 'Memory', wbDecl = None, instFlags = [], pcDecl = None):

            global header_output, decoder_output, exec_output

            codeBlobs = self.codeBlobs
            codeBlobs["predicate_test"] = pickPredicate(codeBlobs)
            (newHeader,
             newDecoder,
             newExec) = self.fillTemplates(self.name, self.Name, codeBlobs,
                                           self.memFlags, instFlags, base,
                                           wbDecl, pcDecl, self.rasPop)

            header_output += newHeader
            decoder_output += newDecoder
            exec_output += newExec

    class RfeInst(LoadInst):
        decConstBase = 'Rfe'

        def __init__(self, mnem, post, add, writeback):
            super(RfeInst, self).__init__(mnem, post, add, writeback)
            self.Name = "RFE_" + loadImmClassName(post, add, writeback, 8)

            self.memFlags.append("ArmISA::TLB::AlignWord")

        def emit(self):
            offset = 0
            if self.post != self.add:
                offset += 4
            if not self.add:
                offset -= 8
            self.codeBlobs["ea_code"] = "EA = Base + %d;" % offset

            wbDiff = -8
            if self.add:
                wbDiff = 8
            accCode = '''
            CPSR cpsr = Cpsr;
            cpsr.nz = CondCodesNZ;
            cpsr.c = CondCodesC;
            cpsr.v = CondCodesV;
            cpsr.ge = CondCodesGE;
            URc = cpsr;
            URa = cSwap<uint32_t>(Mem.ud, cpsr.e);
            URb = cSwap<uint32_t>(Mem.ud >> 32, cpsr.e);
            '''
            self.codeBlobs["memacc_code"] = accCode

            wbDecl = None
            pcDecl = "MicroUopSetPCCPSR(machInst, INTREG_UREG0, INTREG_UREG1, INTREG_UREG2);"

            if self.writeback:
                wbDecl = "MicroAddiUop(machInst, base, base, %d);" % wbDiff
            self.emitHelper('RfeOp', wbDecl, ["IsSerializeAfter", "IsNonSpeculative"], pcDecl)

    class LoadImmInst(LoadInst):
        def __init__(self, *args, **kargs):
            super(LoadImmInst, self).__init__(*args, **kargs)
            self.offset = self.op + " imm"

            if self.add:
                self.wbDecl = "MicroAddiUop(machInst, base, base, imm);"
            else:
                self.wbDecl = "MicroSubiUop(machInst, base, base, imm);"

            if self.add and self.post and self.writeback and not self.sign and \
               not self.user and self.size == 4:
                self.rasPop = True

    class LoadRegInst(LoadInst):
        def __init__(self, *args, **kargs):
            super(LoadRegInst, self).__init__(*args, **kargs)
            self.offset = self.op + " shift_rm_imm(Index, shiftAmt," + \
                                    " shiftType, OptShiftRmCondCodesC)"
            if self.add:
                 self.wbDecl = '''
                     MicroAddUop(machInst, base, base, wbIndexReg, shiftAmt, shiftType);
                 '''
            else:
                 self.wbDecl = '''
                     MicroSubUop(machInst, base, base, wbIndexReg, shiftAmt, shiftType);
                 '''

    class LoadSingle(LoadInst):
        def __init__(self, *args, **kargs):
            super(LoadSingle, self).__init__(*args, **kargs)

            # Build the default class name
            self.Name = self.nameFunc(self.post, self.add, self.writeback,
                                      self.size, self.sign, self.user)

            # Add memory request flags where necessary
            self.memFlags.append("%d" % (self.size - 1))
            if self.user:
                self.memFlags.append("ArmISA::TLB::UserMode")

            self.instFlags = []
            if self.flavor == "dprefetch":
                self.memFlags.append("Request::PREFETCH")
                self.instFlags = ['IsDataPrefetch']
            elif self.flavor == "iprefetch":
                self.memFlags.append("Request::PREFETCH")
                self.instFlags = ['IsInstPrefetch']
            elif self.flavor == "exclusive":
                self.memFlags.append("Request::LLSC")
            elif self.flavor == "normal":
                self.memFlags.append("ArmISA::TLB::AllowUnaligned")

            # Disambiguate the class name for different flavors of loads
            if self.flavor != "normal":
                self.Name = "%s_%s" % (self.name.upper(), self.Name)

        def emit(self):
            # Address compuation code
            eaCode = "EA = Base"
            if not self.post:
                eaCode += self.offset
            eaCode += ";"

            if self.flavor == "fp":
                eaCode += vfpEnabledCheckCode

            self.codeBlobs["ea_code"] = eaCode

            # Code that actually handles the access
            if self.flavor == "dprefetch" or self.flavor == "iprefetch":
                accCode = 'uint64_t temp = Mem%s; temp = temp;'
            elif self.flavor == "fp":
                accCode = "FpDest.uw = cSwap(Mem%s, ((CPSR)Cpsr).e);\n"
            else:
                accCode = "IWDest = cSwap(Mem%s, ((CPSR)Cpsr).e);"
            accCode = accCode % buildMemSuffix(self.sign, self.size)

            self.codeBlobs["memacc_code"] = accCode

            # Push it out to the output files
            base = buildMemBase(self.basePrefix, self.post, self.writeback)
            wbDecl = None
            if self.writeback:
                wbDecl = self.wbDecl
            self.emitHelper(base, wbDecl, self.instFlags)

    def loadImmClassName(post, add, writeback, size=4, sign=False, user=False):
        return memClassName("LOAD_IMM", post, add, writeback, size, sign, user)

    class LoadImm(LoadImmInst, LoadSingle):
        decConstBase = 'LoadImm'
        basePrefix = 'MemoryImm'
        nameFunc = staticmethod(loadImmClassName)

    def loadRegClassName(post, add, writeback, size=4, sign=False, user=False):
        return memClassName("LOAD_REG", post, add, writeback, size, sign, user)

    class LoadReg(LoadRegInst, LoadSingle):
        decConstBase = 'LoadReg'
        basePrefix = 'MemoryReg'
        nameFunc = staticmethod(loadRegClassName)

    class LoadDouble(LoadInst):
        def __init__(self, *args, **kargs):
            super(LoadDouble, self).__init__(*args, **kargs)

            # Build the default class name
            self.Name = self.nameFunc(self.post, self.add, self.writeback)

            # Add memory request flags where necessary
            if self.flavor == "exclusive":
                self.memFlags.append("Request::LLSC")
                self.memFlags.append("ArmISA::TLB::AlignDoubleWord")
            else:
                self.memFlags.append("ArmISA::TLB::AlignWord")

            # Disambiguate the class name for different flavors of loads
            if self.flavor != "normal":
                self.Name = "%s_%s" % (self.name.upper(), self.Name)

        def emit(self):
            # Address computation code
            eaCode = "EA = Base"
            if not self.post:
                eaCode += self.offset
            eaCode += ";"

            if self.flavor == "fp":
                eaCode += vfpEnabledCheckCode

            self.codeBlobs["ea_code"] = eaCode

            # Code that actually handles the access
            if self.flavor != "fp":
                accCode = '''
                CPSR cpsr = Cpsr;
                Dest = cSwap<uint32_t>(Mem.ud, cpsr.e);
                Dest2 = cSwap<uint32_t>(Mem.ud >> 32, cpsr.e);
                '''
            else:
                accCode = '''
                uint64_t swappedMem = cSwap(Mem.ud, ((CPSR)Cpsr).e);
                FpDest.uw = (uint32_t)swappedMem;
                FpDest2.uw = (uint32_t)(swappedMem >> 32);
                '''

            self.codeBlobs["memacc_code"] = accCode

            # Push it out to the output files
            base = buildMemBase(self.basePrefix, self.post, self.writeback)
            wbDecl = None
            if self.writeback:
                wbDecl = self.wbDecl
            self.emitHelper(base, wbDecl)

    def loadDoubleImmClassName(post, add, writeback):
        return memClassName("LOAD_IMMD", post, add, writeback, 4, False, False)

    class LoadDoubleImm(LoadImmInst, LoadDouble):
        decConstBase = 'LoadStoreDImm'
        basePrefix = 'MemoryDImm'
        nameFunc = staticmethod(loadDoubleImmClassName)

    def loadDoubleRegClassName(post, add, writeback):
        return memClassName("LOAD_REGD", post, add, writeback, 4, False, False)

    class LoadDoubleReg(LoadRegInst, LoadDouble):
        decConstBase = 'LoadDReg'
        basePrefix = 'MemoryDReg'
        nameFunc = staticmethod(loadDoubleRegClassName)

    def buildLoads(mnem, size=4, sign=False, user=False):
        LoadImm(mnem, True, True, True, size, sign, user).emit()
        LoadReg(mnem, True, True, True, size, sign, user).emit()
        LoadImm(mnem, True, False, True, size, sign, user).emit()
        LoadReg(mnem, True, False, True, size, sign, user).emit()
        LoadImm(mnem, False, True, True, size, sign, user).emit()
        LoadReg(mnem, False, True, True, size, sign, user).emit()
        LoadImm(mnem, False, False, True, size, sign, user).emit()
        LoadReg(mnem, False, False, True, size, sign, user).emit()
        LoadImm(mnem, False, True, False, size, sign, user).emit()
        LoadReg(mnem, False, True, False, size, sign, user).emit()
        LoadImm(mnem, False, False, False, size, sign, user).emit()
        LoadReg(mnem, False, False, False, size, sign, user).emit()

    def buildDoubleLoads(mnem):
        LoadDoubleImm(mnem, True, True, True).emit()
        LoadDoubleReg(mnem, True, True, True).emit()
        LoadDoubleImm(mnem, True, False, True).emit()
        LoadDoubleReg(mnem, True, False, True).emit()
        LoadDoubleImm(mnem, False, True, True).emit()
        LoadDoubleReg(mnem, False, True, True).emit()
        LoadDoubleImm(mnem, False, False, True).emit()
        LoadDoubleReg(mnem, False, False, True).emit()
        LoadDoubleImm(mnem, False, True, False).emit()
        LoadDoubleReg(mnem, False, True, False).emit()
        LoadDoubleImm(mnem, False, False, False).emit()
        LoadDoubleReg(mnem, False, False, False).emit()

    def buildRfeLoads(mnem):
        RfeInst(mnem, True, True, True).emit()
        RfeInst(mnem, True, True, False).emit()
        RfeInst(mnem, True, False, True).emit()
        RfeInst(mnem, True, False, False).emit()
        RfeInst(mnem, False, True, True).emit()
        RfeInst(mnem, False, True, False).emit()
        RfeInst(mnem, False, False, True).emit()
        RfeInst(mnem, False, False, False).emit()

    def buildPrefetches(mnem, type):
        LoadReg(mnem, False, False, False, size=1, flavor=type).emit()
        LoadImm(mnem, False, False, False, size=1, flavor=type).emit()
        LoadReg(mnem, False, True, False, size=1, flavor=type).emit()
        LoadImm(mnem, False, True, False, size=1, flavor=type).emit()

    buildLoads("ldr")
    buildLoads("ldrt", user=True)
    buildLoads("ldrb", size=1)
    buildLoads("ldrbt", size=1, user=True)
    buildLoads("ldrsb", size=1, sign=True)
    buildLoads("ldrsbt", size=1, sign=True, user=True)
    buildLoads("ldrh", size=2)
    buildLoads("ldrht", size=2, user=True)
    buildLoads("hdrsh", size=2, sign=True)
    buildLoads("ldrsht", size=2, sign=True, user=True)

    buildDoubleLoads("ldrd")

    buildRfeLoads("rfe")

    buildPrefetches("pld", "dprefetch")
    buildPrefetches("pldw", "dprefetch")
    buildPrefetches("pli", "iprefetch")

    LoadImm("ldrex", False, True, False, size=4, flavor="exclusive").emit()
    LoadImm("ldrexh", False, True, False, size=2, flavor="exclusive").emit()
    LoadImm("ldrexb", False, True, False, size=1, flavor="exclusive").emit()
    LoadDoubleImm("ldrexd", False, True, False, flavor="exclusive").emit()

    LoadImm("vldr", False, True, False, size=4, flavor="fp").emit()
    LoadImm("vldr", False, False, False, size=4, flavor="fp").emit()
    LoadDoubleImm("vldr", False, True, False, flavor="fp").emit()
    LoadDoubleImm("vldr", False, False, False, flavor="fp").emit()
}};