Namespace Restructure #54

Merged
admin merged 3 commits from feature/refactor into develop 2026-03-08 12:47:44 +00:00
200 changed files with 6272 additions and 5527 deletions
+2 -2
View File
@@ -22,8 +22,8 @@ steps:
commands:
- git fetch --tags
- find . -type f -print0 | xargs -0 dos2unix
- chmod +x /drone/src/*.sh
- /drone/src/compile.sh
- chmod +x /drone/src/toolchain/*.sh
- /drone/src/toolchain/compile.sh
- name: upload-iso-artifact
image: alpine/git
+1
View File
@@ -18,3 +18,4 @@ lessons_learnt.md
*.log
/doc/*.md
wasuro
src/core/core.version.pas
+1 -2
View File
@@ -14,10 +14,9 @@ RUN curl -sL https://sourceforge.net/projects/freepascal/files/Linux/$FPC_VERSIO
pushd fpc-$FPC_VERSION.i386-linux && ./install.sh && popd && \
rm -rf fpc-$FPC_VERSION.i386-linux
COPY compile.sh /compile.sh
ADD https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver /usr/bin/semver
RUN chmod +x /usr/bin/semver
WORKDIR /code
RUN find . -type f -print0 | xargs -0 dos2unix
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/compile.sh"]
CMD ["find toolchain -name '*.sh' -exec dos2unix {} + 2>/dev/null; find toolchain -name '*.sh' -exec chmod +x {} +; bash toolchain/compile.sh"]
+75
View File
@@ -0,0 +1,75 @@
{ Compatibility shim: wasuro references the old unit name 'lmemorymanager'.
Since wasuro/ cannot be modified, this unit re-exports the public API of
memory.heap so that 'uses lmemorymanager' continues to compile. }
unit lmemorymanager;
interface
uses
memory.heap;
const
ALLOC_UNIT = memory.heap.ALLOC_UNIT;
DATA_OFFSET = memory.heap.DATA_OFFSET;
PAGE_SIZE_LMM = memory.heap.PAGE_SIZE_LMM;
TOTAL_UNITS = memory.heap.TOTAL_UNITS;
BITMAP_DWORDS = memory.heap.BITMAP_DWORDS;
SIZE_PREFIX = memory.heap.SIZE_PREFIX;
LARGE_ALLOC_MAGIC = memory.heap.LARGE_ALLOC_MAGIC;
type
PHeapPageHeader = memory.heap.PHeapPageHeader;
THeapPageHeader = memory.heap.THeapPageHeader;
procedure init;
function kalloc(size : uint32) : void;
function klalloc(size : uint32) : void;
procedure klfree(address : uint32);
function kpalloc(address : uint32) : void;
procedure kfree(area : void);
function lmm_total_free : uint32;
function lmm_page_count : uint32;
implementation
procedure init;
begin
memory.heap.init;
end;
function kalloc(size : uint32) : void; inline;
begin
kalloc := memory.heap.kalloc(size);
end;
function klalloc(size : uint32) : void; inline;
begin
klalloc := memory.heap.klalloc(size);
end;
procedure klfree(address : uint32); inline;
begin
memory.heap.klfree(address);
end;
function kpalloc(address : uint32) : void; inline;
begin
kpalloc := memory.heap.kpalloc(address);
end;
procedure kfree(area : void); inline;
begin
memory.heap.kfree(area);
end;
function lmm_total_free : uint32; inline;
begin
lmm_total_free := memory.heap.lmm_total_free;
end;
function lmm_page_count : uint32; inline;
begin
lmm_page_count := memory.heap.lmm_page_count;
end;
end.
+7
View File
@@ -0,0 +1,7 @@
unit types;
interface
implementation
end.
-8
View File
@@ -1,8 +0,0 @@
#!/usr/bin/env bash
echo " "
echo "======================="
echo " "
echo "Compiling Stub..."
echo " "
nasm -f elf src/stub/stub.asm -o lib/stub.o
nasm -f elf src/stub/splash_tga.asm -o lib/splash_tga.o
+648
View File
File diff suppressed because it is too large Load Diff
@@ -17,12 +17,12 @@
@author(Angus C <angus@actm.uk>)
}
unit base64_prog;
unit app.base64;
interface
uses
stdio, util, strings, tracer, base64, lmemorymanager;
io.stdio, core.util, arch.x86.util, core.strings, debug.tracer, core.enc.base64, memory.heap;
procedure init();
@@ -38,7 +38,7 @@ var
PSize : uInt32;
begin
tracer.push_trace('base64_prog.run');
debug.tracer.push_trace('base64_prog.run');
if paramCount(Params) > 1 then begin
encdec := getParam(0, Params);
if stringEquals(encdec, 'encode') then begin
@@ -58,23 +58,23 @@ begin
dec(pinput);
pinput^ := #0;
result := b64_encode_str(input);
stdio.bufWriteStrLn(stdout_buf, result);
io.stdio.bufWriteStrLn(stdout_buf, result);
kfree(void(result));
end else if stringEquals(encdec, 'decode') then begin
input := getParam(1, Params);
result := b64_decode_str(input);
stdio.bufWriteStrLn(stdout_buf, result);
io.stdio.bufWriteStrLn(stdout_buf, result);
kfree(void(result));
end else stdio.bufWriteStrLn(stderr_buf, 'Usage: base64 <encode/decode> <text>');
end else io.stdio.bufWriteStrLn(stderr_buf, 'Usage: core.enc.base64 <encode/decode> <text>');
end else begin
stdio.bufWriteStrLn(stderr_buf, 'Usage: base64 <encode/decode> <text>');
io.stdio.bufWriteStrLn(stderr_buf, 'Usage: core.enc.base64 <encode/decode> <text>');
end;
end;
procedure init();
begin
tracer.push_trace('base64_prog.init');
stdio.registerCommand('BASE64', @Run, 'Perform Base64 Encode/Decode.');
debug.tracer.push_trace('base64_prog.init');
io.stdio.registerCommand('BASE64', @Run, 'Perform Base64 Encode/Decode.');
end;
end.
@@ -17,12 +17,12 @@
@author(Kieron Morris <kjm@kieronmorris.me>)
}
unit dhclient;
unit app.dhclient;
interface
uses
stdio, util, strings, tracer, dhcp;
io.stdio, core.util, arch.x86.util, core.strings, debug.tracer, driver.net.proto.dhcp;
procedure init();
@@ -30,14 +30,14 @@ implementation
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
begin
tracer.push_trace('dhclient.run');
debug.tracer.push_trace('dhclient.run');
DHCPDiscover();
end;
procedure init();
begin
tracer.push_trace('dhclient.init');
stdio.registerCommand('DHClient', @Run, 'Run the DHCP configuration utility.');
debug.tracer.push_trace('dhclient.init');
io.stdio.registerCommand('DHClient', @Run, 'Run the DHCP configuration utility.');
end;
end.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -17,12 +17,12 @@
@author(Kieron Morris <kjm@kieronmorris.me>)
}
unit md5sum;
unit app.md5sum;
interface
uses
stdio, util, strings, tracer, md5;
io.stdio, core.util, arch.x86.util, core.strings, debug.tracer, core.enc.md5;
procedure init();
@@ -40,15 +40,15 @@ begin
wordlen:= stringSize(md5word);
MD5_Hash := MD5Buffer(puint8(md5word), wordlen);
for i:=0 to 15 do begin
stdio.bufWriteHexPair(stdout_buf, MD5_Hash^[i]);
io.stdio.bufWriteHexPair(stdout_buf, MD5_Hash^[i]);
end;
stdio.bufWriteStrLn(stdout_buf, ' ');
io.stdio.bufWriteStrLn(stdout_buf, ' ');
end;
procedure init();
begin
tracer.push_trace('md5sum.init');
stdio.registerCommand('MD5SUM', @Run, 'Perform MD5SUM on a word.');
debug.tracer.push_trace('md5sum.init');
io.stdio.registerCommand('MD5SUM', @Run, 'Perform MD5SUM on a word.');
end;
end.
+83
View File
@@ -0,0 +1,83 @@
// Copyright 2021 Kieron Morris
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{
Prog->app.meminfo - Print memory statistics (PMM / LMM).
@author(Kieron Morris <[email protected]>)
}
unit app.meminfo;
interface
uses
io.stdio, arch.x86.multiboot, arch.x86.memory.physical, memory.heap, debug.tracer;
procedure init();
implementation
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
var
pmm_total, pmm_free, pmm_used : uint32;
lmm_pages, lmm_free : uint32;
begin
{ Multiboot memory info }
io.stdio.bufWriteStrLn(stdout_buf, '--- Multiboot ---');
io.stdio.bufWriteStr(stdout_buf, 'Lower Memory : ');
io.stdio.bufWriteInt(stdout_buf, multibootinfo^.mem_lower);
io.stdio.bufWriteStrLn(stdout_buf, ' KB');
io.stdio.bufWriteStr(stdout_buf, 'Upper Memory : ');
io.stdio.bufWriteInt(stdout_buf, multibootinfo^.mem_upper);
io.stdio.bufWriteStrLn(stdout_buf, ' KB');
io.stdio.bufWriteStr(stdout_buf, 'Total Memory : ');
io.stdio.bufWriteInt(stdout_buf, ((multibootinfo^.mem_upper + 1000) div 1024) + 1);
io.stdio.bufWriteStrLn(stdout_buf, ' MB');
{ PMM stats }
io.stdio.bufWriteStrLn(stdout_buf, '--- PMM (4 MB blocks) ---');
pmm_total := arch.x86.memory.physical.pmm_total_blocks;
pmm_free := arch.x86.memory.physical.pmm_free_blocks;
pmm_used := pmm_total - pmm_free;
io.stdio.bufWriteStr(stdout_buf, 'Total Blocks : ');
io.stdio.bufWriteIntLn(stdout_buf, pmm_total);
io.stdio.bufWriteStr(stdout_buf, 'Free Blocks : ');
io.stdio.bufWriteIntLn(stdout_buf, pmm_free);
io.stdio.bufWriteStr(stdout_buf, 'Used Blocks : ');
io.stdio.bufWriteIntLn(stdout_buf, pmm_used);
io.stdio.bufWriteStr(stdout_buf, 'Free Physical : ');
io.stdio.bufWriteInt(stdout_buf, pmm_free * 4);
io.stdio.bufWriteStrLn(stdout_buf, ' MB');
{ LMM heap stats }
io.stdio.bufWriteStrLn(stdout_buf, '--- LMM (Heap) ---');
lmm_pages := memory.heap.lmm_page_count;
lmm_free := memory.heap.lmm_total_free;
io.stdio.bufWriteStr(stdout_buf, 'Heap Pages : ');
io.stdio.bufWriteIntLn(stdout_buf, lmm_pages);
io.stdio.bufWriteStr(stdout_buf, 'Heap Size : ');
io.stdio.bufWriteInt(stdout_buf, lmm_pages * 4);
io.stdio.bufWriteStrLn(stdout_buf, ' MB');
io.stdio.bufWriteStr(stdout_buf, 'Heap Free : ');
io.stdio.bufWriteInt(stdout_buf, lmm_free div 1024);
io.stdio.bufWriteStrLn(stdout_buf, ' KB');
end;
procedure init();
begin
debug.tracer.push_trace('meminfo.init');
io.stdio.registerCommand('MEMINFO', @Run, 'Print memory statistics (PMM/LMM).');
end;
end.
+86
View File
@@ -0,0 +1,86 @@
// Copyright 2021 Kieron Morris
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{
ProgManager - Central initialization for terminal registered, baked-in programs.
@author(Kieron Morris <[email protected]>)
@author(Aaron Hance <[email protected]>)
}
unit app.mgr;
interface
uses
debug.tracer, io.stdio, proc.mgr,
//progs
app.base64, app.md5sum, app.dhclient, app.vbeinfo, app.testcmd, app.ping, app.meminfo, app.setres,
//drivers
driver.storage.ctl.ram, driver.mgr,
//network
driver.net.proto.ipv4, driver.net.proto.arp, driver.net.proto.tcp,
//dispatch
driver.storage.filedispatch,
//wasm
app.wasm.runner;
{ Initialize all baked-in programs }
procedure init();
implementation
uses
core.version,
//command provider units
arch.x86.cpu,
app.diskcmd, driver.bus.usb.core, app.diskutil, app.notepad, app.partcmd, app.volcmd;
procedure init();
begin
debug.tracer.push_trace('app.mgr.init');
{ Register commands from provider units }
io.stdio.registerCommand('CPU', @arch.x86.cpu.Terminal_Command_CPU, 'CPU Info.');
io.stdio.registerCommand('DEV', @driver.mgr.terminal_command_dev, 'Driver Management Interface.');
io.stdio.registerCommand('PS', @proc.mgr.terminal_command_ps, 'List running processes.');
io.stdio.registerCommand('KILL', @proc.mgr.terminal_command_kill, 'Force-kill a process by PID.');
io.stdio.registerCommand('TERMINATE', @proc.mgr.terminal_command_terminate, 'Gracefully terminate a process by PID.');
io.stdio.registerCommand('ARP', @driver.net.proto.arp.terminal_command_arp, 'Get ARP Table.');
io.stdio.registerCommand('IFCONFIG', @driver.net.proto.ipv4.terminal_command_ifconfig, 'Configure Network Settings.');
io.stdio.registerCommand('TCPCONNECT', @driver.net.proto.tcp.terminal_command_tcpconnect, 'Connect to a TCP host and send Hello World.');
io.stdio.registerCommand('TCPLISTEN', @driver.net.proto.tcp.terminal_command_tcplisten, 'Listen on a TCP port and log received data.');
io.stdio.registerCommand('TCPHTTP', @driver.net.proto.tcp.terminal_command_tcphttp, 'Send HTTP GET to a host IP (port 80 default).');
io.stdio.registerCommand('USB', @driver.bus.usb.core.terminal_command_usb, 'driver.bus.usb subsystem information.');
{ Initialize baked-in programs }
app.diskcmd.init();
app.partcmd.init();
app.volcmd.init();
app.diskutil.init();
app.notepad.init();
app.md5sum.init();
app.base64.init();
app.dhclient.init();
app.vbeinfo.init();
app.testcmd.init();
app.ping.init();
app.meminfo.init();
{ File dispatch & WASM integration }
driver.storage.ctl.ram.init();
driver.storage.filedispatch.init();
app.wasm.runner.init();
app.setres.init();
end;
end.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+21 -21
View File
@@ -3,28 +3,28 @@
Sends 10 ICMP echo requests to a host, printing round-trip time
for each reply. Sleeps 1 second between pings. Each invocation
uses a heap-allocated state record so multiple terminals can ping
uses a heap-allocated state record so multiple terminals can app.ping
concurrently without corrupting each other.
@author(Kieron Morris <kjm@kieronmorris.me>)
}
unit ping;
unit app.ping;
interface
uses
stdio, tracer;
io.stdio, debug.tracer;
procedure init();
implementation
uses
bios_data_area, nettypes, icmp, netutils, strings,
processmanager, util, lmemorymanager;
arch.x86.bda, driver.net.types, driver.net.proto.icmp, driver.net.util, core.strings,
proc.mgr, core.util, arch.x86.util, memory.heap;
const
PING_TIMEOUT_MS = 5000; { 5-second timeout per ping }
PING_TIMEOUT_MS = 5000; { 5-second timeout per app.ping }
type
TPingResult = (prWaiting, prGotReply, prGotError);
@@ -74,14 +74,14 @@ var
timeoutTicks : uint32;
begin
if ParamCount(Params) < 1 then begin
stdio.bufWriteStrLn(stderr_buf, 'Usage: PING <ip>');
io.stdio.bufWriteStrLn(stderr_buf, 'Usage: PING <ip>');
exit;
end;
ip_str := getParam(0, Params);
ip := stringToIPv4(ip_str);
if ip = nil then begin
stdio.bufWriteStrLn(stderr_buf, 'Invalid IP address.');
io.stdio.bufWriteStrLn(stderr_buf, 'Invalid IP address.');
exit;
end;
@@ -93,12 +93,12 @@ begin
{ Send ICMP echo request }
st^.Result := prWaiting;
st^.SendTime := Counters.c64;
icmp.sendICMPRequest(ip, i, 128, @on_reply, @on_error, void(st));
driver.net.proto.icmp.sendICMPRequest(ip, i, 128, @on_reply, @on_error, void(st));
{ Spin-yield until callback fires or timeout }
tStart := Counters.c32;
while st^.Result = prWaiting do begin
processmanager.proc_yield;
proc.mgr.proc_yield;
tNow := Counters.c32;
if tNow >= tStart then
elapsed := tNow - tStart
@@ -113,22 +113,22 @@ begin
{ Display result }
if st^.Result = prGotReply then begin
stdio.bufWriteStr(stdout_buf, 'Ping Reply: ');
stdio.bufWriteInt(stdout_buf, st^.ReplyTimeMS);
stdio.bufWriteStrLn(stdout_buf, 'ms.');
io.stdio.bufWriteStr(stdout_buf, 'Ping Reply: ');
io.stdio.bufWriteInt(stdout_buf, st^.ReplyTimeMS);
io.stdio.bufWriteStrLn(stdout_buf, 'ms.');
end else begin
stdio.bufWriteStr(stderr_buf, 'Ping Error: ');
io.stdio.bufWriteStr(stderr_buf, 'Ping Error: ');
case st^.ErrorReason of
aecFailedToResolveHost: stdio.bufWriteStrLn(stderr_buf, 'Failed to resolve host.');
aecNoRouteToHost: stdio.bufWriteStrLn(stderr_buf, 'No route to host.');
aecTimeout: stdio.bufWriteStrLn(stderr_buf, 'Timeout expired.');
aecTTLExpired: stdio.bufWriteStrLn(stderr_buf, 'TTL Expired.');
aecFailedToResolveHost: io.stdio.bufWriteStrLn(stderr_buf, 'Failed to resolve host.');
aecNoRouteToHost: io.stdio.bufWriteStrLn(stderr_buf, 'No route to host.');
aecTimeout: io.stdio.bufWriteStrLn(stderr_buf, 'Timeout expired.');
aecTTLExpired: io.stdio.bufWriteStrLn(stderr_buf, 'TTL Expired.');
end;
end;
{ Sleep 1 second between pings (except after last) }
if i < 9 then
processmanager.proc_sleep_ms(1000);
proc.mgr.proc_sleep_ms(1000);
end;
{ Clean up }
@@ -138,8 +138,8 @@ end;
procedure init();
begin
tracer.push_trace('ping.init');
stdio.registerCommand('PING', @run, 'Ping a host.');
debug.tracer.push_trace('ping.init');
io.stdio.registerCommand('PING', @run, 'Ping a host.');
end;
end.

Some files were not shown because too many files have changed in this diff Show More