aboutsummaryrefslogtreecommitdiffstats
path: root/test/MC/Mips/nacl-mask.s
blob: 22286ac7dbbc69c98c3353f79147f926884e5ac0 (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
# RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-nacl %s \
# RUN:  | llvm-objdump -triple mipsel -disassemble -no-show-raw-insn - \
# RUN:  | FileCheck %s

# This test tests that address-masking sandboxing is added when given assembly
# input.


# Test that address-masking sandboxing is added before indirect branches and
# returns.

	.align	4
test1:
	.set	noreorder

        jr	$a0
        nop
        jr	$ra
        nop

# CHECK-LABEL:   test1:

# CHECK:         and     $4, $4, $14
# CHECK-NEXT:    jr      $4

# Check that additional nop is inserted, to align mask and jr to the next
# bundle.

# CHECK-NEXT:    nop
# CHECK-NEXT:    nop

# CHECK:         and     $ra, $ra, $14
# CHECK-NEXT:    jr      $ra



# Test that address-masking sandboxing is added before load instructions.

	.align	4
test2:
	.set	noreorder

        lb      $4, 0($1)
        nop
        lbu     $4, 0($2)
        lh      $4, 0($3)
        lhu     $1, 0($4)
        lw      $4, 0($5)
        lwc1    $f0, 0($6)
        ldc1    $f2, 0($7)
        ll      $4, 0($8)
        lwl     $4, 0($9)
        lwr     $4, 0($10)

        lw      $4, 0($sp)
        lw      $4, 0($t8)

# CHECK-LABEL:   test2:

# CHECK:         and     $1, $1, $15
# CHECK-NEXT:    lb      $4, 0($1)

# Check that additional nop is inserted, to align mask and load to the next
# bundle.

# CHECK:         nop
# CHECK:         nop

# CHECK:         and     $2, $2, $15
# CHECK-NEXT:    lbu     $4, 0($2)

# CHECK:         and     $3, $3, $15
# CHECK-NEXT:    lh      $4, 0($3)

# CHECK:         and     $4, $4, $15
# CHECK-NEXT:    lhu     $1, 0($4)

# CHECK:         and     $5, $5, $15
# CHECK-NEXT:    lw      $4, 0($5)

# CHECK:         and     $6, $6, $15
# CHECK-NEXT:    lwc1    $f0, 0($6)

# CHECK:         and     $7, $7, $15
# CHECK-NEXT:    ldc1    $f2, 0($7)

# CHECK:         and     $8, $8, $15
# CHECK-NEXT:    ll      $4, 0($8)

# CHECK:         and     $9, $9, $15
# CHECK-NEXT:    lwl     $4, 0($9)

# CHECK:         and     $10, $10, $15
# CHECK-NEXT:    lwr     $4, 0($10)


# Check that loads where base register is $sp or $t8 (thread pointer register)
# are not masked.

# CHECK-NOT:     and
# CHECK:         lw      $4, 0($sp)
# CHECK-NOT:     and
# CHECK:         lw      $4, 0($24)



# Test that address-masking sandboxing is added before store instructions.

	.align	4
test3:
	.set	noreorder

        sb      $4, 0($1)
        nop
        sh      $4, 0($2)
        sw      $4, 0($3)
        swc1    $f0, 0($4)
        sdc1    $f2, 0($5)
        swl     $4, 0($6)
        swr     $4, 0($7)
        sc      $4, 0($8)

        sw      $4, 0($sp)
        sw      $4, 0($t8)

# CHECK-LABEL:   test3:

# CHECK:         and     $1, $1, $15
# CHECK-NEXT:    sb      $4, 0($1)

# Check that additional nop is inserted, to align mask and store to the next
# bundle.

# CHECK:         nop
# CHECK:         nop

# CHECK:         and     $2, $2, $15
# CHECK-NEXT:    sh      $4, 0($2)

# CHECK:         and     $3, $3, $15
# CHECK-NEXT:    sw      $4, 0($3)

# CHECK:         and     $4, $4, $15
# CHECK-NEXT:    swc1    $f0, 0($4)

# CHECK:         and     $5, $5, $15
# CHECK-NEXT:    sdc1    $f2, 0($5)

# CHECK:         and     $6, $6, $15
# CHECK-NEXT:    swl     $4, 0($6)

# CHECK:         and     $7, $7, $15
# CHECK-NEXT:    swr     $4, 0($7)

# CHECK:         and     $8, $8, $15
# CHECK-NEXT:    sc      $4, 0($8)


# Check that stores where base register is $sp or $t8 (thread pointer register)
# are not masked.

# CHECK-NOT:     and
# CHECK:         sw      $4, 0($sp)
# CHECK-NOT:     and
# CHECK:         sw      $4, 0($24)



# Test that address-masking sandboxing is added after instructions that change
# stack pointer.

	.align	4
test4:
	.set	noreorder

        addiu   $sp, $sp, 24
        nop
        addu    $sp, $sp, $1
        lw      $sp, 0($2)
        lw      $sp, 123($sp)
        sw      $sp, 123($sp)

# CHECK-LABEL:   test4:

# CHECK:         addiu   $sp, $sp, 24
# CHECK-NEXT:    and     $sp, $sp, $15

# Check that additional nop is inserted, to align instruction and mask to the
# next bundle.

# CHECK:         nop
# CHECK:         nop

# CHECK:         addu    $sp, $sp, $1
# CHECK-NEXT:    and     $sp, $sp, $15

# Since we next check sandboxing sequence which consists of 3 instructions,
# check that 2 additional nops are inserted, to align it to the next bundle.

# CHECK:         nop
# CHECK:         nop


# Check that for instructions that change stack-pointer and load from memory
# masks are added before and after the instruction.

# CHECK:         and     $2, $2, $15
# CHECK-NEXT:    lw      $sp, 0($2)
# CHECK-NEXT:    and     $sp, $sp, $15

# For loads where $sp is destination and base, check that mask is added after
# but not before.

# CHECK-NOT:     and
# CHECK:         lw      $sp, 123($sp)
# CHECK-NEXT:    and     $sp, $sp, $15

# For stores where $sp is destination and base, check that mask is added neither
# before nor after.

# CHECK-NOT:     and
# CHECK:         sw      $sp, 123($sp)
# CHECK-NOT:     and



# Test that call + branch delay is aligned at bundle end.  Test that mask is
# added before indirect calls.

	.align	4
test5:
	.set	noreorder

        jal func1
        addiu $4, $zero, 1

        nop
        bal func2
        addiu $4, $zero, 2

        nop
        nop
        bltzal $t1, func3
        addiu $4, $zero, 3

        nop
        nop
        nop
        bgezal $t2, func4
        addiu $4, $zero, 4

        jalr $t9
        addiu $4, $zero, 5

# CHECK-LABEL:   test5:

# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        jal
# CHECK-NEXT:        addiu   $4, $zero, 1

# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        bal
# CHECK-NEXT:        addiu   $4, $zero, 2

# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        bltzal
# CHECK-NEXT:        addiu   $4, $zero, 3

# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        nop

# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        bgezal
# CHECK-NEXT:        addiu   $4, $zero, 4

# CHECK-NEXT:        nop
# CHECK-NEXT:        and     $25, $25, $14
# CHECK-NEXT:        jalr    $25
# CHECK-NEXT:        addiu   $4, $zero, 5



# Test that we can put non-dangerous loads and stores in branch delay slot.

	.align	4
test6:
	.set	noreorder

        jal func1
        sw      $4, 0($sp)

        bal func2
        lw      $5, 0($t8)

        jalr $t9
        sw      $sp, 0($sp)

# CHECK-LABEL:   test6:

# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        jal
# CHECK-NEXT:        sw      $4, 0($sp)

# CHECK-NEXT:        nop
# CHECK-NEXT:        nop
# CHECK-NEXT:        bal
# CHECK-NEXT:        lw      $5, 0($24)

# CHECK-NEXT:        nop
# CHECK-NEXT:        and     $25, $25, $14
# CHECK-NEXT:        jalr
# CHECK-NEXT:        sw      $sp, 0($sp)