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

This commit is contained in:
kieron 2018-04-11 14:21:06 +00:00
parent 3bed07c80a
commit c8b3b14893
43 changed files with 340 additions and 108 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.

View File

@ -3,7 +3,7 @@ unit netutils;
interface
uses
util, nettypes, console, lmemorymanager;
tracer, util, nettypes, console, lmemorymanager;
procedure copyMAC(src : puint8; dst : puint8);
procedure copyIPv4(src : puint8; dst : puint8);
@ -21,13 +21,15 @@ var
i : uint8;
begin
push_trace('netutils.IPEqual');
IPEqual:= true;
for i:=0 to 3 do begin
if ip1[i] <> ip2[i] then begin
IPEqual:= false;
exit;
break;
end;
end;
pop_trace;
end;
function MACEqual(mac1 : puint8; mac2 : puint8) : boolean;
@ -35,13 +37,15 @@ var
i : uint8;
begin
push_trace('netutils.MACEqual');
MACEqual:= true;
for i:=0 to 5 do begin
if mac1[i] <> mac2[i] then begin
MACEqual:= false;
exit;
break;
end;
end;
pop_trace;
end;
procedure writeIPv4Address(ip : puint8);
@ -49,12 +53,14 @@ var
i : integer;
begin
push_trace('netutils.writeIPv4Address');
console.writeint(ip[0]);
for i:=1 to 3 do begin
console.writestring('.');
console.writeint(ip[i]);
end;
console.writestringln(' ');
pop_trace;
end;
procedure writeMACAddress(mac : puint8);
@ -62,23 +68,29 @@ var
i : integer;
begin
push_trace('netutils.writeMACAddress');
console.writehexpair(mac[0]);
for i:=1 to 5 do begin
console.writestring(':');
console.writehexpair(mac[i]);
end;
console.writestringln(' ');
pop_trace;
end;
function newPacketContext : PPacketContext;
begin
push_trace('netutils.newPacketContext');
newPacketContext:= PPacketContext(kalloc(sizeof(TPacketContext)));
memset(uint32(newPacketContext), 0, sizeof(TPacketContext));
pop_trace;
end;
procedure freePacketContext(p_context : PPacketContext);
begin
push_trace('netutils.freePacketContext');
kfree(void(p_context));
pop_trace;
end;
procedure copyMAC(src : puint8; dst : puint8);
@ -86,9 +98,11 @@ var
i : uint8;
begin
push_trace('netutils.copyMAC');
for i:=0 to 5 do begin
dst[i]:= src[i];
end;
pop_trace;
end;
procedure copyIPv4(src : puint8; dst : puint8);
@ -96,9 +110,11 @@ var
i : uint8;
begin
push_trace('netutils.copyIPv4');
for i:=0 to 3 do begin
dst[i]:= src[i];
end;
pop_trace;
end;
end.

View File

@ -3,6 +3,7 @@ unit net;
interface
uses
tracer,
console,
nettypes, netutils;
@ -25,22 +26,28 @@ var
procedure registerNetworkCard(SendCallback : TNetSendCallback; _MAC : puint8);
begin
push_trace('net.registerNetworkCard');
if CBSend = nil then begin
CBSend:= SendCallback;
MAC:= _MAC;
end;
pop_trace;
end;
procedure registerNextLayer(RecvCallback : TRecvCallback);
begin
push_trace('net.registerNextLayer');
if CBNext = nil then begin
CBNext:= RecvCallback;
end;
pop_trace;
end;
procedure send(p_data : void; p_len : uint16);
begin
push_trace('net.send');
if CBSend <> nil then CBSend(p_data, p_len);
pop_trace;
end;
procedure recv(p_data : void; p_len : uint16);
@ -48,22 +55,28 @@ var
context : PPacketContext;
begin
push_trace('net.recv');
//console.outputln('net', 'RECV.');
context:= newPacketContext;
if CBNext <> nil then CBNext(p_data, p_len, context);
freePacketContext(context);
pop_trace;
end;
function getMAC : puint8;
begin
push_trace('net.getMAC');
getMAC:= MAC;
pop_trace;
end;
procedure init;
begin
push_trace('net.init');
eth2.register;
arp.register;
ipv4.register;
pop_trace;
end;
end.

View File

@ -3,6 +3,7 @@ unit eth2;
interface
uses
tracer,
nettypes, netutils,
net,
console;
@ -19,8 +20,10 @@ var
procedure registerType(eType : uint16; RecvCB : TRecvCallback);
begin
push_trace('eth2.registerType');
register;
if EthTypes[eType] = nil then EthTypes[eType]:= RecvCB;
pop_trace;
end;
procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext);
@ -30,6 +33,7 @@ var
buf : puint8;
begin
push_trace('eth2.recv');
//console.outputln('net.eth2', 'RECV.');
buf:= puint8(p_data);
@ -56,6 +60,7 @@ begin
EthTypes[proto_type](void(buf), p_len - 14, p_context);
end;
end;
pop_trace;
end;
procedure register;
@ -63,6 +68,7 @@ var
i : uint16;
begin
push_trace('eth2.register');
if not Registered then begin
for i:=0 to 65535 do begin
EthTypes[i]:= nil;
@ -71,6 +77,7 @@ begin
MAC:= net.getMAC;
Registered:= true;
end;
pop_trace;
end;
end.

View File

