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

This commit is contained in:
kieron
2018-04-10 14:35:05 +00:00
parent 95f581f7bd
commit 9976400832
14 changed files with 227 additions and 3 deletions

View File

@ -36,8 +36,9 @@ uses
testdriver,
E1000,
IDE,
storagemanagement;
//ipv4;
storagemanagement,
ipv4,
lists;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
@ -85,6 +86,11 @@ var
temp : uint32;
atmp : puint32;
test : puint8;
LList : PLinkedListBase;
Elem : Void;
Str : PChar;
begin
multibootinfo:= mbinfo;
@ -141,7 +147,7 @@ begin
mouse.init();
testdriver.init();
E1000.init();
IDE.init();
//IDE.init();
//Nothing beyond here
USB.init();
@ -157,6 +163,8 @@ begin
console.writestringln('');
console.writestringln('Press any key to boot in to Asuro Terminal...');
LL_TEST();
keyboard.hook(@temphook);
util.halt_and_dont_catch_fire;

216
src/lists.pas Normal file
View File

@ -0,0 +1,216 @@
unit lists;
interface
uses
console,
lmemorymanager;
type
{ Managed Linked List }
PLinkedList = ^TLinkedList;
TLinkedList = record
Previous : PLinkedList;
Data : void;
Next : PLinkedList;
end;
PLinkedListBase = ^TLinkedListBase;
TLinkedListBase = record
Count : uint32;
Head : PLinkedList;
ElementSize : uint32;
end;
{ Managed Linked List }
function LL_New(ElementSize : uint32) : PLinkedListBase;
function LL_Add(LinkedList : PLinkedListBase) : Void;
function LL_Delete(LinkedList : PLinkedListBase; idx : uint32) : boolean;
function LL_Size(LinkedList : PLinkedListBase) : uint32;
function LL_Insert(LinkedList : PLinkedListBase; idx : uint32) : Void;
function LL_Get(LinkedList : PLinkedListBase; idx : uint32) : Void;
procedure LL_TEST();
implementation
{ Managed Linked List }
function LL_New(ElementSize : uint32) : PLinkedListBase;
begin
LL_New:= PLinkedListBase(kalloc(sizeof(TLinkedListBase)));
LL_New^.ElementSize:= ElementSize;
LL_New^.Count:= 0;
LL_New^.Head:= nil;
end;
function LL_Add(LinkedList : PLinkedListBase) : Void;
var
Element : PLinkedList;
Base : PLinkedList;
Count : uint32;
begin
if LinkedList^.Head = nil then begin
Element:= PLinkedList(kalloc(sizeof(TLinkedList)));
Element^.Previous:= nil;
Element^.Next:= nil;
Element^.Data:= kalloc(LinkedList^.ElementSize);
LinkedList^.Head:= Element;
LinkedList^.Count:= LinkedList^.Count + 1;
LL_Add:= Element^.Data;
end else begin
Base:= LinkedList^.Head;
Count:= 1;
While Base^.Next <> nil do begin
Base:= Base^.Next;
Count:= Count + 1;
end;
Element:= PLinkedList(kalloc(sizeof(TLinkedList)));
Base^.Next:= Element;
Element^.Previous:= Base;
Element^.Next:= nil;
Element^.Data:= kalloc(LinkedList^.ElementSize);
LinkedList^.Count:= LinkedList^.Count + 1;
LL_Add:= Element^.Data;
end;
end;
function LL_Delete(LinkedList : PLinkedListBase; idx : uint32) : boolean;
var
Prev, Next : PLinkedList;
Base : PLinkedList;
i : uint32;
begin
Base:= LinkedList^.Head;
i:= 0;
while (i < idx) and (Base <> nil) do begin
i:= i + 1;
Base:= Base^.Next;
end;
if Base = nil then begin
LL_Delete:= false;
exit;
end;
Prev:= Base^.Previous;
Next:= Base^.Next;
if Prev = nil then begin
LinkedList^.Head:= Next;
end else begin
Prev^.Next:= Next;
end;
if Next <> nil then begin
Next^.Previous:= Prev;
end;
LinkedList^.Count:= LinkedList^.Count - 1;
kfree(void(Base^.Data));
kfree(void(Base));
LL_Delete:= True;
end;
function LL_Size(LinkedList : PLinkedListBase) : uint32;
begin
LL_Size:= LinkedList^.Count;
end;
function LL_Insert(LinkedList : PLinkedListBase; idx : uint32) : void;
var
i : uint32;
Base : PLinkedList;
Prev, Next : PLinkedList;
Element : PLinkedList;
begin
LL_Insert:= nil;
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);
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;
function LL_Get(LinkedList : PLinkedListBase; idx : uint32) : void;
var
i : uint32;
Base : PLinkedList;
begin
LL_Get:= nil;
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;
LL_Get:= Base^.Data;
end;
procedure LL_Test();
var
i : uint32;
LList : PLinkedListBase;
Elem : Void;
Str : PChar;
begin
console.writestringln('Add 3 Elements: ');
LList:= LL_New(10);
Elem:= LL_Add(LList);
Str:= PChar(Elem);
Str[0]:= 'H';
Str[1]:= 'E';
Str[2]:= 'L';
Str[3]:= 'L';
Str[4]:= 'O';
Str[5]:= Char(0);
Elem:= LL_Add(LList);
Str:= PChar(Elem);
Str[0]:= 'W';
Str[1]:= 'O';
Str[2]:= 'R';
Str[3]:= 'L';
Str[4]:= 'D';
Str[5]:= Char(0);
Elem:= LL_Add(LList);
Str:= PChar(Elem);
Str[0]:= 'T';
Str[1]:= 'E';
Str[2]:= 'S';
Str[3]:= 'T';
Str[4]:= Char(0);
for i:=0 to LL_Size(LList)-1 do begin
console.writestringln(PChar(LL_Get(LList, i)));
end;
console.writestringln(' ');
console.writestringln('Remove Element 1:');
LL_Delete(LList, 1);
for i:=0 to LL_Size(LList)-1 do begin
console.writestringln(PChar(LL_Get(LList, i)));
end;
end;
end.