The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
hook.S
1 /**
2 * Copyright (C) 2008-2019 HPDCS Group
3 * https://hpdcs.github.io
4 *
5 *
6 * This file is part of ROOT-Sim (ROme OpTimistic Simulator).
7 *
8 * ROOT-Sim is free software; you can redistribute it and/or modify it under the
9 * terms of the GNU General Public License as published by the Free Software
10 * Foundation; only version 3 of the License applies.
11 *
12 * ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ROOT-Sim; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * @file hook.S
21 * @brief This hook is dynamically attached to Linux Kernel's finish_task_switch
22 * to call a module-provided function at the end of the reschedule operation.
23 * @author Alessandro Pellegrini
24 * @date February, 2016
25 */
26 
27 .file "preempt_callback.S"
28 .extern the_hook
29 .extern count
30 .extern audit_counter
31 
32 
33 .text
34 .globl schedule_hook
35 .type schedule_hook, @function
36 .globl schedule_hook_2
37 .type schedule_hook_2, @function
38 .globl schedule_hook_end
39 .type schedule_hook_end, @function
40 .globl schedule_hook_patch_point
41 .type schedule_hook_patch_point, @function
42 .globl schedule_hook_patch_point_2
43 .type schedule_hook_patch_point_2, @function
44 
45 
46 schedule_hook:
47  pushq %rax
48  lock incl count(%rip)
49 
50  # This is here just for audit and could be commented out
51  incl audit_counter(%rip)
52 
53  movq the_hook(%rip), %rax
54  test %rax, %rax
55  # jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
56  jz restore
57  callq *%rax
58 restore:
59  popq %rax
60 schedule_hook_patch_point:
61  nop # Five nops to leave place to dynamically patch this function
62  nop
63  nop
64  nop
65  nop
66  nop
67  nop
68  nop
69  nop
70  nop
71  lock decl count(%rip)
72  ret
73 schedule_hook_2:
74  lock incl count(%rip)
75 
76  # This is here just for audit and could be commented out
77  incl audit_counter(%rip)
78 
79  movq the_hook(%rip), %rax
80  test %rax, %rax
81  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
82  callq *%rax
83 schedule_hook_patch_point_2:
84  nop # Five nops to leave place to dynamically patch this function
85  nop
86  nop
87  nop
88  nop
89  nop
90  nop
91  nop
92  nop
93  nop
94  lock decl count(%rip)
95  ret
96 schedule_hook_3:
97  lock incl count(%rip)
98 
99  # This is here just for audit and could be commented out
100  incl audit_counter(%rip)
101 
102  movq the_hook(%rip), %rax
103  test %rax, %rax
104  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
105  callq *%rax
106 schedule_hook_patch_point_3:
107  nop # Five nops to leave place to dynamically patch this function
108  nop
109  nop
110  nop
111  nop
112  nop
113  nop
114  nop
115  nop
116  nop
117  lock decl count(%rip)
118  ret
119 schedule_hook_4:
120  lock incl count(%rip)
121 
122  # This is here just for audit and could be commented out
123  incl audit_counter(%rip)
124 
125  movq the_hook(%rip), %rax
126  test %rax, %rax
127  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
128  callq *%rax
129 schedule_hook_patch_point_4:
130  nop # Five nops to leave place to dynamically patch this function
131  nop
132  nop
133  nop
134  nop
135  nop
136  nop
137  nop
138  nop
139  nop
140  lock decl count(%rip)
141  ret
142 schedule_hook_5:
143  lock incl count(%rip)
144 
145  # This is here just for audit and could be commented out
146  incl audit_counter(%rip)
147 
148  movq the_hook(%rip), %rax
149  test %rax, %rax
150  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
151  callq *%rax
152 schedule_hook_patch_point_5:
153  nop # Five nops to leave place to dynamically patch this function
154  nop
155  nop
156  nop
157  nop
158  nop
159  nop
160  nop
161  nop
162  nop
163  lock decl count(%rip)
164  ret
165 schedule_hook_6:
166  lock incl count(%rip)
167 
168  # This is here just for audit and could be commented out
169  incl audit_counter(%rip)
170 
171  movq the_hook(%rip), %rax
172  test %rax, %rax
173  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
174  callq *%rax
175 schedule_hook_patch_point_6:
176  nop # Five nops to leave place to dynamically patch this function
177  nop
178  nop
179  nop
180  nop
181  nop
182  nop
183  nop
184  nop
185  nop
186  lock decl count(%rip)
187  ret
188 schedule_hook_7:
189  lock incl count(%rip)
190 
191  # This is here just for audit and could be commented out
192  incl audit_counter(%rip)
193 
194  movq the_hook(%rip), %rax
195  test %rax, %rax
196  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
197  callq *%rax
198 schedule_hook_patch_point_7:
199  nop # Five nops to leave place to dynamically patch this function
200  nop
201  nop
202  nop
203  nop
204  nop
205  nop
206  nop
207  nop
208  nop
209  lock decl count(%rip)
210  ret
211 schedule_hook_8:
212  lock incl count(%rip)
213 
214  # This is here just for audit and could be commented out
215  incl audit_counter(%rip)
216 
217  movq the_hook(%rip), %rax
218  test %rax, %rax
219  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
220  callq *%rax
221 schedule_hook_patch_point_8:
222  nop # Five nops to leave place to dynamically patch this function
223  nop
224  nop
225  nop
226  nop
227  nop
228  nop
229  nop
230  nop
231  nop
232  lock decl count(%rip)
233  ret
234 schedule_hook_9:
235  lock incl count(%rip)
236 
237  # This is here just for audit and could be commented out
238  incl audit_counter(%rip)
239 
240  movq the_hook(%rip), %rax
241  test %rax, %rax
242  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
243  callq *%rax
244 schedule_hook_patch_point_9:
245  nop # Five nops to leave place to dynamically patch this function
246  nop
247  nop
248  nop
249  nop
250  nop
251  nop
252  nop
253  nop
254  nop
255  lock decl count(%rip)
256  ret
257 schedule_hook_10:
258  lock incl count(%rip)
259 
260  # This is here just for audit and could be commented out
261  incl audit_counter(%rip)
262 
263  movq the_hook(%rip), %rax
264  test %rax, %rax
265  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
266  callq *%rax
267 schedule_hook_patch_point_10:
268  nop # Five nops to leave place to dynamically patch this function
269  nop
270  nop
271  nop
272  nop
273  nop
274  nop
275  nop
276  nop
277  nop
278  lock decl count(%rip)
279  ret
280 schedule_hook_11:
281  lock incl count(%rip)
282 
283  # This is here just for audit and could be commented out
284  incl audit_counter(%rip)
285 
286  movq the_hook(%rip), %rax
287  test %rax, %rax
288  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
289  callq *%rax
290 schedule_hook_patch_point_11:
291  nop # Five nops to leave place to dynamically patch this function
292  nop
293  nop
294  nop
295  nop
296  nop
297  nop
298  nop
299  nop
300  nop
301  lock decl count(%rip)
302  ret
303 schedule_hook_12:
304  lock incl count(%rip)
305 
306  # This is here just for audit and could be commented out
307  incl audit_counter(%rip)
308 
309  movq the_hook(%rip), %rax
310  test %rax, %rax
311  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
312  callq *%rax
313 schedule_hook_patch_point_12:
314  nop # Five nops to leave place to dynamically patch this function
315  nop
316  nop
317  nop
318  nop
319  nop
320  nop
321  nop
322  nop
323  nop
324  lock decl count(%rip)
325  ret
326 schedule_hook_13:
327  lock incl count(%rip)
328 
329  # This is here just for audit and could be commented out
330  incl audit_counter(%rip)
331 
332  movq the_hook(%rip), %rax
333  test %rax, %rax
334  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
335  callq *%rax
336 schedule_hook_patch_point_13:
337  nop # Five nops to leave place to dynamically patch this function
338  nop
339  nop
340  nop
341  nop
342  nop
343  nop
344  nop
345  nop
346  nop
347  lock decl count(%rip)
348  ret
349 schedule_hook_14:
350  lock incl count(%rip)
351 
352  # This is here just for audit and could be commented out
353  incl audit_counter(%rip)
354 
355  movq the_hook(%rip), %rax
356  test %rax, %rax
357  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
358  callq *%rax
359 schedule_hook_patch_point_14:
360  nop # Five nops to leave place to dynamically patch this function
361  nop
362  nop
363  nop
364  nop
365  nop
366  nop
367  nop
368  nop
369  nop
370  lock decl count(%rip)
371  ret
372 schedule_hook_15:
373  lock incl count(%rip)
374 
375  # This is here just for audit and could be commented out
376  incl audit_counter(%rip)
377 
378  movq the_hook(%rip), %rax
379  test %rax, %rax
380  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
381  callq *%rax
382 schedule_hook_patch_point_15:
383  nop # Five nops to leave place to dynamically patch this function
384  nop
385  nop
386  nop
387  nop
388  nop
389  nop
390  nop
391  nop
392  nop
393  lock decl count(%rip)
394  ret
395 schedule_hook_16:
396  lock incl count(%rip)
397 
398  # This is here just for audit and could be commented out
399  incl audit_counter(%rip)
400 
401  movq the_hook(%rip), %rax
402  test %rax, %rax
403  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
404  callq *%rax
405 schedule_hook_patch_point_16:
406  nop # Five nops to leave place to dynamically patch this function
407  nop
408  nop
409  nop
410  nop
411  nop
412  nop
413  nop
414  nop
415  nop
416  lock decl count(%rip)
417  ret
418 schedule_hook_17:
419  lock incl count(%rip)
420 
421  # This is here just for audit and could be commented out
422  incl audit_counter(%rip)
423 
424  movq the_hook(%rip), %rax
425  test %rax, %rax
426  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
427  callq *%rax
428 schedule_hook_patch_point_17:
429  nop # Five nops to leave place to dynamically patch this function
430  nop
431  nop
432  nop
433  nop
434  nop
435  nop
436  nop
437  nop
438  nop
439  lock decl count(%rip)
440  ret
441 schedule_hook_18:
442  lock incl count(%rip)
443 
444  # This is here just for audit and could be commented out
445  incl audit_counter(%rip)
446 
447  movq the_hook(%rip), %rax
448  test %rax, %rax
449  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
450  callq *%rax
451 schedule_hook_patch_point_18:
452  nop # Five nops to leave place to dynamically patch this function
453  nop
454  nop
455  nop
456  nop
457  nop
458  nop
459  nop
460  nop
461  nop
462  lock decl count(%rip)
463  ret
464 schedule_hook_19:
465  lock incl count(%rip)
466 
467  # This is here just for audit and could be commented out
468  incl audit_counter(%rip)
469 
470  movq the_hook(%rip), %rax
471  test %rax, %rax
472  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
473  callq *%rax
474 schedule_hook_patch_point_19:
475  nop # Five nops to leave place to dynamically patch this function
476  nop
477  nop
478  nop
479  nop
480  nop
481  nop
482  nop
483  nop
484  nop
485  lock decl count(%rip)
486  ret
487 schedule_hook_20:
488  lock incl count(%rip)
489 
490  # This is here just for audit and could be commented out
491  incl audit_counter(%rip)
492 
493  movq the_hook(%rip), %rax
494  test %rax, %rax
495  jz .+4 # location counter points to jz. jz is 2 bytes, callq is 2 bytes.
496  callq *%rax
497 schedule_hook_patch_point_20:
498  nop # Five nops to leave place to dynamically patch this function
499  nop
500  nop
501  nop
502  nop
503  nop
504  nop
505  nop
506  nop
507  nop
508  lock decl count(%rip)
509  ret
510 schedule_hook_end:
511  nop