@ -3,6 +3,7 @@ unit arp;
interface
uses
tracer,
util, lists, console,
nettypes, netutils,
eth2;
@ -30,14 +31,16 @@ var
r : PARPCacheRecord;
begin
push_trace('arp.findCacheRecordByMAC');
findCacheRecordByMAC:= nil;
for i:=0 to LL_Size(Cache)-1 do begin
r:= PARPCacheRecord(LL_Get(Cache, i));
if MACEqual(mac, @r^.MAC[0]) then begin
findCacheRecordByMAC:= r;
exit;
break;
end;
end;
pop_trace;
end;
function findCacheRecordByIP(ip : puint8) : PARPCacheRecord;
@ -46,14 +49,16 @@ var
r : PARPCacheRecord;
begin
push_trace('arp.findCacheRecordByIP');
findCacheRecordByIP:= nil;
for i:=0 to LL_Size(Cache)-1 do begin
r:= PARPCacheRecord(LL_Get(Cache, i));
if IPEqual(ip, @r^.IP[0]) then begin
findCacheRecordByIP:= r;
exit;
break;
end;
end;
pop_trace;
end;
procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext);
@ -63,6 +68,7 @@ var
CacheElement : PARPCacheRecord;
begin
push_trace('arp.recv');
{ Get our converted Header }
Header:= PARPHeader(p_data);
AHeader.Hardware_Type:= (Header^.Hardware_Type_Hi SHL 8) + Header^.Hardware_Type_Lo;
@ -104,15 +110,18 @@ begin
end;
end;
pop_trace;
end;
procedure register;
begin
push_trace('arp.register');
if not Registered then begin
Cache:= LL_New(sizeof(TARPCacheRecord));
eth2.registerType($0806, @recv);
Registered:= true;
end;
pop_trace;
end;
function IPv4ToMAC(ip : puint8) : puint8;
@ -120,12 +129,14 @@ var
r : PARPCacheRecord;
begin
push_trace('arp.IPv4ToMAC');
register;
IPv4ToMAC:= nil;
r:= findCacheRecordByIP(ip);
if r <> nil then begin
IPv4ToMAC:= @r^.MAC[0];
end;
pop_trace;
end;
function MACToIIPv4(mac : puint8) : puint8;
@ -133,12 +144,14 @@ var
r : PARPCacheRecord;
begin
push_trace('arp.MACToIPv4');
register;
MACToIIPv4:= nil;
r:= findCacheRecordByMAC(mac);
if r <> nil then begin
MACToIIPv4:= @r^.IP[0];
end;
pop_trace;
end;
end.

View File

@ -3,6 +3,7 @@ unit ipv4;
interface
uses
tracer,
util, console, terminal,
net, nettypes, netutils,
eth2;
@ -26,6 +27,7 @@ var
len : uint16;
begin
push_trace('ipv4.recv');
//console.outputln('net.ipv4', 'RECV.');
Header:= PIPV4Header(p_data);
AHeader.version:= Header^.version;
@ -61,12 +63,13 @@ 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;
pop_trace;
end;
procedure terminal_command_ifconfig(params : PParamList);
begin
push_trace('ipv4.terminal_command_ifconfig');
if paramCount(params) > 2 then begin
end else begin
writestring(' MAC: ');
writeMACAddress(net.GetMAC);
@ -81,6 +84,7 @@ begin
else
writestringln(' NetUP: false');
end;
pop_trace;
end;
procedure register;
@ -88,6 +92,7 @@ var
i : uint8;
begin
push_trace('ipv4.register');
if not Registered then begin
for i:=0 to 255 do begin
Protocols[i]:= nil;
@ -102,12 +107,15 @@ begin
terminal.registerCommand('IFCONFIG', @terminal_command_ifconfig, 'Configure Network Settings.');
Registered:= true;
end;
pop_trace;
end;
procedure registerProtocol(Protocol_ID : uint8; recv_callback : TRecvCallback);
begin
push_trace('ipv4.registerProtocol');
register;
if Protocols[Protocol_ID] = nil then Protocols[Protocol_ID]:= recv_callback;
pop_trace;
end;
end.

View File

