Skip to content

Commit 33b1cb1

Browse files
author
Ian Seyler
committed
Adjust b_net_rx for zerocopy
1 parent 32eb966 commit 33b1cb1

File tree

5 files changed

+27
-51
lines changed

5 files changed

+27
-51
lines changed

api/libBareMetal.asm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
; Kernel functions
99
b_input equ 0x0000000000100010 ; Scans keyboard for input. OUT: AL = 0 if no key pressed, otherwise ASCII code
10-
b_output equ 0x0000000000100018 ; Displays a number of characters. IN: RSI = message location, RCX = number of characters
10+
b_output equ 0x0000000000100018 ; Displays a number of characters. IN: RSI = Memory address of message, RCX = number of characters
1111

12-
b_net_tx equ 0x0000000000100020 ; Transmit a packet via a network interface. IN: RSI = Memory location where packet is stored, RCX = Length of packet, RDX = Device
13-
b_net_rx equ 0x0000000000100028 ; Polls the network interface for received packet. IN: RDI = Memory location where packet will be stored, RDX = Device. OUT: RCX = Length of packet
12+
b_net_tx equ 0x0000000000100020 ; Transmit a packet via a network interface. IN: RSI = Memory address of where packet is stored, RCX = Length of packet, RDX = Device
13+
b_net_rx equ 0x0000000000100028 ; Polls the network interface for received packet. IN: RDX = Device. OUT: RDI = Memory address of where packet was stored, RCX = Length of packet
1414

15-
b_nvs_read equ 0x0000000000100030 ; Read data from a non-volatile storage device. IN: RAX = Starting sector, RCX = Number of sectors to read, RDX = Device, RDI = Memory location to store data
16-
b_nvs_write equ 0x0000000000100038 ; Write data to a non-volatile storage device. IN: RAX = Starting sector, RCX = Number of sectors to write, RDX = Device, RSI = Memory location of data to store
15+
b_nvs_read equ 0x0000000000100030 ; Read data from a non-volatile storage device. IN: RAX = Starting sector, RCX = Number of sectors to read, RDX = Device, RDI = Memory address to store data
16+
b_nvs_write equ 0x0000000000100038 ; Write data to a non-volatile storage device. IN: RAX = Starting sector, RCX = Number of sectors to write, RDX = Device, RSI = Memory address of data to store
1717

1818
b_system equ 0x0000000000100040 ; Configure system. IN: RCX = Function, RAX = Variable 1, RDX = Variable 2. OUT: RAX = Result
1919

