git-svn-id: https://spexeah.com:8443/svn/Asuro@484 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
1 parent
3bed07c80a
commit
c8b3b14893
43 files changed
+340
-108
No files matched your search
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
+64
-23
File diff suppressed because it is too large.
Load diff
@@ -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;
|
||||
|
||||
+48
-36
File diff suppressed because it is too large.
Load diff
+27
-16
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
+12
-2
@@ -57,7 +57,8 @@ var
|
||||
buf : puint8;
|
||||
i : uint32;
|
||||
|
||||
begin
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+15
-2
@@ -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;
|
||||
@@ -78,7 +82,8 @@ begin
|
||||
Root:= False;
|
||||
Last:= False;
|
||||
end;
|
||||
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.
|
||||
+16
-1
@@ -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.
|
||||
File diff suppressed because it is too large.
Load diff
+35
-19
@@ -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.
|
||||
@@ -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.
|
||||
Reference in new issue
Block a user