@ -3,6 +3,7 @@ unit E1000;
interface
uses
tracer,
console,
strings,
vmemorymanager,
@ -157,6 +158,7 @@ var
mem : puint32;
begin
push_trace('E1000.writeCommand');
if (bar_type = 0) then begin
mem:= puint32(mem_base + p_address);
mem^:= p_value;
@ -164,6 +166,7 @@ begin
outl(io_base + 0, p_address);
outl(io_base + 4, p_address)
end;
pop_trace;
end;
function readCommand(p_address : uint16) : uint32;
@ -171,6 +174,7 @@ var
mem : puint32;
begin
push_trace('E1000.readCommand');
if (bar_type = 0) then begin
mem:= puint32(mem_base + p_address);
readCommand:= mem^;
@ -178,6 +182,7 @@ begin
outl(io_base, p_address);
readCommand:= inl(io_base + 4);
end;
pop_trace;
end;
function detectEEPROM() : boolean;
@ -185,6 +190,7 @@ var
val, i : uint32;
begin
push_trace('E1000.detectEEPROM');
val:= 0;
writeCommand(REG_EEPROM, $1);
for i:=0 to 1000 do begin
@ -193,6 +199,7 @@ begin
if (val and $10) > 0 then eeprom_exists:= true else eeprom_exists:= false;
end;
detectEEPROM:= eeprom_exists;
pop_trace;
end;
function EEPROMRead( address : uint8 ) : uint32;
@ -201,6 +208,7 @@ var
tmp : uint32;
begin
push_trace('E1000.EEPROMRead');
tmp:= 0;
if (eeprom_exists) then begin
writeCommand( REG_EEPROM, 1 OR (uint32(address) SHL 8) );
@ -215,6 +223,7 @@ begin
end;
data:= uint16( (tmp SHR 16) AND ($FFFF) );
EEPROMRead:= data;
pop_trace;
end;
function readMACAddress() : boolean;
@ -226,6 +235,7 @@ var
i : uint32;
begin
push_trace('E1000.readMACAddress');
res:= true;
if (eeprom_exists) then begin
temp:= EEPROMRead(0);
@ -249,6 +259,7 @@ begin
end;
end;
readMACAddress:= res;
pop_trace;
end;
procedure startLink();
@ -256,8 +267,10 @@ var
val : uint32;
begin
push_trace('E1000.startLink');
val:= readCommand(REG_CTRL);
writeCommand(REG_CTRL, val OR ECTRL_SLU);
pop_trace;
end;
procedure rxinit();
@ -268,6 +281,7 @@ var
i : uint32;
begin
push_trace('E1000.rxinit');
ptr:= puint8(kalloc(sizeof(TE1000_rx_desc) * E1000_NUM_RX_DESC + 16));
descs:= PE1000_rx_desc(ptr);
for i:=0 to E1000_NUM_RX_DESC do begin
@ -297,6 +311,7 @@ begin
rx_curr:= 0;
writeCommand(REG_RCTRL, RCTL_EN OR RCTL_SBP OR RCTL_UPE OR RCTL_MPE OR RCTL_LBM_NONE OR RTCL_RDMTS_HALF OR RCTL_BAM OR RCTL_SECRC OR RCTL_BSIZE_2048);
pop_trace;
end;
procedure txinit();
@ -307,6 +322,7 @@ var
i : uint32;
begin
push_trace('E1000.txinit');
ptr:= puint8(kalloc(sizeof(TE1000_tx_desc) * (E1000_NUM_TX_DESC + 16)));
descs:= PE1000_tx_desc(ptr);
for i:=0 to E1000_NUM_TX_DESC do begin
@ -338,13 +354,16 @@ begin
writeCommand(REG_TCTRL, $3003F0FA);
writeCommand(REG_TIPG, $0060200A);
end;
pop_trace;
end;
procedure enableInturrupt();
begin
push_trace('E1000.enableInterrupt');
writeCommand(REG_IMASK, $1F6DC);
writeCommand(REG_IMASK, $FF AND NOT(4));
readCommand($C0);
pop_trace;
end;
procedure handleReceive();
@ -356,6 +375,7 @@ var
i : uint16;
begin
push_trace('E1000.handleReceive');
while (rx_descs[rx_curr]^.status AND $1) > 0 do begin
got_packet:= true;
buf:= rx_buffs[rx_curr];
@ -369,6 +389,7 @@ begin
rx_curr:= (rx_curr + 1) mod E1000_NUM_RX_DESC;
writeCommand(REG_RXDESCTAIL, old_cur);
end;
pop_trace;
end;
procedure writeCardType();
@ -388,6 +409,7 @@ var
data : uint32;
begin
push_trace('E1000.fire');
//console.outputln('E1000 Driver', 'FIRED.');
status:= readCommand($C0);
@ -412,11 +434,14 @@ begin
//CLI (Not 100% Nessisary as this is done on IRET)
CLI;
pop_trace;
end;
procedure console_command_mac(params : PParamList);
begin
push_trace('E1000.console_command_mac');
writeMACAddress(@mac[0]);
pop_trace;
end;
procedure console_command_sendtest(params : PParamList);
@ -436,6 +461,7 @@ var
);
begin
push_trace('E1000.console_command_sendtest');
TestPacket[6]:= mac[0];
TestPacket[7]:= mac[1];
TestPacket[8]:= mac[2];
@ -450,6 +476,7 @@ begin
TestPacket[26]:= mac[4];
TestPacket[27]:= mac[5];
sendPacket(void(@TestPacket[0]), 42);
pop_trace;
end;
function load(ptr : void) : boolean;
@ -460,6 +487,8 @@ var
iline : uint8;
begin
push_trace('E1000.load');
console.outputln('E1000 Driver', 'Load Start.');
writeCardType();
@ -484,58 +513,66 @@ begin
if not readMACAddress() then begin
console.outputln('E1000 Driver', 'MAC Read Failed.');
load:= false;
exit;
end else begin
console.output('E1000 Driver', 'MAC Address: ');
writeMACAddress(@mac[0]);
startLink();
for i:=0 to $80 do begin
writeCommand($5200 + i*4, 0);
end;
net.registerNetworkCard(@sendPacket, getMACAddress());
IDT.set_gate(32 + PCI_Info^.interrupt_line, uint32(@fire), $08, ISR_RING_0);
enableInturrupt();
rxinit();
txinit();
load:= true;
if load then registercommand('E1000', @console_command_sendtest, 'Test sending a ARP Request.');
if load then registercommand('MAC', @console_command_mac, 'Print MAC Address.');
end;
console.output('E1000 Driver', 'MAC Address: ');
writeMACAddress(@mac[0]);
startLink();
for i:=0 to $80 do begin
writeCommand($5200 + i*4, 0);
end;
net.registerNetworkCard(@sendPacket, getMACAddress());
IDT.set_gate(32 + PCI_Info^.interrupt_line, uint32(@fire), $08, ISR_RING_0);
enableInturrupt();
rxinit();
txinit();
load:= true;
if load then registercommand('E1000', @console_command_sendtest, 'Test sending a ARP Request.');
if load then registercommand('MAC', @console_command_mac, 'Print MAC Address.');
console.outputln('E1000 Driver', 'Load Finish.');
pop_trace;
end;
function loadE1000(ptr : void) : boolean;
begin
push_trace('E1000.loadE1000');
loadE1000:= false;
if not Loaded then begin
card_type:= ctE1000;
loadE1000:= load(ptr);
end;
pop_trace;
end;
function load82577LM(ptr : void) : boolean;
begin
push_trace('E1000.load82577LM');
load82577LM:= false;
if not Loaded then begin
card_type:= ct82577LM;
load82577LM:= load(ptr);
end;
pop_trace;
end;
function loadI217(ptr : void) : boolean;
begin
push_trace('E1000.loadI217');
loadI217:= false;
if not Loaded then begin
card_type:= ctI217;
loadI217:= load(ptr);
end;
pop_trace;
end;
procedure init();
@ -543,6 +580,7 @@ var
dev : TDeviceIdentifier;
begin
push_trace('E1000.init');
card_type:= ctUnknown;
dev.Bus:= biPCI;
dev.id0:= INTEL_VEND;
@ -556,6 +594,7 @@ begin
drivermanagement.register_driver('I217 Ethernet Driver', @dev, @loadI217);
dev.id4:= LM82577_DEV;
drivermanagement.register_driver('82577LM Ethernet Driver', @dev, @load82577LM);
pop_trace;
end;
function getMACAddress : puint8;
@ -568,6 +607,7 @@ var
old_cur : uint8;
begin
push_trace('E1000.sendPacket');
tx_descs[tx_curr]^.address:= uint32(vtop(uint32(p_data)));
tx_descs[tx_curr]^.length:= p_len;
tx_descs[tx_curr]^.cmd:= CMD_EOP OR CMD_IFCS OR CMD_RS OR CMD_RPS;
@ -578,6 +618,7 @@ begin
while (tx_descs[old_cur]^.status AND $FF) = 0 do begin
end;
sendPacket:= 0;
pop_trace;
end;
end.

