git-svn-id: https://spexeah.com:8443/svn/Asuro@423 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c

This commit is contained in:
kieron
2018-04-09 15:21:44 +00:00
parent 0a040812c8
commit 8e91ed30ac
15 changed files with 134 additions and 17 deletions

51
src/driver/net/eth2.pas Normal file
View File

@ -0,0 +1,51 @@
unit eth2;
interface
uses
net, nettypes, console;
procedure register;
implementation
var
Registered : Boolean = false;
EthTypes : Array[0..65535] of TRecvCallback;
MAC : puint8;
procedure registerType(eType : uint16; RecvCB : TRecvCallback);
begin
if EthTypes[eType] = nil then EthTypes[eType]:= RecvCB;
end;
procedure recv(p_data : void; p_len : uint16);
var
src, dst : puint8;
proto_type : uint16;
begin
dst:= puint8(p_data);
src:= puint8(p_data + 6);
console.output('net.eth2', 'DEST: ');
writeMACAddress(dst);
console.output('net.eth2', 'SRC: ');
writeMACAddress(src);
end;
procedure register;
var
i : uint16;
begin
if not Registered then begin
for i:=0 to 65535 do begin
EthTypes[i]:= nil;
end;
net.registerNextLayer(@recv);
MAC:= net.getMAC;
Registered:= true;
end;
end;
end.

View File

@ -2,6 +2,50 @@ unit net;
interface
uses
nettypes;
procedure registerNetworkCard(SendCallback : TNetSendCallback; _MAC : puint8);
procedure registerNextLayer(RecvCallback : TRecvCallback);
procedure send(p_data : void; p_len : uint16);
procedure recv(p_data : void; p_len : uint16);
function getMAC : puint8;
implementation
var
CBSend : TNetSendCallback = nil;
CBNext : TRecvCallback = nil;
MAC : puint8 = nil;
procedure registerNetworkCard(SendCallback : TNetSendCallback; _MAC : puint8);
begin
if CBSend = nil then begin
CBSend:= SendCallback;
MAC:= _MAC;
end;
end;
procedure registerNextLayer(RecvCallback : TRecvCallback);
begin
if CBNext = nil then begin
CBNext:= RecvCallback;
end;
end;
procedure send(p_data : void; p_len : uint16);
begin
CBSend(p_data, p_len);
end;
procedure recv(p_data : void; p_len : uint16);
begin
CBNext(p_data, p_len);
end;
function getMAC : puint8;
begin
getMAC:= MAC;
end;
end.

View File

@ -0,0 +1,29 @@
unit nettypes;
interface
uses
console;
type
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
TRecvCallback = procedure(p_data : void; p_len : uint16);
procedure writeMACAddress(mac : puint8);
implementation
procedure writeMACAddress(mac : puint8);
var
i : integer;
begin
console.writehexpair(mac[0]);
for i:=1 to 5 do begin
console.writestring(':');
console.writehexpair(mac[i]);
end;
console.writestringln(' ');
end;
end.

View File

@ -12,7 +12,9 @@ uses
util,
IDT,
PCI,
terminal;
terminal,
net,
nettypes;
const
INTEL_VEND = $8086;
@ -355,6 +357,8 @@ begin
len:= rx_descs[rx_curr]^.length;
//Inject Packet into Network Stack
kpalloc(uint32(buf));
net.recv(void(buf), len);
rx_descs[rx_curr]^.status:= 0;
old_cur:= rx_curr;
@ -374,19 +378,6 @@ begin
end;
end;
procedure writeMACAddress();
var
i : integer;
begin
console.writehexpair(mac[0]);
for i:=1 to 5 do begin
console.writestring(':');
console.writehexpair(mac[i]);
end;
console.writestringln(' ');
end;
procedure fire(); interrupt;
var
status : uint32;
@ -419,7 +410,7 @@ end;
procedure console_command_mac(params : PParamList);
begin
writeMACAddress();
writeMACAddress(@mac[0]);
end;
procedure console_command_sendtest(params : PParamList);
@ -490,7 +481,7 @@ begin
exit;
end;
console.output('E1000 Driver', 'MAC Address: ');
writeMACAddress();
writeMACAddress(@mac[0]);
startLink();
@ -498,9 +489,11 @@ begin
writeCommand($5200 + i*4, 0);
end;
IDT.set_gate(32 + PCI_Info^.interrupt_line, uint32(@fire), $08, ISR_RING_0);
net.registerNetworkCard(@sendPacket, getMACAddress());
IDT.set_gate(32 + PCI_Info^.interrupt_line, uint32(@fire), $08, ISR_RING_0);
enableInturrupt();
rxinit();
txinit();