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

This commit is contained in:
kieron 2018-05-12 20:25:42 +00:00
parent ec1c22ff0f
commit 7e293e683b
33 changed files with 129 additions and 55 deletions

BIN
Asuro.iso

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,6 +4,7 @@ interface
type type
{ Generic }
TMACAddress = Array[0..5] of uint8; TMACAddress = Array[0..5] of uint8;
TIPv4Address = Array[0..3] of uint8; TIPv4Address = Array[0..3] of uint8;
@ -25,6 +26,8 @@ type
L4 : uint16; L4 : uint16;
end; end;
{ Context }
PPacketContext = ^TPacketContext; PPacketContext = ^TPacketContext;
TPacketContext = record TPacketContext = record
MAC : TMACPair; MAC : TMACPair;
@ -33,6 +36,8 @@ type
TTL : uint8; TTL : uint8;
end; end;
{ Config }
PIPv4Configuration = ^TIPv4Configuration; PIPv4Configuration = ^TIPv4Configuration;
TIPv4Configuration = record TIPv4Configuration = record
Address : array[0..3] of uint8; Address : array[0..3] of uint8;
@ -41,6 +46,8 @@ type
UP : Boolean; UP : Boolean;
end; end;
{ ARP }
TARPAbstractHeader = record TARPAbstractHeader = record
Hardware_Type : uint16; Hardware_Type : uint16;
Protocol_Type : uint16; Protocol_Type : uint16;
@ -69,6 +76,8 @@ type
Destination_Protocol : TIPv4Address; Destination_Protocol : TIPv4Address;
end; end;
{ ETH2 }
PEthernetHeader = ^TEthernetHeader; PEthernetHeader = ^TEthernetHeader;
TEthernetHeader = bitpacked record TEthernetHeader = bitpacked record
dst : array[0..5] of uint8; dst : array[0..5] of uint8;
@ -77,6 +86,8 @@ type
EthTypeLo : uint8; EthTypeLo : uint8;
end; end;
{ IPv4 }
PIPV4Header = ^TIPV4Header; PIPV4Header = ^TIPV4Header;
TIPV4Header = bitpacked record TIPV4Header = bitpacked record
version : ubit4; version : ubit4;
@ -98,11 +109,6 @@ type
Padding : uint8; Padding : uint8;
end; end;
PIPv4AsWORDs = ^TIPv4AsWORDs;
TIPv4AsWORDs = bitpacked record
WORDS : Array[0..11] of uint16;
end;
TTCPFlags = record TTCPFlags = record
RS : Boolean; RS : Boolean;
DF : Boolean; DF : Boolean;
@ -125,9 +131,13 @@ type
Options : uint32; Options : uint32;
end; end;
{ Callback Types }
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32; TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
TRecvCallback = procedure(p_data : void; p_len : uint16; p_context : PPacketContext); TRecvCallback = procedure(p_data : void; p_len : uint16; p_context : PPacketContext);
{ Constants }
const const
BROADCAST_MAC : Array[0..5] of uint8 = ($FF, $FF, $FF, $FF, $FF, $FF); BROADCAST_MAC : Array[0..5] of uint8 = ($FF, $FF, $FF, $FF, $FF, $FF);
NULL_MAC : Array[0..5] of uint8 = ($00, $00, $00, $00, $00, $00); NULL_MAC : Array[0..5] of uint8 = ($00, $00, $00, $00, $00, $00);

View File

@ -17,9 +17,40 @@ function MACEqual(mac1 : puint8; mac2 : puint8) : boolean;
function IPEqual(ip1 : puint8; ip2 : puint8) : boolean; function IPEqual(ip1 : puint8; ip2 : puint8) : boolean;
function newPacketContext : PPacketContext; function newPacketContext : PPacketContext;
procedure freePacketContext(p_context : PPacketContext); procedure freePacketContext(p_context : PPacketContext);
function calculateChecksum(p_data : puint16; p_len : uint16) : uint16;
function verifyChecksum(p_data : puint16; p_len : uint16) : boolean;
implementation implementation
function calculateChecksum(p_data : puint16; p_len : uint16) : uint16;
var
sum : uint32;
dat : puint16;
carry : uint16;
i : uint32;
l : uint32;
begin
dat:= p_data;
sum:= 0;
l:= p_len div 2;
for i:=1 to l do begin
sum:= sum + p_data^;
inc(p_data);
end;
while (sum > $FFFF) do begin
carry:= (sum AND $FFFF0000) SHR 16;
sum:= (sum AND $FFFF);
sum:= sum + carry;
end;
calculateChecksum:= not (sum AND $FFFF);
end;
function verifyChecksum(p_data : puint16; p_len : uint16) : boolean;
begin
verifyChecksum:= calculateChecksum(p_data, p_len) = $0000;
end;
function stringToMAC(str : pchar) : puint8; function stringToMAC(str : pchar) : puint8;
var var
Mac_Delim : PLinkedListBase; Mac_Delim : PLinkedListBase;