View File

@ -31,7 +31,7 @@ type
PPCreateHook = procedure(disk : PStorage_Device; sectors : uint32; start : uint32);
PPDetectHook = procedure(disk : PStorage_Device);
PPHIOHook = procedure(device : PStorage_device; LBA : uint32; sectorCount : uint32; buffer : Puint32);
PPHIOHook_ = procedure(device : PStorage_device; LBA : uint32; sectorCount : uint32; buffer : Puint32);
TFilesystem = record
sName : pchar;
@ -58,7 +58,7 @@ type
maxSectorCount : uint32;
sectorSize : uint32;
writable : boolean;
volumes : array[0..7] of TStorage_Volume
volumes : array[0..7] of TStorage_Volume;
writeCallback : PPHIOHook;
readCallback : PPHIOHook;
end;

View File

@ -88,7 +88,7 @@ var
i : uint32;
begin
//push_trace('driver_management.terminal_command_drivers');
push_trace('driver_management.terminal_command_drivers');
Drv:= Root;
i:= 1;
while Drv <> nil do begin
@ -120,7 +120,7 @@ begin
end;
Drv:= Drv^.Next;
end;
//pop_trace;
pop_trace;
end;
procedure terminal_command_driversex(Params : PParamList);
@ -130,7 +130,7 @@ var
i : uint32;
begin
//push_trace('driver_management.terminal_command_driversex');
push_trace('driver_management.terminal_command_driversex');
Drv:= Root;
i:= 1;
while Drv <> nil do begin
@ -161,7 +161,7 @@ begin
i:= i + 1;
Drv:= Drv^.Next;
end;
//pop_trace;
pop_trace;
end;
procedure terminal_command_devices(Params : PParamList);
@ -171,7 +171,7 @@ var
i : uint32;
begin
//push_trace('driver_management.terminal_command_devices');
push_trace('driver_management.terminal_command_devices');
Dv:= Dev;
i:= 1;
while Dv <> nil do begin
@ -209,7 +209,7 @@ begin
i:= i + 1;
Dv:= Dv^.Next;
end;
//pop_trace;
pop_trace;
end;
{ Main Functions }
@ -222,6 +222,7 @@ var
new_ex: PDevEx;
begin
push_trace('driver_management.copy_identifier');
New_DevID:= PDeviceIdentifier(kalloc(sizeof(TDeviceIdentifier)));
New_DevID^.Bus:= DeviceID^.Bus;
New_DevID^.id0:= DeviceID^.id0;
@ -246,6 +247,7 @@ begin
end;
New_DevID^.ex:= root_ex;
copy_identifier:= New_DevID;
pop_trace;
end;
function identifiers_match(i1, i2 : PDeviceIdentifier) : boolean;
@ -254,6 +256,7 @@ var
b1, b2 : boolean;
begin
push_trace('driver_management.identifiers_match');
identifiers_match:= true;
identifiers_match:= identifiers_match and ((i1^.Bus = i2^.Bus) OR (i1^.Bus = biANY) OR (i2^.Bus = biANY));
identifiers_match:= identifiers_match and ((i1^.id0 = i2^.id0) OR (i1^.id0 = $FFFFFFFF) OR (i2^.id0 = $FFFFFFFF));
@ -267,28 +270,36 @@ begin
b1:= ll1 <> nil;
b2:= ll2 <> nil;
identifiers_match:= identifiers_match and (b1 = b2);
if not (b1 and b2) then exit;
if not (b1 and b2) then begin
identifiers_match:= false;
break;
end;
if b1 = b2 then begin
identifiers_match:= identifiers_match and ((ll1^.idN = ll2^.idN) OR (ll1^.idN = $FFFFFFFF) OR (ll2^.idN = $FFFFFFFF));
end else begin
identifiers_match:= false;
exit;
break;
end;
ll1:= ll1^.ex;
ll2:= ll2^.ex;
end;
pop_trace;
end;
procedure init;
begin
push_trace('driver_management.init');
terminal.registerCommand('DRIVERSEX', @terminal_command_driversex, 'List all available drivers.');
terminal.registerCommand('DRIVERS', @terminal_command_drivers, 'List loaded drivers.');
terminal.registerCommand('DEVICES', @terminal_command_devices, 'List devices.');
pop_trace;
end;
procedure register_driver(Driver_Name : PChar; DeviceID : PDeviceIdentifier; Load_Callback : TDriverLoadCallback);
begin
push_trace('driver_management.register_driver');
register_driver_ex(Driver_Name, DeviceID, Load_Callback, false);
pop_trace;
end;
procedure register_driver_ex(Driver_Name : PChar; DeviceID : PDeviceIdentifier; Load_Callback : TDriverLoadCallback; force_load : boolean);
@ -297,33 +308,34 @@ var
RegList : PDriverRegistration;
begin
//push_trace('driver_management.register_driver_ex');
if DeviceID = nil then exit;
NewReg:= PDriverRegistration(kalloc(sizeof(TDriverRegistration)));
NewReg^.Driver_Name:= stringCopy(Driver_Name);
NewReg^.Identifier:= copy_identifier(DeviceID);
NewReg^.Loaded:= false;
NewReg^.Driver_Load:= Load_Callback;
NewReg^.Next:= nil;
if Root = nil then begin
Root:= NewReg;
end else begin
RegList:= Root;
While RegList^.Next <> nil do begin
RegList:= RegList^.Next;
push_trace('driver_management.register_driver_ex');
if DeviceID <> nil then begin;
NewReg:= PDriverRegistration(kalloc(sizeof(TDriverRegistration)));
NewReg^.Driver_Name:= stringCopy(Driver_Name);
NewReg^.Identifier:= copy_identifier(DeviceID);
NewReg^.Loaded:= false;
NewReg^.Driver_Load:= Load_Callback;
NewReg^.Next:= nil;
if Root = nil then begin
Root:= NewReg;
end else begin
RegList:= Root;
While RegList^.Next <> nil do begin
RegList:= RegList^.Next;
end;
RegList^.Next:= NewReg;
end;
console.output('Driver Management', 'New Driver Registered: ');
console.writestringln(NewReg^.Driver_Name);
if force_load then begin
console.output('Driver Management', 'Driver (');
console.writestring(NewReg^.Driver_Name);
console.writestringln(') forced to load.');
NewReg^.Loaded:= True;
NewReg^.Driver_Load(nil);
end;
RegList^.Next:= NewReg;
end;
console.output('Driver Management', 'New Driver Registered: ');
console.writestringln(NewReg^.Driver_Name);
if force_load then begin
console.output('Driver Management', 'Driver (');
console.writestring(NewReg^.Driver_Name);
console.writestringln(') forced to load.');
NewReg^.Loaded:= True;
NewReg^.Driver_Load(nil);
end;
//pop_trace;
pop_trace;
end;
procedure register_device(Device_Name : PChar; DeviceID : PDeviceIdentifier; ptr : void);
@ -333,7 +345,7 @@ var
dev_list : PDeviceRegistration;
begin
//push_trace('driver_management.register_device');
push_trace('driver_management.register_device');
drv:= Root;
new_dev:= PDeviceRegistration(kalloc(sizeof(TDeviceRegistration)));
new_dev^.Device_Name:= stringCopy(Device_Name);
@ -365,12 +377,12 @@ begin
drv^.Loaded:= true;
new_dev^.Driver_Loaded:= true;
new_dev^.Driver:= drv;
exit;
break;
end;
end;
drv:= drv^.Next;
end;
//pop_trace;
pop_trace;
end;
end.

