The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
ecs_callback.S
1 /**
2  * @file arch/x86/ecs_callback.S
3  *
4  * @brief Userspace callback for preĆ«mptive Time Warp
5  *
6  * This callback is used to transfer back control from kernel space to
7  * platform space when an artificial page fault due to ECS is faced.
8  *
9  * @copyright
10  * Copyright (C) 2008-2019 HPDCS Group
11  * https://hpdcs.github.io
12  *
13  * This file is part of ROOT-Sim (ROme OpTimistic Simulator).
14  *
15  * ROOT-Sim is free software; you can redistribute it and/or modify it under the
16  * terms of the GNU General Public License as published by the Free Software
17  * Foundation; only version 3 of the License applies.
18  *
19  * ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY
20  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21  * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License along with
24  * ROOT-Sim; if not, write to the Free Software Foundation, Inc.,
25  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26  *
27  * @author Alessandro Pellegrini
28  *
29  * @date December, 2015
30  */
31 
32 .file "ecs_callback.S"
33 
34 #ifdef OS_LINUX
35 
36 #include <arch/asm_defines.h>
37 
38 .extern ECS
39 .extern current
40 
41 .text
42 .globl rootsim_cross_state_dependency_handler
43 .type rootsim_cross_state_dependency_handler, @function
44 
45 # This function is called by the kernel upon a page fault.
46 # This is the organization of the stack after the various push:
47 #
48 # _______________________
49 # | FLAGS |
50 # |---------------------|
51 # | RAX |
52 # |---------------------|
53 # | RETURN ADDRESS | -> Placed by kernel module
54 # |---------------------|
55 #
56 # This function accepts no arguments
57 
58 rootsim_cross_state_dependency_handler:
59  pushq %rax
60 
61  # Save FLAGS
62  lahf
63  seto %al
64  push %rax
65 
66  # Force checking
67  movq $1, %rax
68 
69  # Access to current->context
70  movq $current, %rsi
71  addq $offsetof_LP_State_context, %rsi
72  leaq (%rsi, %rdi, 8), %rdi
73  movq (%rdi), %rdi
74 
75  call _set_jmp
76  testq %rax, %rax
77  jnz .dont
78 
79  // Fake frame to support printf in ECS
80  push %rbp
81  mov %rsp, %rbp
82 
83  call ECS
84 
85  pop %rbp
86 
87  .dont:
88 
89  # Restore FLAGS
90  popq %rax
91  addb $0x7f, %al # Overflow if OF was set
92  sahf
93 
94  popq %rax
95  ret
96 
97 .size rootsim_cross_state_dependency_handler, .-rootsim_cross_state_dependency_handler
98 
99 #endif