View File

@ -30,29 +30,6 @@ begin
getIPv4Config:= @Config; getIPv4Config:= @Config;
end; end;
function calculateChecksum(p_data : puint16; p_len : uint16) : uint16;
var
sum : uint32;
dat : puint16;
carry : uint16;
i : uint32;
l : uint32;
begin
dat:= p_data;
sum:= 0;
l:= p_len div 2;
for i:=1 to l do begin
sum:= sum + p_data^;
inc(p_data);
end;
while (sum > $FFFF) do begin
carry:= (sum AND $FFFF0000) SHR 16;
sum:= sum + carry;
end;
calculateChecksum:= not sum;
end;
procedure send(p_data : void; p_len : uint16; p_context : PPacketContext); procedure send(p_data : void; p_len : uint16; p_context : PPacketContext);
var var
Header : TIPV4Header; Header : TIPV4Header;
@ -133,8 +110,10 @@ begin
copyIPv4(@AHeader.Src[0], @p_context^.IP.Source[0]); copyIPv4(@AHeader.Src[0], @p_context^.IP.Source[0]);
copyIPv4(@AHeader.Dst[0], @p_context^.IP.Destination[0]); copyIPv4(@AHeader.Dst[0], @p_context^.IP.Destination[0]);
if (IPEqual(@Config.Address[0], @AHeader.Dst[0])) OR (AHeader.Dst[3] = 255) then begin if Config.UP then begin
if Protocols[AHeader.Protocol] <> nil then Protocols[AHeader.Protocol](void(buf), len, p_context); if (IPEqual(@Config.Address[0], @AHeader.Dst[0])) OR (AHeader.Dst[3] = 255) then begin
if Protocols[AHeader.Protocol] <> nil then Protocols[AHeader.Protocol](void(buf), len, p_context);
end;
end; end;
pop_trace; pop_trace;
end; end;

View File

@ -9,14 +9,14 @@ const
VERSION_SUB = '1'; VERSION_SUB = '1';
REVISION = '728'; REVISION = '728';
RELEASE = 'ia'; RELEASE = 'ia';
LINE_COUNT = 28339; LINE_COUNT = 28413;
FILE_COUNT = 90; FILE_COUNT = 90;
DRIVER_COUNT = 32; DRIVER_COUNT = 32;
FPC_VERSION = '2.6.4'; FPC_VERSION = '2.6.4';
NASM_VERSION = '2.10.09'; NASM_VERSION = '2.10.09';
MAKE_VERSION = '3.81'; MAKE_VERSION = '3.81';
COMPILE_DATE = '12/05/18'; COMPILE_DATE = '12/05/18';
COMPILE_TIME = '16:47:26'; COMPILE_TIME = '18:38:28';
implementation implementation

View File

