Skip to content

Commit da41ce0

Browse files
author
Ian Seyler
committed
Cleanup
1 parent 5b2bfe7 commit da41ce0

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/drivers/net/i8254x.asm

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ net_i8254x_init:
2222
shl eax, 7 ; Quick multiply by 128
2323
add rdi, rax
2424

25-
mov ax, 0x8254
25+
mov ax, 0x8254 ; Driver tag for i8254x
2626
stosw
2727
add rdi, 14
2828

@@ -98,7 +98,6 @@ net_i8254x_reset:
9898
add rsi, rax
9999
add rsi, 16
100100
mov rsi, [rsi]
101-
; mov rsi, [os_NetIOBaseMem]
102101
mov rdi, rsi
103102

104103
; Disable Interrupts
@@ -144,7 +143,7 @@ net_i8254x_reset:
144143
mov ecx, i8254x_MAX_DESC
145144
; TODO - Adjust value based on iid
146145
mov rdi, os_rx_desc
147-
net_i8254x_reset_nextdesc:
146+
net_i8254x_reset_nextdesc:
148147
mov rax, os_PacketBuffers ; Default packet will go here
149148
stosq
150149
xor eax, eax
@@ -221,7 +220,6 @@ net_i8254x_transmit:
221220
mov rdi, os_tx_desc ; Transmit Descriptor Base Address
222221

223222
; Calculate the descriptor to write to
224-
; mov eax, [i8254x_tx_lasttail]
225223
mov eax, [rdx+0x30] ; Get tx_lasttail
226224
push rax ; Save lasttail
227225
shl eax, 4 ; Quick multiply by 16
@@ -240,9 +238,7 @@ net_i8254x_transmit:
240238
pop rax ; Restore lasttail
241239
add eax, 1
242240
and eax, i8254x_MAX_DESC - 1
243-
; mov [i8254x_tx_lasttail], eax
244241
mov [rdx+0x30], eax ; Set tx_lasttail
245-
; mov rdi, [os_NetIOBaseMem]
246242
mov rdi, [rdx+0x10] ; Load the base MMIO of the NIC
247243
mov [rdi+i8254x_TDT], eax ; TDL - Transmit Descriptor Tail
248244

@@ -272,11 +268,9 @@ net_i8254x_poll:
272268
push rax
273269

274270
mov rdi, os_rx_desc
275-
; mov rsi, [os_NetIOBaseMem] ; Load the base MMIO of the NIC
276271
mov rsi, [rdx+0x10] ; Load the base MMIO of the NIC
277272

278273
; Calculate the descriptor to read from
279-
; mov eax, [i8254x_rx_lasthead]
280274
mov eax, [rdx+0x34] ; Get rx_lasthead
281275
shl eax, 4 ; Quick multiply by 16
282276
add eax, 8 ; Offset to bytes received
@@ -291,11 +285,9 @@ net_i8254x_poll:
291285
stosq ; Clear the descriptor length and status
292286

293287
; Increment i8254x_rx_lasthead and the Receive Descriptor Tail
294-
; mov eax, [i8254x_rx_lasthead]
295288
mov eax, [rdx+0x34] ; Get rx_lasthead
296289
add eax, 1
297290
and eax, i8254x_MAX_DESC - 1
298-
; mov [i8254x_rx_lasthead], eax
299291
mov [rdx+0x34], eax ; Set rx_lasthead
300292

301293
mov eax, [rsi+i8254x_RDT] ; Read the current Receive Descriptor Tail
@@ -333,10 +325,6 @@ net_i8254x_poll_end:
333325
; -----------------------------------------------------------------------------
334326

335327

336-
; Variables
337-
;i8254x_tx_lasttail: dd 0
338-
;i8254x_rx_lasthead: dd 0
339-
340328
; Constants
341329
i8254x_MAX_PKT_SIZE equ 16384
342330
i8254x_MAX_DESC equ 16 ; Must be 16, 32, 64, 128, etc.

src/syscalls/net.asm

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ b_net_tx:
5050
cmp byte [os_NetEnabled], 1 ; Check if networking is enabled
5151
jne b_net_tx_fail
5252

53+
shl edx, 7 ; Quick multiply by 128
54+
add edx, net_table ; Add offset to net_table
55+
5356
b_net_tx_maxcheck:
5457
cmp rcx, 1522 ; Fail if more than 1522 bytes
5558
ja b_net_tx_fail
@@ -63,15 +66,13 @@ b_net_tx_maxcheck:
6366
call os_virt_to_phys
6467
xchg rax, rsi
6568

66-
; TODO - This should be per interface
67-
; inc qword [os_net_TXPackets]
68-
; add qword [os_net_TXBytes], rcx
69-
7069
; Call the driver transmit function
71-
shl edx, 7 ; Quick multiply by 128
72-
add edx, net_table ; Add offset to net_table
7370
call [rdx+0x20] ; Call driver transmit function passing RDX as interface
7471

72+
; Increment interface counters
73+
inc qword [rdx+0x40] ; Increment TXPackets
74+
add qword [rdx+0x48], rcx ; Increment TXBytes
75+
7576
; TODO - This should be per interface
7677
mov rax, os_NetLock
7778
call b_smp_unlock
@@ -101,22 +102,26 @@ b_net_rx:
101102
cmp byte [os_NetEnabled], 1 ; Check if networking is enabled
102103
jne b_net_rx_nodata
103104

104-
; Call the driver poll function
105105
shl edx, 7 ; Quick multiply by 128
106106
add edx, net_table ; Add offset to net_table
107+
108+
; Call the driver poll function
107109
call [rdx+0x28] ; Call driver poll function passing RDX as interface
108110

109111
cmp cx, 0
110112
je b_net_rx_nodata
111-
; TODO - This should be per interface
112-
; inc qword [os_net_RXPackets]
113-
; add qword [os_net_RXBytes], rcx
113+
114+
; Increment interface counters
115+
inc qword [rdx+0x50] ; Increment RXPackets
116+
add qword [rdx+0x58], rcx ; Increment RXBytes
114117

115118
mov rsi, os_PacketBuffers ; Packet exists here
116119
push rcx
117120
rep movsb ; Copy packet to requested address
118121
pop rcx
119122

123+
; TODO is b_net_rx_nodata needed if CX is already set
124+
b_net_rx_end:
120125
pop rax
121126
pop rdx
122127
pop rsi

src/sysvar.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ net_table: equ os_SystemVariables + 0xA000
183183
; 0x30
184184
; 32-bit tx_last_head
185185
; 32-bit rx_last_head
186+
; 8 bytes of padding
187+
; 0x40
188+
; 64-bit TXPackets
189+
; 64-bit TXBytes
190+
; 0x50
191+
; 64-bit RXPackets
192+
; 64-bit RXBytes
186193

187194

188195
; Misc

0 commit comments

Comments
 (0)