@@ -20,8 +20,8 @@ pub mod svsm_gdbstub {
20
20
use crate :: locking:: { LockGuard , SpinLock } ;
21
21
use crate :: mm:: guestmem:: { read_u8, write_u8} ;
22
22
use crate :: mm:: PerCPUPageMappingGuard ;
23
+ use crate :: platform:: SvsmPlatform ;
23
24
use crate :: serial:: { SerialPort , Terminal } ;
24
- use crate :: svsm_console:: SVSMIOPort ;
25
25
use crate :: task:: { is_current_task, TaskContext , INITIAL_TASK_ID , TASKLIST } ;
26
26
use core:: arch:: asm;
27
27
use core:: fmt;
@@ -44,12 +44,11 @@ pub mod svsm_gdbstub {
44
44
const INT3_INSTR : u8 = 0xcc ;
45
45
const MAX_BREAKPOINTS : usize = 32 ;
46
46
47
- pub fn gdbstub_start ( ) -> Result < ( ) , u64 > {
47
+ pub fn gdbstub_start ( platform : & ' static dyn SvsmPlatform ) -> Result < ( ) , u64 > {
48
48
unsafe {
49
- GDB_SERIAL . init ( ) ;
50
49
let mut target = GdbStubTarget :: new ( ) ;
51
50
#[ allow( static_mut_refs) ]
52
- let gdb = GdbStubBuilder :: new ( GdbStubConnection :: new ( ) )
51
+ let gdb = GdbStubBuilder :: new ( GdbStubConnection :: new ( platform ) )
53
52
. with_packet_buffer ( & mut PACKET_BUFFER )
54
53
. build ( )
55
54
. expect ( "Failed to initialise GDB stub" )
@@ -173,8 +172,6 @@ pub mod svsm_gdbstub {
173
172
174
173
static GDB_INITIALISED : AtomicBool = AtomicBool :: new ( false ) ;
175
174
static GDB_STATE : SpinLock < Option < SvsmGdbStub < ' _ > > > = SpinLock :: new ( None ) ;
176
- static GDB_IO : SVSMIOPort = SVSMIOPort :: new ( ) ;
177
- static mut GDB_SERIAL : SerialPort < ' _ > = SerialPort :: new ( & GDB_IO , 0x2f8 ) ;
178
175
static mut PACKET_BUFFER : [ u8 ; 4096 ] = [ 0 ; 4096 ] ;
179
176
// Allocate the GDB stack as an array of u64's to ensure 8 byte alignment of the stack.
180
177
static mut GDB_STACK : [ u64 ; 8192 ] = [ 0 ; 8192 ] ;
@@ -217,7 +214,7 @@ pub mod svsm_gdbstub {
217
214
}
218
215
219
216
struct SvsmGdbStub < ' a > {
220
- gdb : GdbStubStateMachine < ' a , GdbStubTarget , GdbStubConnection > ,
217
+ gdb : GdbStubStateMachine < ' a , GdbStubTarget , GdbStubConnection < ' a > > ,
221
218
target : GdbStubTarget ,
222
219
}
223
220
@@ -306,25 +303,27 @@ pub mod svsm_gdbstub {
306
303
} ) ;
307
304
}
308
305
309
- struct GdbStubConnection ;
306
+ struct GdbStubConnection < ' a > {
307
+ serial_port : SerialPort < ' a > ,
308
+ }
310
309
311
- impl GdbStubConnection {
312
- const fn new ( ) -> Self {
313
- Self { }
310
+ impl < ' a > GdbStubConnection < ' a > {
311
+ fn new ( platform : & ' a dyn SvsmPlatform ) -> Self {
312
+ let serial_port = SerialPort :: new ( platform. get_io_port ( ) , 0x2f8 ) ;
313
+ serial_port. init ( ) ;
314
+ Self { serial_port }
314
315
}
315
316
316
317
fn read ( & self ) -> Result < u8 , & ' static str > {
317
- unsafe { Ok ( GDB_SERIAL . get_byte ( ) ) }
318
+ Ok ( self . serial_port . get_byte ( ) )
318
319
}
319
320
}
320
321
321
- impl Connection for GdbStubConnection {
322
+ impl Connection for GdbStubConnection < ' _ > {
322
323
type Error = usize ;
323
324
324
325
fn write ( & mut self , byte : u8 ) -> Result < ( ) , Self :: Error > {
325
- unsafe {
326
- GDB_SERIAL . put_byte ( byte) ;
327
- }
326
+ self . serial_port . put_byte ( byte) ;
328
327
Ok ( ( ) )
329
328
}
330
329
@@ -742,8 +741,9 @@ pub mod svsm_gdbstub {
742
741
#[ cfg( not( feature = "enable-gdb" ) ) ]
743
742
pub mod svsm_gdbstub {
744
743
use crate :: cpu:: X86ExceptionContext ;
744
+ use crate :: platform:: SvsmPlatform ;
745
745
746
- pub fn gdbstub_start ( ) -> Result < ( ) , u64 > {
746
+ pub fn gdbstub_start ( _platform : & ' static dyn SvsmPlatform ) -> Result < ( ) , u64 > {
747
747
Ok ( ( ) )
748
748
}
749
749
0 commit comments