@ -23,6 +23,7 @@ uses
serial; serial;
type type
THaltCallback = procedure();
PParamList = ^TParamList; PParamList = ^TParamList;
TParamList = record TParamList = record
Param : pchar; Param : pchar;
@ -49,6 +50,9 @@ var
bIndex : uint32 = 0; bIndex : uint32 = 0;
Commands : array[0..65534] of TCommand; Commands : array[0..65534] of TCommand;
Working_Directory : PChar = '/'; Working_Directory : PChar = '/';
Halted : Boolean = false;
HaltID : uint32 = 0;
HaltCB : THaltCallback = nil;
procedure run; procedure run;
procedure init; procedure init;
@ -60,6 +64,8 @@ function getParam(index : uint32; params : PParamList) : pchar;
procedure setWorkingDirectory(str : pchar); procedure setWorkingDirectory(str : pchar);
function getWorkingDirectory : pchar; function getWorkingDirectory : pchar;
function getTerminalHWND : uint32; function getTerminalHWND : uint32;
function halt(id : uint32; cb : THaltCallback) : boolean;
function done(id : uint32) : boolean;
implementation implementation
@ -69,6 +75,42 @@ uses
var var
TERMINAL_HWND : HWND = 0; TERMINAL_HWND : HWND = 0;
function halt(id : uint32; cb : THaltCallback) : boolean;
begin
halt:= false;
if not Halted then begin
Halted:= true;
halt:= true;
HaltID:= id;
HaltCB:= cb;
end;
end;
function done(id : uint32) : boolean;
begin
done:= false;
if Halted then begin
if id = HaltID then begin
if HaltCB <> nil then HaltCB();
HaltCB:= nil;
Halted:= false;
HaltID:= 0;
done:= true;
console.writestringWND('Asuro#', TERMINAL_HWND);
console.writestringWND(Working_Directory, TERMINAL_HWND);
console.writestringWND('> ', TERMINAL_HWND);
bIndex:= 0;
memset(uint32(@buffer[0]), 0, 1024);
end;
end;
end;
procedure force_done;
begin
HaltID:= 0;
done(0);
end;
function getTerminalHWND : uint32; function getTerminalHWND : uint32;
begin begin
getTerminalHWND:= TERMINAL_HWND; getTerminalHWND:= TERMINAL_HWND;
@ -381,13 +423,14 @@ begin
console.writestringlnWND('Unknown Command.', TERMINAL_HWND); console.writestringlnWND('Unknown Command.', TERMINAL_HWND);
end; end;
{ Reset the terminal ready for the next command } if not Halted then begin
console.writestringWND('Asuro#', TERMINAL_HWND); { Reset the terminal ready for the next command }
console.writestringWND(Working_Directory, TERMINAL_HWND); console.writestringWND('Asuro#', TERMINAL_HWND);
console.writestringWND('> ', TERMINAL_HWND); console.writestringWND(Working_Directory, TERMINAL_HWND);
bIndex:= 0; console.writestringWND('> ', TERMINAL_HWND);
memset(uint32(@buffer[0]), 0, 1024); bIndex:= 0;
memset(uint32(@buffer[0]), 0, 1024);
end;
pop_trace; pop_trace;
end; end;
@ -395,23 +438,29 @@ procedure key_event(info : TKeyInfo);
begin begin
if TERMINAL_HWND <> 0 then begin if TERMINAL_HWND <> 0 then begin
//writeintlnWND(info.key_code, TERMINAL_HWND); //writeintlnWND(info.key_code, TERMINAL_HWND);
if (info.key_code >= 32) and (info.key_code <= 126) then begin if info.CTRL_DOWN then begin
if bIndex < 1024 then begin if info.key_code = uint8('c') then force_done;
buffer[bIndex]:= info.key_code; end else begin
inc(bIndex); if not halted then begin
console.writecharWND(char(info.key_code), TERMINAL_HWND); if (info.key_code >= 32) and (info.key_code <= 126) then begin
if bIndex < 1024 then begin
buffer[bIndex]:= info.key_code;
inc(bIndex);
console.writecharWND(char(info.key_code), TERMINAL_HWND);
end;
end;
if info.key_code = 8 then begin //backspace
if bIndex > 0 then begin
console.backspaceWND(TERMINAL_HWND);
dec(bIndex);
buffer[bIndex]:= 0;
end;
end;
if info.key_code = 13 then begin //return
process_command;
end;
end; end;
end; end;
if info.key_code = 8 then begin //backspace
if bIndex > 0 then begin
console.backspaceWND(TERMINAL_HWND);
dec(bIndex);
buffer[bIndex]:= 0;
end;
end;
if info.key_code = 13 then begin //return
process_command;
end;
end; end;
end; end;
@ -452,9 +501,14 @@ begin
resetSystem; resetSystem;
end; end;
procedure teapot_halt;
begin
console.writeStringlnWND('Stopped. [CTRL+C]', getTerminalHWND);
end;
procedure teapot(Params : PParamList); procedure teapot(Params : PParamList);
begin begin
console.writestringlnWND('Teapot?', getTerminalHWND); terminal.halt(555, @teapot_halt);
end; end;
procedure init; procedure init;