View File

@ -128,31 +128,42 @@ var
begin
LL_Insert:= nil;
if idx >= LinkedList^.Count then exit;
if idx > LinkedList^.Count then exit;
Base:= LinkedList^.Head;
i:=0;
while (i < idx) and (Base <> nil) do begin
i:= i + 1;
Base:= Base^.Next;
end;
if Base = nil then exit;
Prev:= Base^.Previous;
Next:= Base;
Element:= PLinkedList(kalloc(sizeof(TLinkedList)));
Element^.Data:= kalloc(LinkedList^.ElementSize);
memset(uint32(Element^.Data), 0, LinkedList^.ElementSize);
Element^.Previous:= Prev;
Element^.Next:= Next;
if Prev = nil then begin
if i = 0 then begin
Element:= PLinkedList(kalloc(sizeof(TLinkedList)));
Element^.Data:= kalloc(LinkedList^.ElementSize);
memset(uint32(Element^.Data), 0, LinkedList^.ElementSize);
Element^.Next:= LinkedList^.Head;
Element^.Previous:= nil;
LinkedList^.Head:= Element;
LinkedList^.Count:= LinkedList^.Count + 1;
LL_Insert:= Element^.Data;
end else begin
Prev^.Next:= Element;
if Base = nil then exit;
Prev:= Base^.Previous;
Next:= Base;
Element:= PLinkedList(kalloc(sizeof(TLinkedList)));
Element^.Data:= kalloc(LinkedList^.ElementSize);
memset(uint32(Element^.Data), 0, LinkedList^.ElementSize);
Element^.Previous:= Prev;
Element^.Next:= Next;
if Prev = nil then begin
LinkedList^.Head:= Element;
end else begin
Prev^.Next:= Element;
end;
if Next <> nil then begin
Next^.Previous:= Element;
end;
LinkedList^.Count:= LinkedList^.Count + 1;
LL_Insert:= Element^.Data;
end;
if Next <> nil then begin
Next^.Previous:= Element;
end;
LinkedList^.Count:= LinkedList^.Count + 1;
LL_Insert:= Element^.Data;
end;
function LL_Get(LinkedList : PLinkedListBase; idx : uint32) : void;

View File

@ -14,7 +14,7 @@ interface
const
KERNEL_VIRTUAL_BASE = $C0000000;
KERNEL_PAGE_NUMBER = KERNEL_VIRTUAL_BASE SHR 22;
BSOD_ENABLE = false;
BSOD_ENABLE = true;
type
//internal types

View File

@ -58,6 +58,7 @@ var
i : uint32;
begin
push_trace('util.printmemory');
buf:= puint8(source);
for i:=0 to length do begin
if offset_row and (i = 0) then begin
@ -76,6 +77,7 @@ begin
end;
end;
console.writestringln(' ');
pop_trace;
end;
function hi(b : uint8) : uint8; [public, alias: 'util_hi'];
@ -219,10 +221,12 @@ var
i : uint32;
begin
push_trace('util.memset');
for i:=0 to size-1 do begin
loc:= puint8(location + i);
loc^:= value;
end;
pop_trace;
end;
procedure memcpy(source : uint32; dest : uint32; size : uint32);
@ -231,11 +235,13 @@ var
i : uint32;
begin
push_trace('util.memcpy');
for i:=0 to size-1 do begin
src:= puint8(source + i);
dst:= puint8(dest + i);
dst^:= src^;
end;
pop_trace;
end;
function getWord(i : uint32; hi : boolean) : uint16;
@ -257,6 +263,9 @@ begin
end;
procedure BSOD(fault : pchar; info : pchar);
var
trace : pchar;
begin
if not BSOD_ENABLE then exit;
console.setdefaultattribute(console.combinecolors(white, Red));
@ -298,7 +307,8 @@ begin
console.writestring(' Fault Info: ');
console.writestringln(info);
console.writestring(' Faulting Module: ');
console.writestringln(tracer.get_last_trace);
trace:= tracer.get_last_trace;
if trace <> nil then console.writestringln(tracer.get_last_trace) else console.writestringln('Unknown');
console.writestringln(' ');
halt_and_catch_fire();
end;

