-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmod.rs
More file actions
122 lines (116 loc) · 3.86 KB
/
mod.rs
File metadata and controls
122 lines (116 loc) · 3.86 KB
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
// Copyright 2025 The Axvisor Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
mod accessors;
#[cfg(feature = "tracing")]
mod diff;
#[allow(unused_imports)]
pub use accessors::*;
#[cfg(feature = "tracing")]
pub use diff::*;
/// General-purpose registers for the 64-bit x86 architecture.
///
/// This structure holds the values of the general-purpose registers
/// used in 64-bit x86 systems, allowing for easy manipulation and storage of register states.
#[repr(C)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
// #[cfg_attr(feature = "tracing", derive(Snapshot))]
pub struct GeneralRegisters {
/// The RAX register, typically used for return values in functions.
pub rax: u64,
/// The RCX register, often used as a counter in loops.
pub rcx: u64,
/// The RDX register, commonly used for I/O operations.
pub rdx: u64,
/// The RBX register, usually used as a base pointer or to store values across function calls.
pub rbx: u64,
/// Unused space for the RSP register, preserved for padding or future use.
_unused_rsp: u64,
/// The RBP register, often used as a frame pointer in function calls.
pub rbp: u64,
/// The RSI register, often used as a source index in string operations.
pub rsi: u64,
/// The RDI register, often used as a destination index in string operations.
pub rdi: u64,
/// The R8 register, an additional general-purpose register available in 64-bit mode.
pub r8: u64,
/// The R9 register, an additional general-purpose register available in 64-bit mode.
pub r9: u64,
/// The R10 register, an additional general-purpose register available in 64-bit mode.
pub r10: u64,
/// The R11 register, an additional general-purpose register available in 64-bit mode.
pub r11: u64,
/// The R12 register, an additional general-purpose register available in 64-bit mode.
pub r12: u64,
/// The R13 register, an additional general-purpose register available in 64-bit mode.
pub r13: u64,
/// The R14 register, an additional general-purpose register available in 64-bit mode.
pub r14: u64,
/// The R15 register, an additional general-purpose register available in 64-bit mode.
pub r15: u64,
}
impl GeneralRegisters {
/// The names of the general-purpose registers in 64-bit x86 architecture.
///
/// We follow the order of registers opcode encoding.
pub const REGISTER_NAMES: [&'static str; 16] = [
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", "r8", "r9", "r10", "r11", "r12",
"r13", "r14", "r15",
];
/// Returns the name of the register corresponding to the given index.
pub const fn register_name(index: u8) -> &'static str {
Self::REGISTER_NAMES[index as usize]
}
}
macro_rules! save_regs_to_stack {
() => {
"
push r15
push r14
push r13
push r12
push r11
push r10
push r9
push r8
push rdi
push rsi
push rbp
sub rsp, 8
push rbx
push rdx
push rcx
push rax"
};
}
macro_rules! restore_regs_from_stack {
() => {
"
pop rax
pop rcx
pop rdx
pop rbx
add rsp, 8
pop rbp
pop rsi
pop rdi
pop r8
pop r9
pop r10
pop r11
pop r12
pop r13
pop r14
pop r15"
};
}