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

View File

@ -17,9 +17,40 @@ function MACEqual(mac1 : puint8; mac2 : puint8) : boolean;
function IPEqual(ip1 : puint8; ip2 : puint8) : boolean;
function newPacketContext : 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
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;
var
Mac_Delim : PLinkedListBase;

View File

@ -30,29 +30,6 @@ begin
getIPv4Config:= @Config;
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);
var
Header : TIPV4Header;
@ -133,8 +110,10 @@ begin
copyIPv4(@AHeader.Src[0], @p_context^.IP.Source[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 Protocols[AHeader.Protocol] <> nil then Protocols[AHeader.Protocol](void(buf), len, p_context);
if Config.UP then begin
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;
pop_trace;
end;

View File

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

View File

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