View File

@ -100,6 +100,8 @@ begin
multibootinfo:= mbinfo;
multibootmagic:= mbmagic;
tracer.freeze();
{ Console Init }
console.init();
@ -177,6 +179,8 @@ begin
console.writestringln('');
console.writestringln('Press any key to boot in to Asuro Terminal...');
GPF;
keyboard.hook(@temphook);
util.halt_and_dont_catch_fire;

View File

@ -15,7 +15,8 @@ uses
util,
vmemorymanager,
pmemorymanager,
console;
console,
tracer;
const
ALLOC_SPACE = 8; //64-Bit Allocations
@ -56,11 +57,13 @@ var
i : integer;
begin
push_trace('lmemorymanager.new_lmm_page');
i:= KERNEL_PAGE_NUMBER + 4;
while not vmemorymanager.new_page(i) do begin
i:= i + 1;
end;
new_lmm_page:= i SHL 22;
pop_trace;
end;
function new_heap_page(CurrentPage : PHeapPage) : PHeapPage;
@ -68,6 +71,7 @@ var
i : integer;
begin
push_trace('lmemorymanager.new_heap_page');
new_heap_page:= PHeapPage(new_lmm_page);
if CurrentPage <> nil then CurrentPage^.Next_Page:= uint32(new_heap_page);
new_heap_page^.Next_Page:= 0;
@ -79,6 +83,7 @@ begin
Last:= False;
end;
end;
pop_trace;
end;
procedure init;
@ -86,6 +91,7 @@ var
i : uint32;
begin
push_trace('lmemorymanager.init');
console.outputln('LMM','INIT BEGIN.');
Root_Page:= PHeapPage(new_lmm_page);
Search_Page:= Root_Page;
@ -97,6 +103,7 @@ begin
Root_Page^.Entries[i].Last:= False;
end;
console.outputln('LMM','INIT END.');
pop_trace;
end;
function kpalloc(address : uint32) : void;
@ -104,10 +111,12 @@ var
block : uint16;
begin
push_trace('lmemorymanager.kpalloc');
block:= address SHR 22;
force_alloc_block(block, 0);
map_page(block, block);
kpalloc:= void(block SHL 22);
pop_trace;
end;
function kalloc(size : uint32) : void;
@ -118,6 +127,7 @@ var
miss : boolean;
begin
push_trace('lmemorymanager.kalloc');
Heap_Entries:= size div 8;
If sint32(size-(Heap_Entries*8)) > 0 then Heap_Entries:= Heap_Entries + 1;
hp:= Search_Page;
@ -153,6 +163,7 @@ begin
Search_Page:= hp;
end;
end;
pop_trace;
end;
procedure kfree(area : void);
@ -161,6 +172,7 @@ var
entry : uint32;
begin
push_trace('lmemorymanager.kfree');
hp:= PHeapPage((uint32(area) SHR 22) SHL 22);
entry:= (uint32(area) - DATA_OFFSET - uint32(hp)) div 8;
if hp^.Entries[entry].Present then begin
@ -180,6 +192,7 @@ begin
end else begin
GPF;
end;
pop_trace;
end;
end.

View File

@ -14,7 +14,8 @@ interface
uses
util,
console,
multiboot;
multiboot,
tracer;
type
TPhysicalMemoryEntry = packed record
@ -44,6 +45,7 @@ var
i : uint32;
begin
push_trace('pmemorymanager.set_memory_area_present');
FirstBlock:= base SHR 22;
LastBlock:= (base+length) SHR 22;
if (FirstBlock > 1023) then exit;
@ -61,6 +63,7 @@ begin
end;
end;
end;
pop_trace;
end;
procedure walk_memory_map;
@ -71,6 +74,7 @@ var
i : uint16;
begin
push_trace('pmemorymanager.walk_memory_map');
address:= multibootinfo^.mmap_addr + KERNEL_VIRTUAL_BASE;
length:= multibootinfo^.mmap_length;
mmap:= Pmemory_map_t(address);
@ -92,10 +96,12 @@ begin
for i:=0 to 1023 do begin
if PhysicalMemory[i].Present then nPresent:= nPresent + 1;
end;
pop_trace;
end;
procedure force_alloc_block(block : uint16; caller : uint32);
begin
push_trace('pmemorymanager.force_alloc_block');
PhysicalMemory[block].Allocated:= True;
PhysicalMemory[block].MappedTo:= caller;
// console.writestring('PMM: 4MiB Block Force Allocated @ ');
@ -105,10 +111,12 @@ begin
// console.writestring(' - ');
// console.writehex(((block+1) SHL 22));
// console.writestringln(']');
pop_trace;
end;
procedure init;
begin
push_trace('pmemorymanager.init');
console.outputln('PMM','INIT BEGIN.');
walk_memory_map;
force_alloc_block(0, 0);
@ -119,10 +127,12 @@ begin
console.writeword(nPresent);
console.writestringln('/1024 Block Available for Allocation.');
console.outputln('PMM','INIT END.');
pop_trace;
end;
function alloc_block(block : uint16; caller : uint32) : boolean;
begin
push_trace('pmemorymanager.alloc_block');
alloc_block:= false;
if (PhysicalMemory[block].Present) then begin
if PhysicalMemory[block].Allocated then begin
@ -143,6 +153,7 @@ begin
GPF;
alloc_block:= false;
end;
pop_trace;
end;
function new_block(caller : uint32) : uint16;
@ -150,6 +161,7 @@ var
i : uint16;
begin
push_trace('pmemorymanager.new_block');
new_block:= 0;
for i:=2 to 1023 do begin
if PhysicalMemory[i].Present then begin
@ -161,10 +173,12 @@ begin
end;
end;
end;
pop_trace;
end;
procedure free_block(block : uint16; caller : uint32);
begin
push_trace('pmemorymanager.free_block');
if block > 1023 then begin
GPF;
exit;
@ -182,6 +196,7 @@ begin
exit;
end;
PhysicalMemory[block].Allocated:= false;
pop_trace;
end;
end.

