@@ -42,50 +42,81 @@ pub unsafe fn inl(port: u16) -> u32 {
42
42
ret
43
43
}
44
44
45
- /// Write 8-bit array to port
46
- #[ inline]
47
- pub unsafe fn outsb ( port : u16 , buf : & [ u8 ] ) {
48
- asm ! ( "rep outsb (%esi), %dx"
49
- :: "{ecx}" ( buf. len( ) ) , "{dx}" ( port) , "{esi}" ( buf. as_ptr( ) )
50
- : "ecx" , "edi" ) ;
51
- }
45
+ #[ cfg( all( test, feature = "vmtest" ) ) ]
46
+ mod x86testing {
47
+ use super :: * ;
48
+ use x86test:: * ;
52
49
53
- /// Read 8-bit array from port
54
- # [ inline ]
55
- pub unsafe fn insb ( port : u16 , buf : & mut [ u8 ] ) {
56
- asm ! ( "rep insb %dx, (%edi)"
57
- :: "{ecx}" ( buf . len ( ) ) , "{dx}" ( port) , "{edi}" ( buf . as_ptr ( ) )
58
- : "ecx" , "edi" : "volatile" ) ;
59
- }
50
+ # [ x86test ( ioport ( 0x0 , 0xaf ) ) ]
51
+ fn check_outb ( ) {
52
+ unsafe {
53
+ outb ( 0x0 , 0xaf ) ;
54
+ // hypervisor will fail here if port 0x0 doesn't see 0xaf
55
+ }
56
+ }
60
57
61
- /// Write 16-bit array to port
62
- # [ inline ]
63
- pub unsafe fn outsw ( port : u16 , buf : & [ u16 ] ) {
64
- asm ! ( "rep outsw (%esi), %dx"
65
- :: "{ecx}" ( buf . len ( ) ) , "{dx}" ( port ) , "{esi}" ( buf . as_ptr ( ) )
66
- : "ecx" , "edi" ) ;
67
- }
58
+ # [ x86test ( ioport ( 0x0 , 0xaf ) ) ]
59
+ # [ should_panic ]
60
+ fn check_outb_wrong_value ( ) {
61
+ unsafe {
62
+ outb ( 0x0 , 0xff ) ;
63
+ }
64
+ }
68
65
69
- /// Read 16-bit array from port
70
- #[ inline]
71
- pub unsafe fn insw ( port : u16 , buf : & mut [ u16 ] ) {
72
- asm ! ( "rep insw %dx, (%edi)"
73
- :: "{ecx}" ( buf. len( ) ) , "{dx}" ( port) , "{edi}" ( buf. as_ptr( ) )
74
- : "ecx" , "edi" : "volatile" ) ;
75
- }
66
+ #[ x86test( ioport( 0x1 , 0xad ) ) ]
67
+ fn check_inb ( ) {
68
+ unsafe {
69
+ kassert ! (
70
+ inb( 0x1 ) == 0xad ,
71
+ "`inb` instruction didn't read the correct value"
72
+ ) ;
73
+ }
74
+ }
76
75
77
- /// Write 32-bit array to port
78
- #[ inline]
79
- pub unsafe fn outsl ( port : u16 , buf : & [ u32 ] ) {
80
- asm ! ( "rep outsl (%esi), %dx"
81
- :: "{ecx}" ( buf. len( ) ) , "{dx}" ( port) , "{esi}" ( buf. as_ptr( ) )
82
- : "ecx" , "edi" ) ;
83
- }
76
+ #[ x86test( ioport( 0x2 , 0xad ) ) ]
77
+ #[ should_panic]
78
+ fn check_inb_wrong_port ( ) {
79
+ unsafe {
80
+ kassert ! (
81
+ inb( 0x1 ) == 0xad ,
82
+ "`inb` instruction didn't read the correct value"
83
+ ) ;
84
+ }
85
+ }
84
86
85
- /// Read 32-bit array from port
86
- #[ inline]
87
- pub unsafe fn insl ( port : u16 , buf : & mut [ u32 ] ) {
88
- asm ! ( "rep insl %dx, (%edi)"
89
- :: "{ecx}" ( buf. len( ) ) , "{dx}" ( port) , "{edi}" ( buf. as_ptr( ) )
90
- : "ecx" , "edi" : "volatile" ) ;
87
+ #[ x86test( ioport( 0x2 , 0x99 ) ) ]
88
+ fn check_outw ( ) {
89
+ unsafe {
90
+ super :: outw ( 0x2 , 0x99 ) ;
91
+ // hypervisor will fail here if port 0x2 doesn't see 0x99
92
+ }
93
+ }
94
+
95
+ #[ x86test( ioport( 0x3 , 0xfefe ) ) ]
96
+ fn check_inw ( ) {
97
+ unsafe {
98
+ kassert ! (
99
+ inw( 0x3 ) == 0xfefe ,
100
+ "`inw` instruction didn't read the correct value"
101
+ ) ;
102
+ }
103
+ }
104
+
105
+ #[ x86test( ioport( 0x5 , 0xbeefaaaa ) ) ]
106
+ fn check_outl ( ) {
107
+ unsafe {
108
+ outl ( 0x5 , 0xbeefaaaa ) ;
109
+ // hypervisor will fail here if port 0x5 doesn't see 0xbeefaaaa
110
+ }
111
+ }
112
+
113
+ #[ x86test( ioport( 0x4 , 0xdeadbeef ) ) ]
114
+ fn check_inl ( ) {
115
+ unsafe {
116
+ kassert ! (
117
+ inl( 0x4 ) == 0xdeadbeef ,
118
+ "`inl` instruction didn't read the correct value"
119
+ ) ;
120
+ }
121
+ }
91
122
}
0 commit comments