api/libBareMetal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void b_net_tx(void *mem, u64 len, u64 iid) {
3030

3131
u64 b_net_rx(void *mem, u64 iid) {
3232
u64 tlong;
33-
asm volatile ("call *0x00100028" : "=c"(tlong) : "D"(mem), "d"(iid));
33+
asm volatile ("call *0x00100028" : "=D"(mem), "=c"(tlong) : "d"(iid));
3434
return tlong;
3535
}
3636

src/drivers/net/i8254x.asm

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ net_i8254x_transmit:
270270

271271
; -----------------------------------------------------------------------------
272272
; net_i8254x_poll - Polls the Intel 8254x NIC for a received packet
273-
; IN: RDI = Location to store packet
274-
; RDX = Interface ID
275-
; OUT: RCX = Length of packet
273+
; IN: RDX = Interface ID
274+
; OUT: RDI = Location of stored packet
275+
; RCX = Length of packet
276276
; Note: RDESC Descriptor Format:
277277
; First Qword:
278278
; Bits 63:0 - Buffer Address
@@ -283,8 +283,8 @@ net_i8254x_transmit:
283283
; Bits 47:40 - Errors
284284
; Bits 63:48 - Special
285285
net_i8254x_poll:
286-
push rdi
287286
push rsi ; Used for the base MMIO of the NIC
287+
push rbx
288288
push rax
289289

290290
mov rdi, [rdx+nt_rx_desc]
@@ -293,8 +293,9 @@ net_i8254x_poll:
293293
; Calculate the descriptor to read from
294294
mov eax, [rdx+nt_rx_head] ; Get rx_lasthead
295295
shl eax, 4 ; Quick multiply by 16
296-
add eax, 8 ; Offset to bytes received
297296
add rdi, rax ; Add offset to RDI
297+
mov rbx, [rdi]
298+
add rdi, 8 ; Offset to bytes received
298299
; Todo: read all 64 bits. check status bit for DD
299300
xor ecx, ecx ; Clear RCX
300301
mov cx, [rdi] ; Get the packet length
@@ -303,6 +304,7 @@ net_i8254x_poll:
303304

304305
xor eax, eax
305306
stosq ; Clear the descriptor length and status
307+
mov rdi, rbx
306308

307309
; Increment i8254x_rx_lasthead and the Receive Descriptor Tail
308310
mov eax, [rdx+nt_rx_head] ; Get rx_lasthead
@@ -315,16 +317,10 @@ net_i8254x_poll:
315317
and eax, i8254x_MAX_DESC - 1
316318
mov [rsi+i8254x_RDT], eax ; Write the updated Receive Descriptor Tail
317319

318-
pop rax
319-
pop rsi
320-
pop rdi
321-
ret
322-
323320
net_i8254x_poll_end:
324-
xor ecx, ecx
325321
pop rax
322+
pop rbx
326323
pop rsi
327-
pop rdi
328324
ret
329325
; -----------------------------------------------------------------------------
330326

src/syscalls/io.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ b_input_no_serial:
2929

3030
; -----------------------------------------------------------------------------
3131
; b_output -- Outputs characters
32-
; IN: RSI = message location (non zero-terminated)
32+
; IN: RSI = Memory address of message (non zero-terminated)
3333
; RCX = number of chars to output
3434
; OUT: All registers preserved
3535
b_output:

src/syscalls/net.asm

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ b_net_status_end:
4242

4343
; -----------------------------------------------------------------------------
4444
; b_net_tx -- Transmit a packet via the network
45-
; IN: RSI = Memory location where packet is stored
45+
; IN: RSI = Memory address of where packet is stored
4646
; RCX = Length of packet
4747
; RDX = Interface ID
4848
; OUT: Nothing. All registers preserved
@@ -75,8 +75,8 @@ b_net_tx_maxcheck:
7575
call [rdx+nt_transmit] ; Call driver transmit function passing RDX as interface
7676

7777
; Increment interface counters
78-
inc qword [rdx+nt_tx_packets] ; Increment TXPackets
79-
add qword [rdx+nt_tx_bytes], rcx ; Increment TXBytes
78+
inc qword [rdx+nt_tx_packets]
79+
add qword [rdx+nt_tx_bytes], rcx
8080

8181
; Unlock the network interface
8282
mov rax, rdx
@@ -93,53 +93,33 @@ b_net_tx_fail:
9393

9494
; -----------------------------------------------------------------------------
9595
; b_net_rx -- Polls the network for received data
96-
; IN: RDI = Memory location where packet will be stored
97-
; RDX = Interface ID
98-
; OUT: RCX = Length of packet, 0 if no data
96+
; IN: RDX = Interface ID
97+
; OUT: RDI = Memory address of where packet was stored
98+
; RCX = Length of packet, 0 if no data
9999
; All other registers preserved
100100
b_net_rx:
101-
push rdi
102-
push rsi
103101
push rdx
104-
push rax
105102

106103
xor ecx, ecx
107104

108-
cmp byte [os_NetEnabled], 1 ; Check if networking is enabled
109-
jne b_net_rx_nodata
105+
cmp byte [os_net_icount], dl ; Check if interface is valid
106+
ja b_net_rx_end
110107

111108
shl edx, 7 ; Quick multiply by 128
112109
add edx, net_table ; Add offset to net_table
113110

114111
; Call the driver poll function
115-
call [rdx+nt_poll] ; Call driver poll function passing RDX as interface
112+
call [rdx+nt_poll] ; Call driver poll function passing RDX as interface
116113

117114
cmp cx, 0
118-
je b_net_rx_nodata
115+
je b_net_rx_end
119116

120117
; Increment interface counters
121-
inc qword [rdx+nt_rx_packets] ; Increment RXPackets
122-
add qword [rdx+nt_rx_bytes], rcx ; Increment RXBytes
123-
124-
mov rsi, os_PacketBuffers ; Packet exists here
125-
push rcx
126-
rep movsb ; Copy packet to requested address
127-
pop rcx
118+
inc qword [rdx+nt_rx_packets]
119+
add qword [rdx+nt_rx_bytes], rcx
128120

129-
; TODO is b_net_rx_nodata needed if CX is already set
130121
b_net_rx_end:
131-
pop rax
132-
pop rdx
133-
pop rsi
134-
pop rdi
135-
ret
136-
137-
b_net_rx_nodata:
138-
xor ecx, ecx
139-
pop rax
140122
pop rdx
141-
pop rsi
142-
pop rdi
143123
ret
144124
; -----------------------------------------------------------------------------
145125

0 commit comments

Comments
 (0)