summaryrefslogtreecommitdiff
path: root/src/arch/arm/isa/insts/ldr64.isa
blob: 8c966e40e9b0f7ba10af1291e749996be06accaa (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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
// -*- mode:c++ -*-

// Copyright (c) 2011-2014 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 LoadInst64(LoadStoreInst):
        execBase = 'Load64'
        micro = False

        def __init__(self, mnem, Name, size=4, sign=False, user=False,
                     literal=False, flavor="normal", top=False):
            super(LoadInst64, self).__init__()

            self.name = mnem
            self.Name = Name
            self.size = size
            self.sign = sign
            self.user = user
            self.literal = literal
            self.flavor = flavor
            self.top = top

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

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

            if self.flavor == "dprefetch":
                self.memFlags.append("Request::PREFETCH")
                self.instFlags = ['IsDataPrefetch']
            elif self.flavor == "iprefetch":
                self.memFlags.append("Request::PREFETCH")
                self.instFlags = ['IsInstPrefetch']
            if self.micro:
                self.instFlags.append("IsMicroop")

            if self.flavor in ("acexp", "exp"):
                # For exclusive pair ops alignment check is based on total size
                self.memFlags.append("%d" % int(math.log(self.size, 2) + 1))
            elif not (self.size == 16 and self.top):
                # Only the first microop should perform alignment checking.
                self.memFlags.append("%d" % int(math.log(self.size, 2)))

            if self.flavor not in ("acquire", "acex", "exclusive",
                                   "acexp", "exp"):
                self.memFlags.append("ArmISA::TLB::AllowUnaligned")

            if self.flavor in ("acquire", "acex", "acexp"):
                self.instFlags.extend(["IsMemBarrier",
                                       "IsWriteBarrier",
                                       "IsReadBarrier"])
            if self.flavor in ("acex", "exclusive", "exp", "acexp"):
                self.memFlags.append("Request::LLSC")

        def buildEACode(self):
            # Address computation code
            eaCode = ""
            if self.flavor == "fp":
                eaCode += vfp64EnabledCheckCode

            if self.literal:
                eaCode += "EA = RawPC"
            else:
                eaCode += SPAlignmentCheckCode + "EA = XBase"

            if self.size == 16:
                if self.top:
                    eaCode += " + (isBigEndian64(xc->tcBase()) ? 0 : 8)"
                else:
                    eaCode += " + (isBigEndian64(xc->tcBase()) ? 8 : 0)"
            if not self.post:
                eaCode += self.offset
            eaCode += ";"

            self.codeBlobs["ea_code"] = eaCode

        def emitHelper(self, base='Memory64', wbDecl=None):
            global header_output, decoder_output, exec_output

            # If this is a microop itself, don't allow anything that would
            # require further microcoding.
            if self.micro:
                assert not wbDecl

            fa_code = None
            if not self.micro and self.flavor in ("normal", "widen", "acquire"):
                fa_code = '''
                    fault->annotate(ArmFault::SAS, %s);
                    fault->annotate(ArmFault::SSE, %s);
                    fault->annotate(ArmFault::SRT, dest);
                    fault->annotate(ArmFault::SF, %s);
                    fault->annotate(ArmFault::AR, %s);
                ''' % ("0" if self.size == 1 else
                       "1" if self.size == 2 else
                       "2" if self.size == 4 else "3",
                       "true" if self.sign else "false",
                       "true" if (self.size == 8 or
                                  self.flavor == "widen") else "false",
                       "true" if self.flavor == "acquire" else "false")

            (newHeader, newDecoder, newExec) = \
                self.fillTemplates(self.name, self.Name, self.codeBlobs,
                                   self.memFlags, self.instFlags,
                                   base, wbDecl, faCode=fa_code)

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

    class LoadImmInst64(LoadInst64):
        def __init__(self, *args, **kargs):
            super(LoadImmInst64, self).__init__(*args, **kargs)
            self.offset = " + imm"

            self.wbDecl = "MicroAddXiUop(machInst, base, base, imm);"

    class LoadRegInst64(LoadInst64):
        def __init__(self, *args, **kargs):
            super(LoadRegInst64, self).__init__(*args, **kargs)
            self.offset = " + extendReg64(XOffset, type, shiftAmt, 64)"

            self.wbDecl = \
                "MicroAddXERegUop(machInst, base, base, " + \
                "                 offset, type, shiftAmt);"

    class LoadRawRegInst64(LoadInst64):
        def __init__(self, *args, **kargs):
            super(LoadRawRegInst64, self).__init__(*args, **kargs)
            self.offset = ""

    class LoadSingle64(LoadInst64):
        def emit(self):
            self.buildEACode()

            # Code that actually handles the access
            if self.flavor in ("dprefetch", "iprefetch"):
                accCode = 'uint64_t temp M5_VAR_USED = Mem%s;'
            elif self.flavor == "fp":
                if self.size in (1, 2, 4):
                    accCode = '''
                        AA64FpDestP0_uw = cSwap(Mem%s,
                                                isBigEndian64(xc->tcBase()));
                        AA64FpDestP1_uw = 0;
                        AA64FpDestP2_uw = 0;
                        AA64FpDestP3_uw = 0;
                    '''
                elif self.size == 8:
                    accCode = '''
                        uint64_t data = cSwap(Mem%s,
                                              isBigEndian64(xc->tcBase()));
                        AA64FpDestP0_uw = (uint32_t)data;
                        AA64FpDestP1_uw = (data >> 32);
                        AA64FpDestP2_uw = 0;
                        AA64FpDestP3_uw = 0;
                    '''
                elif self.size == 16:
                    accCode = '''
                    auto data = cSwap(Mem%s, isBigEndian64(xc->tcBase()));
                    AA64FpDestP0_uw = (uint32_t)data[0];
                    AA64FpDestP1_uw = (data[0] >> 32);
                    AA64FpDestP2_uw = (uint32_t)data[1];
                    AA64FpDestP3_uw = (data[1] >> 32);
                    '''
            elif self.flavor == "widen" or self.size == 8:
                accCode = "XDest = cSwap(Mem%s, isBigEndian64(xc->tcBase()));"
            else:
                accCode = "WDest = cSwap(Mem%s, isBigEndian64(xc->tcBase()));"

            accCode = accCode % buildMemSuffix(self.sign, self.size)

            self.codeBlobs["memacc_code"] = accCode

            # Push it out to the output files
            wbDecl = None
            if self.writeback and not self.micro:
                wbDecl = self.wbDecl
            self.emitHelper(self.base, wbDecl)

    class LoadDouble64(LoadInst64):
        def emit(self):
            self.buildEACode()

            # Code that actually handles the access
            if self.flavor == "fp":
                if self.size == 4:
                    accCode = '''
                        uint64_t data = cSwap(Mem_ud, isBigEndian64(xc->tcBase()));
                        AA64FpDestP0_uw = isBigEndian64(xc->tcBase())
                                            ? (data >> 32)
                                            : (uint32_t)data;
                        AA64FpDestP1_uw = 0;
                        AA64FpDestP2_uw = 0;
                        AA64FpDestP3_uw = 0;
                        AA64FpDest2P0_uw = isBigEndian64(xc->tcBase())
                                            ? (uint32_t)data
                                            : (data >> 32);
                        AA64FpDest2P1_uw = 0;
                        AA64FpDest2P2_uw = 0;
                        AA64FpDest2P3_uw = 0;
                    '''
                elif self.size == 8:
                    accCode = '''
                        uint64_t data_a = cSwap(Mem_tud[0],
                                                isBigEndian64(xc->tcBase()));
                        uint64_t data_b = cSwap(Mem_tud[1],
                                                isBigEndian64(xc->tcBase()));
                        AA64FpDestP0_uw = (uint32_t)data_a;
                        AA64FpDestP1_uw = (uint32_t)(data_a >> 32);
                        AA64FpDestP2_uw = 0;
                        AA64FpDestP3_uw = 0;
                        AA64FpDest2P0_uw = (uint32_t)data_b;
                        AA64FpDest2P1_uw = (uint32_t)(data_b >> 32);
                        AA64FpDest2P2_uw = 0;
                        AA64FpDest2P3_uw = 0;
                    '''
            else:
                if self.sign:
                    if self.size == 4:
                        accCode = '''
                            uint64_t data = cSwap(Mem_ud,
                                                  isBigEndian64(xc->tcBase()));
                            XDest = isBigEndian64(xc->tcBase())
                                    ? sext<32>(data >> 32)
                                    : sext<32>((uint32_t)data);
                            XDest2 = isBigEndian64(xc->tcBase())
                                     ? sext<32>((uint32_t)data)
                                     : sext<32>(data >> 32);
                        '''
                    elif self.size == 8:
                        accCode = '''
                            XDest = cSwap(Mem_tud[0],
                                          isBigEndian64(xc->tcBase()));
                            XDest2 = cSwap(Mem_tud[1],
                                           isBigEndian64(xc->tcBase()));
                        '''
                else:
                    if self.size == 4:
                        accCode = '''
                            uint64_t data = cSwap(Mem_ud,
                                                  isBigEndian64(xc->tcBase()));
                            XDest = isBigEndian64(xc->tcBase())
                                    ? (data >> 32)
                                    : (uint32_t)data;
                            XDest2 = isBigEndian64(xc->tcBase())
                                    ? (uint32_t)data
                                    : (data >> 32);
                        '''
                    elif self.size == 8:
                        accCode = '''
                            XDest = cSwap(Mem_tud[0],
                                          isBigEndian64(xc->tcBase()));
                            XDest2 = cSwap(Mem_tud[1],
                                           isBigEndian64(xc->tcBase()));
                        '''
            self.codeBlobs["memacc_code"] = accCode

            # Push it out to the output files
            wbDecl = None
            if self.writeback and not self.micro:
                wbDecl = self.wbDecl
            self.emitHelper(self.base, wbDecl)

    class LoadImm64(LoadImmInst64, LoadSingle64):
        decConstBase = 'LoadStoreImm64'
        base = 'ArmISA::MemoryImm64'
        writeback = False
        post = False

    class LoadPre64(LoadImmInst64, LoadSingle64):
        decConstBase = 'LoadStoreImm64'
        base = 'ArmISA::MemoryPreIndex64'
        writeback = True
        post = False

    class LoadPost64(LoadImmInst64, LoadSingle64):
        decConstBase = 'LoadStoreImm64'
        base = 'ArmISA::MemoryPostIndex64'
        writeback = True
        post = True

    class LoadReg64(LoadRegInst64, LoadSingle64):
        decConstBase = 'LoadStoreReg64'
        base = 'ArmISA::MemoryReg64'
        writeback = False
        post = False

    class LoadRaw64(LoadRawRegInst64, LoadSingle64):
        decConstBase = 'LoadStoreRaw64'
        base = 'ArmISA::MemoryRaw64'
        writeback = False
        post = False

    class LoadEx64(LoadRawRegInst64, LoadSingle64):
        decConstBase = 'LoadStoreEx64'
        base = 'ArmISA::MemoryEx64'
        writeback = False
        post = False

    class LoadLit64(LoadImmInst64, LoadSingle64):
        decConstBase = 'LoadStoreLit64'
        base = 'ArmISA::MemoryLiteral64'
        writeback = False
        post = False

    def buildLoads64(mnem, NameBase, size, sign, flavor="normal"):
        LoadImm64(mnem, NameBase + "_IMM", size, sign, flavor=flavor).emit()
        LoadPre64(mnem, NameBase + "_PRE", size, sign, flavor=flavor).emit()
        LoadPost64(mnem, NameBase + "_POST", size, sign, flavor=flavor).emit()
        LoadReg64(mnem, NameBase + "_REG", size, sign, flavor=flavor).emit()

    buildLoads64("ldrb", "LDRB64", 1, False)
    buildLoads64("ldrsb", "LDRSBW64", 1, True)
    buildLoads64("ldrsb", "LDRSBX64", 1, True, flavor="widen")
    buildLoads64("ldrh", "LDRH64", 2, False)
    buildLoads64("ldrsh", "LDRSHW64", 2, True)
    buildLoads64("ldrsh", "LDRSHX64", 2, True, flavor="widen")
    buildLoads64("ldrsw", "LDRSW64", 4, True, flavor="widen")
    buildLoads64("ldr", "LDRW64", 4, False)
    buildLoads64("ldr", "LDRX64", 8, False)
    buildLoads64("ldr", "LDRBFP64", 1, False, flavor="fp")
    buildLoads64("ldr", "LDRHFP64", 2, False, flavor="fp")
    buildLoads64("ldr", "LDRSFP64", 4, False, flavor="fp")
    buildLoads64("ldr", "LDRDFP64", 8, False, flavor="fp")

    LoadImm64("prfm", "PRFM64_IMM", 8, flavor="dprefetch").emit()
    LoadReg64("prfm", "PRFM64_REG", 8, flavor="dprefetch").emit()
    LoadLit64("prfm", "PRFM64_LIT", 8, literal=True, flavor="dprefetch").emit()
    LoadImm64("prfum", "PRFUM64_IMM", 8, flavor="dprefetch").emit()

    LoadImm64("ldurb", "LDURB64_IMM", 1, False).emit()
    LoadImm64("ldursb", "LDURSBW64_IMM", 1, True).emit()
    LoadImm64("ldursb", "LDURSBX64_IMM", 1, True, flavor="widen").emit()
    LoadImm64("ldurh", "LDURH64_IMM", 2, False).emit()
    LoadImm64("ldursh", "LDURSHW64_IMM", 2, True).emit()
    LoadImm64("ldursh", "LDURSHX64_IMM", 2, True, flavor="widen").emit()
    LoadImm64("ldursw", "LDURSW64_IMM", 4, True, flavor="widen").emit()
    LoadImm64("ldur", "LDURW64_IMM", 4, False).emit()
    LoadImm64("ldur", "LDURX64_IMM", 8, False).emit()
    LoadImm64("ldur", "LDURBFP64_IMM", 1, flavor="fp").emit()
    LoadImm64("ldur", "LDURHFP64_IMM", 2, flavor="fp").emit()
    LoadImm64("ldur", "LDURSFP64_IMM", 4, flavor="fp").emit()
    LoadImm64("ldur", "LDURDFP64_IMM", 8, flavor="fp").emit()

    LoadImm64("ldtrb", "LDTRB64_IMM", 1, False, True).emit()
    LoadImm64("ldtrsb", "LDTRSBW64_IMM", 1, True, True).emit()
    LoadImm64("ldtrsb", "LDTRSBX64_IMM", 1, True, True, flavor="widen").emit()
    LoadImm64("ldtrh", "LDTRH64_IMM", 2, False, True).emit()
    LoadImm64("ldtrsh", "LDTRSHW64_IMM", 2, True, True).emit()
    LoadImm64("ldtrsh", "LDTRSHX64_IMM", 2, True, True, flavor="widen").emit()
    LoadImm64("ldtrsw", "LDTRSW64_IMM", 4, True, flavor="widen").emit()
    LoadImm64("ldtr", "LDTRW64_IMM", 4, False, True).emit()
    LoadImm64("ldtr", "LDTRX64_IMM", 8, False, True).emit()

    LoadLit64("ldrsw", "LDRSWL64_LIT", 4, True, \
              literal=True, flavor="widen").emit()
    LoadLit64("ldr", "LDRWL64_LIT", 4, False, literal=True).emit()
    LoadLit64("ldr", "LDRXL64_LIT", 8, False, literal=True).emit()
    LoadLit64("ldr", "LDRSFP64_LIT", 4, literal=True, flavor="fp").emit()
    LoadLit64("ldr", "LDRDFP64_LIT", 8, literal=True, flavor="fp").emit()

    LoadRaw64("ldar", "LDARX64", 8, flavor="acquire").emit()
    LoadRaw64("ldar", "LDARW64", 4, flavor="acquire").emit()
    LoadRaw64("ldarh", "LDARH64", 2, flavor="acquire").emit()
    LoadRaw64("ldarb", "LDARB64", 1, flavor="acquire").emit()

    LoadEx64("ldaxr", "LDAXRX64", 8, flavor="acex").emit()
    LoadEx64("ldaxr", "LDAXRW64", 4, flavor="acex").emit()
    LoadEx64("ldaxrh", "LDAXRH64", 2, flavor="acex").emit()
    LoadEx64("ldaxrb", "LDAXRB64", 1, flavor="acex").emit()

    LoadEx64("ldxr", "LDXRX64", 8, flavor="exclusive").emit()
    LoadEx64("ldxr", "LDXRW64", 4, flavor="exclusive").emit()
    LoadEx64("ldxrh", "LDXRH64", 2, flavor="exclusive").emit()
    LoadEx64("ldxrb", "LDXRB64", 1, flavor="exclusive").emit()

    class LoadImmU64(LoadImm64):
        decConstBase = 'LoadStoreImmU64'
        micro = True

    class LoadImmDU64(LoadImmInst64, LoadDouble64):
        decConstBase = 'LoadStoreImmDU64'
        base = 'ArmISA::MemoryDImm64'
        micro = True
        post = False
        writeback = False

    class LoadImmDouble64(LoadImmInst64, LoadDouble64):
        decConstBase = 'LoadStoreImmDU64'
        base = 'ArmISA::MemoryDImm64'
        micro = False
        post = False
        writeback = False

    class LoadRegU64(LoadReg64):
        decConstBase = 'LoadStoreRegU64'
        micro = True

    class LoadLitU64(LoadLit64):
        decConstBase = 'LoadStoreLitU64'
        micro = True

    LoadImmDU64("ldp_uop", "MicroLdPairUop", 8).emit()
    LoadImmDU64("ldp_fp8_uop", "MicroLdPairFp8Uop", 8, flavor="fp").emit()
    LoadImmU64("ldfp16_uop", "MicroLdFp16Uop", 16, flavor="fp").emit()
    LoadReg64("ldfp16reg_uop", "MicroLdFp16RegUop", 16, flavor="fp").emit()

    LoadImmDouble64("ldaxp", "LDAXPW64", 4, flavor="acexp").emit()
    LoadImmDouble64("ldaxp", "LDAXPX64", 8, flavor="acexp").emit()
    LoadImmDouble64("ldxp", "LDXPW64", 4, flavor="exp").emit()
    LoadImmDouble64("ldxp", "LDXPX64", 8, flavor="exp").emit()

    LoadImmU64("ldrxi_uop", "MicroLdrXImmUop", 8).emit()
    LoadRegU64("ldrxr_uop", "MicroLdrXRegUop", 8).emit()
    LoadLitU64("ldrxl_uop", "MicroLdrXLitUop", 8, literal=True).emit()
    LoadImmU64("ldrfpxi_uop", "MicroLdrFpXImmUop", 8, flavor="fp").emit()
    LoadRegU64("ldrfpxr_uop", "MicroLdrFpXRegUop", 8, flavor="fp").emit()
    LoadLitU64("ldrfpxl_uop", "MicroLdrFpXLitUop", 8, literal=True,
               flavor="fp").emit()
    LoadLitU64("ldfp16_lit__uop", "MicroLdFp16LitUop",
               16, literal=True, flavor="fp").emit()
    LoadImmDU64("ldrduxi_uop", "MicroLdrDUXImmUop", 4, sign=False).emit()
    LoadImmDU64("ldrdsxi_uop", "MicroLdrDSXImmUop", 4, sign=True).emit()
    LoadImmDU64("ldrdfpxi_uop", "MicroLdrDFpXImmUop", 4, flavor="fp").emit()
}};