Skip to content

Commit 6b1454c

Browse files
committed
gdb: move arch specific values to a different file
- this helps contain the x86 specific registers, masks isolated from the higher level logic Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 617b158 commit 6b1454c

File tree

4 files changed

+45
-30
lines changed

4 files changed

+45
-30
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2024 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//! This file contains architecture specific code for the x86_64
18+
19+
/// Software Breakpoint size in memory
20+
pub(crate) const SW_BP_SIZE: usize = 1;
21+
/// Software Breakpoint opcode - INT3
22+
/// Check page 7-28 Vol. 3A of Intel 64 and IA-32
23+
/// Architectures Software Developer's Manual
24+
pub(crate) const SW_BP_OP: u8 = 0xCC;
25+
/// Software Breakpoint written to memory
26+
pub(crate) const SW_BP: [u8; SW_BP_SIZE] = [SW_BP_OP];
27+
/// Maximum number of supported hardware breakpoints
28+
pub(crate) const MAX_NO_OF_HW_BP: usize = 4;
29+
30+
/// Check page 19-4 Vol. 3B of Intel 64 and IA-32
31+
/// Architectures Software Developer's Manual
32+
/// Bit position of BS flag in DR6 debug register
33+
pub(crate) const DR6_BS_FLAG_POS: usize = 14;
34+
/// Bit mask of BS flag in DR6 debug register
35+
pub(crate) const DR6_BS_FLAG_MASK: u64 = 1 << DR6_BS_FLAG_POS;
36+
/// Bit position of HW breakpoints status in DR6 debug register
37+
pub(crate) const DR6_HW_BP_FLAGS_POS: usize = 0;
38+
/// Bit mask of HW breakpoints status in DR6 debug register
39+
pub(crate) const DR6_HW_BP_FLAGS_MASK: u64 = 0x0F << DR6_HW_BP_FLAGS_POS;

src/hyperlight_host/src/hypervisor/gdb/kvm_debug.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ use kvm_bindings::{
2222
};
2323
use kvm_ioctls::VcpuFd;
2424

25-
use super::{
26-
GuestDebug, VcpuStopReason, X86_64Regs, DR6_BS_FLAG_MASK, DR6_HW_BP_FLAGS_MASK,
27-
MAX_NO_OF_HW_BP, SW_BP_SIZE,
28-
};
25+
use super::arch::{DR6_BS_FLAG_MASK, DR6_HW_BP_FLAGS_MASK, MAX_NO_OF_HW_BP, SW_BP_SIZE};
26+
use super::{GuestDebug, VcpuStopReason, X86_64Regs};
2927
use crate::{new_error, HyperlightError, Result};
3028

3129
/// Exception id for SW breakpoint

src/hyperlight_host/src/hypervisor/gdb/mod.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
mod arch;
1718
mod event_loop;
1819
#[cfg(kvm)]
1920
mod kvm_debug;
@@ -26,6 +27,7 @@ use std::net::TcpListener;
2627
use std::sync::{Arc, Mutex};
2728
use std::thread;
2829

30+
use arch::{SW_BP, SW_BP_SIZE};
2931
use crossbeam_channel::{Receiver, Sender, TryRecvError};
3032
use event_loop::event_loop_thread;
3133
use gdbstub::conn::ConnectionExt;
@@ -43,28 +45,6 @@ use crate::hypervisor::handlers::DbgMemAccessHandlerCaller;
4345
use crate::mem::layout::SandboxMemoryLayout;
4446
use crate::{new_error, HyperlightError};
4547

46-
/// Software Breakpoint size in memory
47-
const SW_BP_SIZE: usize = 1;
48-
/// Software Breakpoint opcode - INT3
49-
/// Check page 7-28 Vol. 3A of Intel 64 and IA-32
50-
/// Architectures Software Developer's Manual
51-
const SW_BP_OP: u8 = 0xCC;
52-
/// Software Breakpoint written to memory
53-
const SW_BP: [u8; SW_BP_SIZE] = [SW_BP_OP];
54-
/// Maximum number of supported hardware breakpoints
55-
const MAX_NO_OF_HW_BP: usize = 4;
56-
57-
/// Check page 19-4 Vol. 3B of Intel 64 and IA-32
58-
/// Architectures Software Developer's Manual
59-
/// Bit position of BS flag in DR6 debug register
60-
const DR6_BS_FLAG_POS: usize = 14;
61-
/// Bit mask of BS flag in DR6 debug register
62-
const DR6_BS_FLAG_MASK: u64 = 1 << DR6_BS_FLAG_POS;
63-
/// Bit position of HW breakpoints status in DR6 debug register
64-
const DR6_HW_BP_FLAGS_POS: usize = 0;
65-
/// Bit mask of HW breakpoints status in DR6 debug register
66-
const DR6_HW_BP_FLAGS_MASK: u64 = 0x0F << DR6_HW_BP_FLAGS_POS;
67-
6848
#[derive(Debug, Error)]
6949
pub(crate) enum GdbTargetError {
7050
#[error("Error encountered while binding to address and port")]

src/hyperlight_host/src/hypervisor/gdb/mshv_debug.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ use mshv_bindings::{
3232
};
3333
use mshv_ioctls::VcpuFd;
3434

35-
use super::{
36-
GuestDebug, VcpuStopReason, X86_64Regs, DR6_BS_FLAG_MASK, DR6_HW_BP_FLAGS_MASK,
37-
MAX_NO_OF_HW_BP, SW_BP_SIZE,
38-
};
35+
use super::arch::{DR6_BS_FLAG_MASK, DR6_HW_BP_FLAGS_MASK, MAX_NO_OF_HW_BP, SW_BP_SIZE};
36+
use super::{GuestDebug, VcpuStopReason, X86_64Regs};
3937
use crate::{new_error, HyperlightError, Result};
4038

4139
#[derive(Debug, Default)]

0 commit comments

Comments
 (0)