getting ready

This commit is contained in:
Aaron committed 2026-03-07 18:57:38 +00:00
1 parent 4e3acd6af7
commit 789fb7971a
25 files changed
+3142 -1093

No files matched your search

File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -20,7 +20,7 @@
unit AHCITypes;
interface
uses
console,
syslog,
drivermanagement,
drivertypes,
idetypes,
+2 -2
View File
@@ -22,7 +22,7 @@ unit asfs;
interface
uses
console,
syslog,
lists,
lmemorymanager,
rtc,
@@ -30,7 +30,7 @@ uses
storagemanagement,
storagemanager,
strings,
terminal,
stdio,
tracer,
util;
File diff suppressed because it is too large. Load diff
+58 -10
View File
@@ -27,8 +27,8 @@ uses
strings,
filesystemmanager,
lists,
console,
terminal,
syslog,
stdio,
storagemanager,
storagetypes,
lmemorymanager,
@@ -148,7 +148,6 @@ begin
kfree(puint32(data));
read_file(volume, '/logs/log.txt', PuInt32(data), status);
writestringlnWND(pchar(data), getterminalhwnd());
end;
procedure write_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32);
@@ -271,14 +270,12 @@ begin
compString := stringSub(fileEntrys[i].name, 0, stringSize(directory));
afterString := stringSub(fileEntrys[i].name, stringSize(directory), stringSize(fileEntrys[i].name)-1);
writestringlnWND(afterString, getterminalhwnd());
push_trace('read_directory_2');
if stringEquals(compString, directory) and
(not stringContains(afterString, slash)) then begin
writestringlnWND(fileEntrys[i].name, getterminalhwnd());
STRLL_Add(directories, afterString);
end;
end;
@@ -542,6 +539,56 @@ begin
status^ := 0;
end;
{ Count free sectors on a FlatFS volume by scanning file entries. }
function countFreeFlatFSSectors(volume : PStorage_Volume) : uint32;
var
buffer : puint32;
diskInfo : PDisk_Info;
sectorCount : uint32;
fileCount : uint32;
tableSectors : uint32;
fileEntries : PFile_Entry;
usedSectors : uint32;
overhead : uint32;
i : uint32;
begin
countFreeFlatFSSectors := 0;
buffer := puint32(kalloc(512));
memset(uint32(buffer), 0, 512);
storagemanager.storage_read(volume^.device, volume^.sectorStart, 1, buffer);
diskInfo := PDisk_Info(buffer);
sectorCount := diskInfo^.sectorCount;
fileCount := diskInfo^.fileCount;
kfree(buffer);
if sectorCount = 0 then exit;
tableSectors := (fileCount * sizeof(TFile_Entry)) div 512;
overhead := 2 + tableSectors; { header + boundary + file table }
usedSectors := 0;
if fileCount > 0 then begin
fileEntries := PFile_Entry(kalloc(sizeof(TFile_Entry) * fileCount + 512));
memset(uint32(fileEntries), 0, sizeof(TFile_Entry) * fileCount);
storagemanager.storage_read(volume^.device, volume^.sectorStart + 1,
tableSectors, puint32(fileEntries));
for i := 0 to fileCount - 1 do begin
if fileEntries[i].attribues <> 0 then
usedSectors := usedSectors + fileEntries[i].size;
end;
kfree(puint32(fileEntries));
end;
if sectorCount > (overhead + usedSectors) then
countFreeFlatFSSectors := sectorCount - overhead - usedSectors
else
countFreeFlatFSSectors := 0;
end;
procedure detect_volumes(disk : PStorage_Device);
var
buffer : puint32;
@@ -553,7 +600,7 @@ begin
memset(uint32(buffer), 0, 512);
if (disk^.readCallback = nil) and (disk^.readCallbackAsync = nil) then begin
console.writestringln('FlatFS: detect_volumes: device has no read callback.');
syslog.writestringln('FlatFS: detect_volumes: device has no read callback.');
kfree(buffer);
exit;
end;
@@ -561,15 +608,15 @@ begin
storagemanager.storage_read(disk, 2, 1, buffer);
if (PDisk_Info(buffer)^.signature = $0B00B1E5) then begin
console.writestringln('FlatFS: volume found!');
syslog.writestringln('FlatFS: volume found!');
volume := PStorage_volume(kalloc(sizeof(TStorage_Volume)));
memset(uint32(volume), 0, sizeof(TStorage_Volume));
volume^.device := disk;
volume^.sectorStart := 2;
volume^.sectorSize := 512;
volume^.sectorCount := PDisk_Info(buffer)^.sectorCount;
volume^.freeSectors := 0; { TODO: implement free sector count }
volume^.filesystem := @filesystem;
volume^.freeSectors := countFreeFlatFSSectors(volume);
volume^.isBootDrive := false;
volumemanager.register_volume(disk, volume);
@@ -710,7 +757,6 @@ begin
end;
function identify_volume(volume : PStorage_Volume) : boolean;
var
buffer : puint32;
@@ -724,8 +770,10 @@ begin
storagemanager.storage_read(volume^.device, volume^.sectorStart, 1, buffer);
if (PDisk_Info(buffer)^.signature = $0B00B1E5) then
if (PDisk_Info(buffer)^.signature = $0B00B1E5) then begin
identify_volume := true;
volume^.freeSectors := countFreeFlatFSSectors(volume);
end;
kfree(buffer);
end;
+1 -1
View File
@@ -12,7 +12,7 @@ unit iso9660;
interface
uses
console,
syslog,
filesystemmanager,
lists,
lmemorymanager,
+2 -2
View File
@@ -13,13 +13,13 @@ unit partitiontable;
interface
uses
console,
syslog,
lists,
lmemorymanager,
rtc,
storagemanagement,
strings,
terminal,
stdio,
tracer,
util;
+19 -6
View File
@@ -16,11 +16,13 @@ uses
lmemorymanager,
MBR,
storagetypes,
syslog,
tracer,
util;
var
storageDevices : PDList;
nextDeviceId : uint32;
procedure init();
procedure register_device(device : PStorage_Device);
@@ -40,17 +42,32 @@ procedure storage_write(device : PStorage_Device; addr : uint32; sectors : uint3
implementation
uses
volumemanager;
procedure init();
begin
push_trace('StorageManager.init');
storageDevices := DL_New(sizeof(TStorage_Device));
nextDeviceId := 0;
end;
procedure register_device(device : PStorage_Device);
var
storedDev : PStorage_Device;
begin
push_trace('StorageManager.register_device');
device^.id := nextDeviceId;
nextDeviceId := nextDeviceId + 1;
DL_Add(storageDevices);
DL_Set(storageDevices, DL_Size(storageDevices) - 1, puint32(device));
{ Get pointer to the DList copy so volumes reference the canonical device }
storedDev := PStorage_Device(DL_Get(storageDevices, DL_Size(storageDevices) - 1));
{ Discover partitions and register volumes automatically }
if storedDev^.maxSectorCount > 0 then
volumemanager.discover_volumes(storedDev);
end;
function get_device_list() : PDList;
@@ -115,10 +132,7 @@ begin
device^.readCallbackAsync(device, addr, sectors, buffer, @storage_sync_done, @done);
asm sti end;
while done = 0 do begin
asm hlt end; { sleep until next interrupt }
{ Fallback: if the hardware IRQ was not delivered through the PIC,
poll the driver inline so the completion fires. }
if (done = 0) and (device^.pollCallback <> nil) then
if device^.pollCallback <> nil then
device^.pollCallback();
end;
end else if device^.readCallback <> nil then
@@ -134,8 +148,7 @@ begin
device^.writeCallbackAsync(device, addr, sectors, buffer, @storage_sync_done, @done);
asm sti end;
while done = 0 do begin
asm hlt end; { sleep until next interrupt }
if (done = 0) and (device^.pollCallback <> nil) then
if device^.pollCallback <> nil then
device^.pollCallback();
end;
end else if device^.writeCallback <> nil then
File diff suppressed because it is too large. Load diff
+108 -106
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -13,7 +13,7 @@ unit volumemanager;
interface
uses
console,
syslog,
filesystemmanager,
lists,
lmemorymanager,
@@ -21,7 +21,7 @@ uses
storagemanager,
storagetypes,
strings,
terminal,
stdio,
tracer,
util;
+9 -9
View File
@@ -17,7 +17,7 @@ interface
uses
util,
lmemorymanager,
console;
syslog;
{ Initialise IOAPIC/LAPIC support — maps MMIO regions, ensures LAPIC
is enabled. Safe to call even if the hardware doesn't have an IOAPIC
@@ -88,11 +88,11 @@ begin
{ Probe: read IOAPIC version register — should return non-zero/non-$FF }
ver := ioapic_read(IOAPIC_VER);
if (ver = 0) or (ver = $FFFFFFFF) then begin
console.outputln('IOAPIC', 'Not detected — PCI interrupts rely on 8259 PIC.');
syslog.logln('IOAPIC', 'Not detected — PCI interrupts rely on 8259 PIC.');
exit;
end;
console.outputln('IOAPIC', 'Detected.');
syslog.logln('IOAPIC', 'Detected.');
{ Ensure the Local APIC is software-enabled (bit 8 of SVR).
We set the spurious vector to $FF which is unused. }
@@ -101,7 +101,7 @@ begin
svr := svr or $100; { Enable APIC }
svr := (svr and $FFFFFF00) or $FF; { Spurious vector = 0xFF }
puint32(LAPIC_PHYS + LAPIC_SVR)^ := svr;
console.outputln('IOAPIC', 'LAPIC software-enabled.');
syslog.logln('IOAPIC', 'LAPIC software-enabled.');
end;
ioapic_present := true;
@@ -128,11 +128,11 @@ begin
ioapic_write(IOAPIC_REDTBL + uint32(irq) * 2, lo);
ioapic_write(IOAPIC_REDTBL + uint32(irq) * 2 + 1, 0);
console.output('IOAPIC', 'Routed IRQ ');
console.writeint(irq);
console.writestring(' -> vector ');
console.writeint(vector);
console.writestringln('');
syslog.log('IOAPIC', 'Routed IRQ ');
syslog.writeint(irq);
syslog.writestring(' -> vector ');
syslog.writeint(vector);
syslog.writestringln('');
end;
procedure lapic_eoi();
+1 -1
View File
@@ -35,7 +35,7 @@ procedure dispatchHooks(INT_N : uint8);
implementation
uses
console, ioapic;
syslog, ioapic;
var
Hooks : TISRHookArray;
+86 -51
View File
File diff suppressed because it is too large. Load diff
+3 -3
View File
@@ -30,10 +30,10 @@ unit pmemorymanager;
interface
uses
util,
syslog,
multiboot,
tracer;
syslog,
tracer,
util;
{ Public interface — signatures unchanged from the original unit }
procedure init;
+9 -9
View File
@@ -18,13 +18,13 @@ procedure init();
implementation
uses
console,
syslog,
lists,
lmemorymanager,
storagemanager,
storagetypes,
strings,
terminal,
stdio,
tracer,
util,
volumemanager;
@@ -33,7 +33,7 @@ uses
function wnd : uint32;
begin
wnd := getTerminalHWND;
wnd := 0;
end;
function str2int(s : pchar) : uint32;
@@ -57,22 +57,22 @@ end;
procedure print(s : pchar);
begin
console.writestringWND(s, wnd);
syslog.writestring(s);
end;
procedure println(s : pchar);
begin
console.writestringlnWND(s, wnd);
syslog.writestringln(s);
end;
procedure printint(v : uint32);
begin
console.writeintWND(v, wnd);
syslog.writeint(v);
end;
procedure printhex(v : uint32);
begin
console.writehexWND(v, wnd);
syslog.writehex(v);
end;
procedure printsize(bytes : uint32);
@@ -270,7 +270,7 @@ end;
{ ---------- Main dispatcher ---------- }
procedure command_disk(params : PParamList);
procedure command_disk(params : PParamList; stdin_buf, stdout_buf, stderr_buf: POutBuf);
var
subcmd : pchar;
begin
@@ -306,7 +306,7 @@ end;
procedure init();
begin
terminal.registerCommand('DISK', @command_disk, 'Storage device information.');
stdio.registerCommand('DISK', @command_disk, 'Storage device information.');
end;
end.
File diff suppressed because it is too large. Load diff
+64 -64
View File
File diff suppressed because it is too large. Load diff
+15 -15
View File
@@ -12,11 +12,11 @@ unit inio;
interface
uses
console,
syslog,
lmemorymanager,
storagetypes,
strings,
terminal,
stdio,
tracer,
util,
vfs;
@@ -25,7 +25,7 @@ procedure init();
implementation
procedure Run(Params : PParamList);
procedure Run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf: POutBuf);
var
filePath : pchar;
absPath : pchar;
@@ -45,7 +45,7 @@ begin
pCount := paramCount(Params);
if pCount < 2 then begin
console.writestringlnWND('Usage: inio <file> < | inio <file> > text', getTerminalHWND());
syslog.writestringln('Usage: inio <file> < | inio <file> > text');
exit;
end;
@@ -53,11 +53,11 @@ begin
op := getParam(1, Params);
if filePath = nil then begin
console.writestringlnWND('Error: no file specified.', getTerminalHWND());
syslog.writestringln('Error: no file specified.');
exit;
end;
if op = nil then begin
console.writestringlnWND('Error: no operation specified.', getTerminalHWND());
syslog.writestringln('Error: no operation specified.');
exit;
end;
@@ -67,7 +67,7 @@ begin
if op[0] = '<' then begin
fHandle := vfs.OpenFile(absPath, omReadOnly, wmRewrite, false, @fError);
if (fHandle = 0) or (fError <> eNone) then begin
console.writestringlnWND('Error: cannot open file for reading.', getTerminalHWND());
syslog.writestringln('Error: cannot open file for reading.');
kfree(void(absPath));
exit;
end;
@@ -78,10 +78,10 @@ begin
if bytesRead > 0 then begin
buf[bytesRead] := char(0);
console.writestringWND(buf, getTerminalHWND());
console.writestringlnWND(' ', getTerminalHWND());
syslog.writestring(buf);
syslog.writestringln(' ');
end else begin
console.writestringlnWND('(0 bytes read)', getTerminalHWND());
syslog.writestringln('(0 bytes read)');
end;
kfree(puint32(buf));
end
@@ -89,7 +89,7 @@ begin
{ ---- WRITE ---- }
else if op[0] = '>' then begin
if pCount < 3 then begin
console.writestringlnWND('Error: no content to write.', getTerminalHWND());
syslog.writestringln('Error: no content to write.');
kfree(void(absPath));
exit;
end;
@@ -119,7 +119,7 @@ begin
end;
if (fHandle = 0) or (fError <> eNone) then begin
console.writestringlnWND('Error: cannot open file for writing.', getTerminalHWND());
syslog.writestringln('Error: cannot open file for writing.');
kfree(void(content));
kfree(void(absPath));
exit;
@@ -127,10 +127,10 @@ begin
vfs.WriteFile(fHandle, 0, puint8(content), contentLen);
vfs.CloseFile(fHandle);
console.writestringlnWND('Written.', getTerminalHWND());
syslog.writestringln('Written.');
kfree(void(content));
end else begin
console.writestringlnWND('Error: operation must be < or >.', getTerminalHWND());
syslog.writestringln('Error: operation must be < or >.');
end;
kfree(void(absPath));
@@ -139,7 +139,7 @@ end;
procedure init();
begin
tracer.push_trace('inio.init');
terminal.registerCommand('INIO', @Run, 'Inline IO: inio <file> < | inio <file> > text');
stdio.registerCommand('INIO', @Run, 'Inline IO: inio <file> < | inio <file> > text');
end;
end.
+9 -9
View File
@@ -21,15 +21,15 @@ procedure init();
implementation
uses
console,
filesystemmanager,
lists,
lmemorymanager,
MBR,
stdio,
storagemanager,
storagetypes,
strings,
terminal,
syslog,
tracer,
volumemanager;
@@ -37,7 +37,7 @@ uses
function wnd : uint32;
begin
wnd := getTerminalHWND;
wnd := 0;
end;
function str2int(s : pchar) : uint32;
@@ -61,22 +61,22 @@ end;
procedure print(s : pchar);
begin
console.writestringWND(s, wnd);
syslog.writestring(s);
end;
procedure println(s : pchar);
begin
console.writestringlnWND(s, wnd);
syslog.writestringln(s);
end;
procedure printint(v : uint32);
begin
console.writeintWND(v, wnd);
syslog.writeint(v);
end;
procedure printhex(v : uint32);
begin
console.writehexWND(v, wnd);
syslog.writehex(v);
end;
procedure printsize(bytes : uint32);
@@ -540,7 +540,7 @@ end;
{ ---------- Main dispatcher ---------- }
procedure command_part(params : PParamList);
procedure command_part(params : PParamList; stdin_buf, stdout_buf, stderr_buf: POutBuf);
var
subcmd : pchar;
begin
@@ -581,7 +581,7 @@ end;
procedure init();
begin
terminal.registerCommand('PART', @command_part, 'Partition management.');
stdio.registerCommand('PART', @command_part, 'Partition management.');
end;
end.
Loaded 20 of 25 files, more files were not shown because too many files have changed in this diff. Show more