View File

@ -60,6 +60,7 @@ var
i : uint32;
begin
push_trace('terminal.paramCount');
current:= params;
i:= 0;
while current^.param <> nil do begin
@ -67,6 +68,7 @@ begin
current:= current^.next;
end;
paramCount:= i-1;
pop_trace;
end;
function getParams(buf : TCommandBuffer) : PParamList;
@ -78,6 +80,7 @@ var
current : PParamList;
begin
push_trace('terminal.getParams');
root:= PParamList(kalloc(sizeof(TParamList)));
current:= root;
current^.next:= nil;
@ -103,6 +106,7 @@ begin
inc(finish);
end;
getParams:= root;
pop_trace;
end;
function getParam(index : uint32; params : PParamList) : pchar;
@ -112,12 +116,14 @@ var
i : uint32;
begin
push_trace('terminal.getParam');
result:= nil;
search:= params;
for i:=0 to index do begin
search:= search^.next;
end;
result:= search^.param;
pop_trace;
end;
procedure freeParams(params : PParamList);
@ -126,6 +132,7 @@ var
next : PParamList;
begin
push_trace('terminal.freeParams');
p:= params;
next:= p^.next;
while p^.next <> nil do begin
@ -134,14 +141,17 @@ begin
p:= next;
next:= p^.next;
end;
pop_trace;
end;
procedure testParams(params : PParamList);
begin
push_trace('terminal.testParams');
while params^.Param <> nil do begin
writestringln(params^.Param);
params:= params^.next;
end;
pop_trace;
end;
procedure echo(params : PParamList);
@ -149,6 +159,7 @@ var
current : PParamList;
begin
push_trace('terminal.echo');
current:= params^.next;
while current^.param <> nil do begin
console.writestring(current^.param);
@ -156,22 +167,28 @@ begin
current:= current^.next;
end;
console.writestringln('');
pop_trace;
end;
procedure clear(params : PParamList);
begin
push_trace('terminal.clear');
console.clear();
pop_trace;
end;
procedure version(params : PParamList);
begin
push_trace('terminal.version');
console.writestringln('Asuro v1.0');
pop_trace;
end;
procedure help(params : PParamList);
var
i : uint32;
begin
push_trace('terminal.help');
console.writestringln('Registered Commands: ');
for i:=0 to 65534 do begin
if Commands[i].Registered then begin
@ -181,15 +198,18 @@ begin
console.writestringln(Commands[i].description);
end;
end;
pop_trace;
end;
procedure test(params : PParamList);
begin
push_trace('terminal.test');
if paramCount(params) > 0 then begin
console.writeintln(stringToInt(getParam(0, params)));
end else begin
console.writestringln('Invalid number of params');
end;
pop_trace;
end;
procedure registerCommand(command : pchar; method : TCommandMethod; description : pchar);
@ -197,12 +217,14 @@ var
index : uint32;
begin
push_trace('terminal.registerCommand');
index:= 0;
while Commands[index].registered = true do inc(index);
Commands[index].registered:= true;
Commands[index].Command:= command;
Commands[index].method:= method;
Commands[index].description:= description;
pop_trace;
end;
procedure process_command;
@ -214,6 +236,8 @@ var
uppera, upperb : pchar;
begin
push_trace('terminal.process_command');
{ Start a new line. }
console.writecharln(' ');
@ -249,10 +273,13 @@ begin
console.writestring('Asuro#> ');
bIndex:= 0;
memset(uint32(@buffer[0]), 0, 1024);
pop_trace;
end;
procedure key_event(info : TKeyInfo);
begin
push_trace('terminal.key_event');
if (info.key_code >= 32) and (info.key_code <= 126) then begin
if bIndex < 1024 then begin
buffer[bIndex]:= info.key_code;
@ -270,10 +297,12 @@ begin
if info.key_code = 13 then begin //return
process_command;
end;
pop_trace;
end;
procedure init;
begin
push_trace('terminal.init');
console.writestringln('TERMINAL: INIT BEGIN.');
memset(uint32(@Commands[0]), 0, 65535*sizeof(TCommand));
memset(uint32(@buffer[0]), 0, 1024);
@ -284,13 +313,16 @@ begin
registerCommand('TESTPARAMS', @testParams, 'Tests param parsing.');
registerCommand('TEST', @test, 'Command for testing.');
console.writestringln('TERMINAL: INIT END.');
pop_trace;
end;
procedure run;
begin
push_trace('terminal.run');
keyboard.hook(@key_event);
console.clear();
console.writestring('Asuro#> ');
pop_trace;
end;
end.

View File

