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#ifndef __ARCH_SIM_H__
42#define __ARCH_SIM_H__
43
44#include <arch/sim_def.h>
45#include <arch/abi.h>
46
47#ifndef __ASSEMBLER__
48
49#include <arch/spr_def.h>
50
51
52
53
54
55
56
57static inline int
58sim_is_simulator(void)
59{
60 return __insn_mfspr(SPR_SIM_CONTROL) != 0;
61}
62
63
64
65
66
67
68
69
70static __inline void
71sim_checkpoint(void)
72{
73 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_CHECKPOINT);
74}
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91static __inline unsigned int
92sim_get_tracing(void)
93{
94 return __insn_mfspr(SPR_SIM_CONTROL) & SIM_TRACE_FLAG_MASK;
95}
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117static __inline void
118sim_set_tracing(unsigned int mask)
119{
120 __insn_mtspr(SPR_SIM_CONTROL, SIM_TRACE_SPR_ARG(mask));
121}
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145static __inline void
146sim_dump(unsigned int mask)
147{
148 __insn_mtspr(SPR_SIM_CONTROL, SIM_DUMP_SPR_ARG(mask));
149}
150
151
152
153
154
155
156
157static __inline void
158sim_print(const char* str)
159{
160 for ( ; *str != '\0'; str++)
161 {
162 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
163 (*str << _SIM_CONTROL_OPERATOR_BITS));
164 }
165 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
166 (SIM_PUTC_FLUSH_BINARY << _SIM_CONTROL_OPERATOR_BITS));
167}
168
169
170
171
172
173
174
175static __inline void
176sim_print_string(const char* str)
177{
178 for ( ; *str != '\0'; str++)
179 {
180 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
181 (*str << _SIM_CONTROL_OPERATOR_BITS));
182 }
183 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
184 (SIM_PUTC_FLUSH_STRING << _SIM_CONTROL_OPERATOR_BITS));
185}
186
187
188
189
190
191
192
193
194
195
196
197
198
199static __inline void
200sim_command(const char* str)
201{
202 int c;
203 do
204 {
205 c = *str++;
206 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_COMMAND |
207 (c << _SIM_CONTROL_OPERATOR_BITS));
208 }
209 while (c);
210}
211
212
213
214#ifndef __DOXYGEN__
215
216
217
218
219
220
221
222
223static __inline long _sim_syscall0(int val)
224{
225 long result;
226 __asm__ __volatile__ ("mtspr SIM_CONTROL, r0"
227 : "=R00" (result) : "R00" (val));
228 return result;
229}
230
231static __inline long _sim_syscall1(int val, long arg1)
232{
233 long result;
234 __asm__ __volatile__ ("{ and zero, r1, r1; mtspr SIM_CONTROL, r0 }"
235 : "=R00" (result) : "R00" (val), "R01" (arg1));
236 return result;
237}
238
239static __inline long _sim_syscall2(int val, long arg1, long arg2)
240{
241 long result;
242 __asm__ __volatile__ ("{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
243 : "=R00" (result)
244 : "R00" (val), "R01" (arg1), "R02" (arg2));
245 return result;
246}
247
248
249
250
251
252
253static __inline long _sim_syscall3(int val, long arg1, long arg2, long arg3)
254{
255 long result;
256 __asm__ __volatile__ ("{ and zero, r3, r3 };"
257 "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
258 : "=R00" (result)
259 : "R00" (val), "R01" (arg1), "R02" (arg2),
260 "R03" (arg3));
261 return result;
262}
263
264static __inline long _sim_syscall4(int val, long arg1, long arg2, long arg3,
265 long arg4)
266{
267 long result;
268 __asm__ __volatile__ ("{ and zero, r3, r4 };"
269 "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
270 : "=R00" (result)
271 : "R00" (val), "R01" (arg1), "R02" (arg2),
272 "R03" (arg3), "R04" (arg4));
273 return result;
274}
275
276static __inline long _sim_syscall5(int val, long arg1, long arg2, long arg3,
277 long arg4, long arg5)
278{
279 long result;
280 __asm__ __volatile__ ("{ and zero, r3, r4; and zero, r5, r5 };"
281 "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
282 : "=R00" (result)
283 : "R00" (val), "R01" (arg1), "R02" (arg2),
284 "R03" (arg3), "R04" (arg4), "R05" (arg5));
285 return result;
286}
287
288
289
290
291
292
293
294
295
296
297
298#define _sim_syscall(syscall_num, nr, args...) \
299 _sim_syscall##nr( \
300 ((syscall_num) << _SIM_CONTROL_OPERATOR_BITS) | SIM_CONTROL_SYSCALL, \
301 ##args)
302
303
304
305#define SIM_WATCHPOINT_READ 1
306#define SIM_WATCHPOINT_WRITE 2
307#define SIM_WATCHPOINT_EXECUTE 4
308
309
310static __inline int
311sim_add_watchpoint(unsigned int process_id,
312 unsigned long address,
313 unsigned long size,
314 unsigned int access_mask,
315 unsigned long user_data)
316{
317 return _sim_syscall(SIM_SYSCALL_ADD_WATCHPOINT, 5, process_id,
318 address, size, access_mask, user_data);
319}
320
321
322static __inline int
323sim_remove_watchpoint(unsigned int process_id,
324 unsigned long address,
325 unsigned long size,
326 unsigned int access_mask,
327 unsigned long user_data)
328{
329 return _sim_syscall(SIM_SYSCALL_REMOVE_WATCHPOINT, 5, process_id,
330 address, size, access_mask, user_data);
331}
332
333
334
335
336
337struct SimQueryWatchpointStatus
338{
339
340
341
342
343 int syscall_status;
344
345
346
347
348
349
350 unsigned long address;
351
352
353 unsigned long user_data;
354};
355
356
357static __inline struct SimQueryWatchpointStatus
358sim_query_watchpoint(unsigned int process_id)
359{
360 struct SimQueryWatchpointStatus status;
361 long val = SIM_CONTROL_SYSCALL |
362 (SIM_SYSCALL_QUERY_WATCHPOINT << _SIM_CONTROL_OPERATOR_BITS);
363 __asm__ __volatile__ ("{ and zero, r1, r1; mtspr SIM_CONTROL, r0 }"
364 : "=R00" (status.syscall_status),
365 "=R01" (status.address),
366 "=R02" (status.user_data)
367 : "R00" (val), "R01" (process_id));
368 return status;
369}
370
371
372
373static __inline void
374sim_validate_lines_evicted(unsigned long long pa, unsigned long length)
375{
376#ifdef __LP64__
377 _sim_syscall(SIM_SYSCALL_VALIDATE_LINES_EVICTED, 2, pa, length);
378#else
379 _sim_syscall(SIM_SYSCALL_VALIDATE_LINES_EVICTED, 4,
380 0 , (long)(pa), (long)(pa >> 32), length);
381#endif
382}
383
384
385
386static __inline long
387sim_query_cpu_speed(void)
388{
389 return _sim_syscall(SIM_SYSCALL_QUERY_CPU_SPEED, 0);
390}
391
392#endif
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
427static __inline int
428sim_set_shaping(unsigned shim,
429 unsigned type,
430 unsigned units,
431 unsigned rate)
432{
433 if ((rate & ~((1 << SIM_CONTROL_SHAPING_RATE_BITS) - 1)) != 0)
434 return 1;
435
436 __insn_mtspr(SPR_SIM_CONTROL, SIM_SHAPING_SPR_ARG(shim, type, units, rate));
437 return 0;
438}
439
440#ifdef __tilegx__
441
442
443static __inline void
444sim_enable_mpipe_links(unsigned mpipe, unsigned long link_mask)
445{
446 __insn_mtspr(SPR_SIM_CONTROL,
447 (SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE |
448 (mpipe << 8) | (1 << 16) | ((uint_reg_t)link_mask << 32)));
449}
450
451
452static __inline void
453sim_disable_mpipe_links(unsigned mpipe, unsigned long link_mask)
454{
455 __insn_mtspr(SPR_SIM_CONTROL,
456 (SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE |
457 (mpipe << 8) | (0 << 16) | ((uint_reg_t)link_mask << 32)));
458}
459
460#endif
461
462
463
464
465
466
467#ifndef __DOXYGEN__
468
469#define sim_enable_functional() \
470 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_ENABLE_FUNCTIONAL)
471
472#define sim_disable_functional() \
473 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_DISABLE_FUNCTIONAL)
474
475#endif
476
477
478
479
480
481
482
483
484
485
486
487
488
489static __inline void
490sim_profiler_enable(void)
491{
492 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_ENABLE);
493}
494
495
496
497static __inline void
498sim_profiler_disable(void)
499{
500 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_DISABLE);
501}
502
503
504
505
506
507
508
509
510
511
512
513static __inline void
514sim_profiler_set_enabled(int enabled)
515{
516 int val =
517 enabled ? SIM_CONTROL_PROFILER_ENABLE : SIM_CONTROL_PROFILER_DISABLE;
518 __insn_mtspr(SPR_SIM_CONTROL, val);
519}
520
521
522
523
524
525
526
527
528
529static __inline int
530sim_profiler_is_enabled(void)
531{
532 return ((__insn_mfspr(SPR_SIM_CONTROL) & SIM_PROFILER_ENABLED_MASK) != 0);
533}
534
535
536
537
538
539
540
541
542static __inline void
543sim_profiler_clear(void)
544{
545 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_CLEAR);
546}
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564static __inline void
565sim_profiler_chip_enable(unsigned int mask)
566{
567 __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_ENABLE_SPR_ARG(mask));
568}
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586static __inline void
587sim_profiler_chip_disable(unsigned int mask)
588{
589 __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_DISABLE_SPR_ARG(mask));
590}
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608static __inline void
609sim_profiler_chip_clear(unsigned int mask)
610{
611 __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_CLEAR_SPR_ARG(mask));
612}
613
614
615
616
617
618
619#ifndef __DOXYGEN__
620
621static __inline void
622sim_event_begin(unsigned int x)
623{
624#if defined(__tile__) && !defined(__NO_EVENT_SPR__)
625 __insn_mtspr(SPR_EVENT_BEGIN, x);
626#endif
627}
628
629static __inline void
630sim_event_end(unsigned int x)
631{
632#if defined(__tile__) && !defined(__NO_EVENT_SPR__)
633 __insn_mtspr(SPR_EVENT_END, x);
634#endif
635}
636
637#endif
638
639#endif
640
641#endif
642
643
644