1212; OUT: RAX = MAC Address (bits 0-47) if net is enabled, otherwise 0
1313b_net_status:
1414 push rsi
15+ push rdx
1516 push rcx
1617
1718 cld
1819 xor eax , eax
1920
21+ ; Validity checks
2022 and edx , 0x000000FF ; Keep low 8-bits
21- cmp byte [ os_net_icount ], dl ; Check provided Interface ID
22- jb b_net_status_end ; Bail out if it was an invalid interface
23-
24- mov ecx , 6
23+ mov cl , byte [ os_net_icount ] ; Gather Interface count
24+ cmp cl , 0 ; Is Interface count 0?
25+ je b_net_status_end ; If so, bail out as there are no interfaces
2526
2627 mov rsi , rdx
28+
29+ ; Calculate offset into net_table
2730 shl esi , 7 ; Quick multiply by 128
2831 add esi , net_table ; Add offset to net_table
2932 add esi , 8
3033
34+ mov ecx , 6
3135b_net_status_loadMAC:
3236 shl rax , 8
3337 lodsb
@@ -37,6 +41,7 @@ b_net_status_loadMAC:
3741
3842b_net_status_end:
3943 pop rcx
44+ pop rdx
4045 pop rsi
4146 ret
4247; -----------------------------------------------------------------------------
@@ -51,18 +56,25 @@ b_net_config:
5156 push rsi
5257 push rdx
5358 push rcx
59+ push rbx
5460
61+ ; Validity checks
5562 and edx , 0x000000FF ; Keep low 8-bits
56- cmp byte [ os_net_icount ], dl ; Check provided Interface ID
57- jb b_net_config_end ; Bail out if it was an invalid interface
63+ mov bl , byte [ os_net_icount ] ; Gather Interface count
64+ cmp bl , 0 ; Is Interface count 0?
65+ je b_net_config_end ; If so, bail out as there are no interfaces
66+ cmp bl , dl ; Make sure Interface ID < Interface count
67+ ja b_net_config_end ; Bail out if it was an invalid interface
5868
69+ ; Calculate offset into net_table
5970 shl edx , 7 ; Quick multiply by 128
6071 add edx , net_table ; Add offset to net_table
6172
6273 ; Call the driver config function
6374 call [ rdx + nt_config ] ; Call driver transmit function passing RDX as interface
6475
6576b_net_config_end:
77+ pop rbx
6678 pop rcx
6779 pop rdx
6880 pop rsi
@@ -81,17 +93,20 @@ b_net_tx:
8193 push rcx
8294 push rax
8395
96+ ; Validity checks
8497 and edx , 0x000000FF ; Keep low 8-bits
85- cmp byte [ os_net_icount ], dl ; Check provided Interface ID
86- jb b_net_tx_fail ; Bail out if it was an invalid interface
87-
98+ mov al , byte [ os_net_icount ] ; Gather Interface count
99+ cmp al , 0 ; Is Interface count 0?
100+ je b_net_tx_fail ; If so, bail out as there are no interfaces
101+ cmp al , dl ; Make sure Interface ID < Interface count
102+ jbe b_net_tx_fail ; Bail out if it was an invalid interface
103+ cmp cx , 1522 ; Check how many bytes were to be sent
104+ ja b_net_tx_fail ; Fail if more than 1522 bytes
105+
106+ ; Calculate offset into net_table
88107 shl edx , 7 ; Quick multiply by 128
89108 add edx , net_table ; Add offset to net_table
90109
91- b_net_tx_maxcheck:
92- cmp rcx , 1522 ; Fail if more than 1522 bytes
93- ja b_net_tx_fail
94-
95110 ; Lock the network interface so only one send can happen at a time
96111 mov rax , rdx
97112 add rax , nt_lock
@@ -130,13 +145,19 @@ b_net_tx_fail:
130145; All other registers preserved
131146b_net_rx:
132147 push rdx
148+ push rax
133149
134150 xor ecx , ecx
135151
152+ ; Validity checks
136153 and edx , 0x000000FF ; Keep low 8-bits
137- cmp byte [ os_net_icount ], dl ; Check provided Interface ID
154+ mov al , byte [ os_net_icount ] ; Gather Interface count
155+ cmp al , 0 ; Is Interface count 0?
156+ je b_net_rx_end ; If so, bail out as there are no interfaces
157+ cmp al , dl ; Make sure Interface ID < Interface count
138158 jb b_net_rx_end ; Bail out if it was an invalid interface
139159
160+ ; Calculate offset into net_table
140161 shl edx , 7 ; Quick multiply by 128
141162 add edx , net_table ; Add offset to net_table
142163
@@ -151,6 +172,7 @@ b_net_rx:
151172 add qword [ rdx + nt_rx_bytes ], rcx
152173
153174b_net_rx_end:
175+ pop rax
154176 pop rdx
155177 ret
156178; -----------------------------------------------------------------------------
0 commit comments