@ -6,6 +6,9 @@ procedure init;
procedure push_trace(t_name : pchar);
procedure pop_trace;
function get_last_trace : pchar;
procedure freeze;
function get_trace_count : uint32;
function get_trace_N(idx : uint32) : pchar;
implementation
@ -13,11 +16,11 @@ uses
console, util, lists, strings;
var
t_ready : Boolean = false;
Locked : Boolean = false;
t_ready : Boolean;
Locked : Boolean;
TraceStack : PLinkedListBase;
procedure lock;
procedure freeze;
begin
t_ready:= false;
end;
@ -27,38 +30,51 @@ var
mem : void;
begin
if not Initialized then exit;
console.writestringln('WTF?!?!?');
if not Locked then begin
Locked:= true;
mem:= LL_Insert(TraceStack, 0);
memset(uint32(mem), 0, StringSize(t_name) + 5);
memcpy(uint32(t_name), uint32(mem), StringSize(t_name) + 1);
Locked:= false;
if t_ready then begin
if not Locked then begin
Locked:= true;
mem:= LL_Insert(TraceStack, 0);
memset(uint32(mem), 0, StringSize(t_name) + 5);
memcpy(uint32(t_name), uint32(mem), StringSize(t_name) + 1);
Locked:= false;
end;
end;
end;
procedure pop_trace;
begin
if not Initialized then exit;
if not Locked then begin
Locked:= true;
LL_Delete(TraceStack, 0);
Locked:= false;
if t_ready then begin
if not Locked then begin
Locked:= true;
LL_Delete(TraceStack, 0);
Locked:= false;
end;
end;
end;
function get_last_trace : pchar;
begin
if not Initialized then exit;
get_last_trace:= pchar(LL_Get(TraceStack, 0));
get_last_trace:= nil;
if t_ready then begin
get_last_trace:= pchar(LL_Get(TraceStack, 0));
end;
end;
procedure init;
begin
TraceStack:= LL_New(255);
t_ready:= true;
push_trace('kmain');
Initialized:= true;
end;
function get_trace_count : uint32;
begin
get_trace_count:= LL_Size(TraceStack);
end;
function get_trace_N(idx : uint32) : pchar;
begin
get_trace_N:= pchar(LL_Get(TraceStack, idx));
end;
end.

View File

@ -58,7 +58,9 @@ uses
function new_page_directory : uint32;
begin
push_trace('vmemorymanager.new_page_directory');
new_page_directory:= uint32(kalloc(sizeof(TPageDirectory)));
pop_trace;
end;
function new_kernel_mapped_page_directory : uint32;
@ -67,11 +69,13 @@ var
i : uint32;
begin
push_trace('vmemorymanager.new_kernel_mapped_page_directory');
PD:= PPageDirectory(new_page_directory);
for i:=KERNEL_PAGE_NUMBER to 1023 do begin
PD^[i]:= KERNEL_PAGE_DIRECTORY^[i];
end;
new_kernel_mapped_page_directory:= uint32(PD);
pop_trace;
end;
function load_current_page_directory : PPageDirectory;
@ -79,6 +83,7 @@ var
Directory : uint32;
begin
push_trace('vmemorymanager.load_current_page_directory');
asm
MOV EAX, CR3
MOV Directory, EAX
@ -93,6 +98,7 @@ var
i : uint32;
begin
push_trace('vmemorymanager.init');
console.outputln('VMM','INIT BEGIN.');
PageDirectory:= load_current_page_directory;
KERNEL_PAGE_DIRECTORY:= PageDirectory;
@ -101,6 +107,7 @@ begin
map_page(KERNEL_PAGE_NUMBER + 2, 2);
map_page(KERNEL_PAGE_NUMBER + 3, 3);
console.outputln('VMM','INIT END.');
pop_trace;
end;
function map_page_ex(page_number : uint16; block : uint16; PD : PPageDirectory) : boolean;
@ -109,6 +116,7 @@ var
page : uint16;
begin
push_trace('vmemorymanager.map_page_ex');
map_page_ex:= false;
PD^[page_number].Present:= true;
addr:= block;
@ -134,6 +142,7 @@ begin
// console.writestringln(']');
map_page_ex:= true;
pop_trace;
end;
function map_page(page_number : uint16; block : uint16) : boolean;
@ -143,6 +152,7 @@ var
rldpd : uint32;
begin
push_trace('vmemorymanager.map_page');
map_page:= false;
PageDirectory^[page_number].Present:= true;
addr:= block;
@ -155,6 +165,7 @@ begin
mov eax, rldpd
mov CR3, eax
end;
pop_trace;
end;
function vtop(address : uint32) : uint32;
@ -164,10 +175,12 @@ var
loadd : uint32;
begin
push_trace('vmemorymanager.vtop');
idx:= address SHR 22;
paddress:= uint32(KERNEL_PAGE_DIRECTORY^[idx].address) SHL 12;
loadd:= address AND $FFFFFF;
vtop:= paddress + loadd;
pop_trace;
end;
function new_page(page_number : uint16) : boolean;
@ -175,6 +188,7 @@ var
block : uint16;
begin
push_trace('vmemorymanager.new_page');
new_page:= false;
if PageDirectory^[page_number].Present then exit;
if PageDirectory^[page_number].Reserved then exit;
@ -185,6 +199,7 @@ begin
end else begin
new_page:= map_page(page_number, block);
end;
pop_trace;
end;
function new_page_at_address(address : uint32) : boolean;
@ -192,8 +207,10 @@ var
page_number : uint16;
begin
push_trace('vmemorymanager.new_page_at_address');
page_number:= address SHR 22;
new_page_at_address:= new_page(page_number);
pop_trace;
end;
procedure free_page(page_number : uint16);
@ -201,6 +218,7 @@ var
block : uint16;
begin
push_trace('vmemorymanager.free_page');
if PageDirectory^[page_number].Present then begin
block:= PageDirectory^[page_number].Address;
asm
@ -210,6 +228,7 @@ begin
end else begin
GPF;
end;
pop_trace;
end;
procedure free_page_at_address(address : uint32);
@ -217,8 +236,10 @@ var
page_number : uint16;
begin
push_trace('vmemorymanager.free_page_at_address');
page_number:= address SHR 22;
free_page(page_number);
pop_trace;
end;
end.