refactor: namespace restructure of entire codebase
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Reorganize all source files into a hierarchical namespace structure with dot-separated unit names matching directory paths. Major changes: - src/prog/ -> src/app/ (app.*.pas) - src/fault/ -> src/arch/x86/fault/ (arch.x86.fault.*.pas) - src/isr/ -> src/arch/x86/isr/ (arch.x86.isr.*.pas) - src/include/ -> src/core/ (core.*.pas) + src/arch/x86/ - src/driver/ subtree reorganized with driver.* namespace prefixes - src/driver/storage/con/ -> src/driver/storage/ctl/ (Windows reserved name fix) - src/driver/storage/ split into con(ctl)/fs/vol/ subdirectories - src/driver/net/ flattened from l1-l5 layers to driver.net.*.pas - kernel.pas -> asuro.pas, faults.pas -> arch.x86.faults.pas - stdio.pas/syslog.pas -> io/io.stdio.pas, io/io.syslog.pas - processmanager.pas -> proc/proc.mgr.pas - lmemorymanager.pas -> memory/memory.heap.pas - Build scripts moved to toolchain/ - Added compat/ shims for lmemorymanager and types - Added doc/namespace.md tracking the refactor 197 files changed, 6292 insertions(+), 5526 deletions(-)
This commit is contained in:
1 parent
e922f086c2
commit
6fa008ed79
197 files changed
+6291
-5525
No files matched your search
@@ -0,0 +1,80 @@
|
||||
// Copyright 2021 Angus C
|
||||
//
|
||||
// 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->Base64 - Base64 encode and decode.
|
||||
|
||||
@author(Angus C <[email protected]>)
|
||||
}
|
||||
unit app.base64;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.stdio, core.util, arch.x86.util, core.strings, debug.tracer, core.enc.base64, memory.heap;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
|
||||
var
|
||||
input : pchar;
|
||||
pinput : pchar;
|
||||
encdec : pchar;
|
||||
result : pchar;
|
||||
i : uInt32;
|
||||
PSize : uInt32;
|
||||
|
||||
begin
|
||||
debug.tracer.push_trace('base64_prog.run');
|
||||
if paramCount(Params) > 1 then begin
|
||||
encdec := getParam(0, Params);
|
||||
if stringEquals(encdec, 'encode') then begin
|
||||
PSize := 0;
|
||||
for i := 1 to ParamCount(params) - 1 do begin
|
||||
PSize := PSize + stringSize(getParam(i, Params));
|
||||
end;
|
||||
Psize := PSize + 1 + (ParamCount(params) - 1);
|
||||
input := pchar(kalloc(PSize));
|
||||
pinput := input;
|
||||
for i := 1 to ParamCount(params) - 1 do begin
|
||||
memcpy(uInt32(getParam(i, Params)), uInt32(pinput), stringSize(getParam(i, Params)));
|
||||
inc(pinput, stringSize(getParam(i, Params)));
|
||||
pinput^ := ' ';
|
||||
inc(pinput);
|
||||
end;
|
||||
dec(pinput);
|
||||
pinput^ := #0;
|
||||
result := b64_encode_str(input);
|
||||
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);
|
||||
io.stdio.bufWriteStrLn(stdout_buf, result);
|
||||
kfree(void(result));
|
||||
end else io.stdio.bufWriteStrLn(stderr_buf, 'Usage: core.enc.base64 <encode/decode> <text>');
|
||||
end else begin
|
||||
io.stdio.bufWriteStrLn(stderr_buf, 'Usage: core.enc.base64 <encode/decode> <text>');
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
debug.tracer.push_trace('base64_prog.init');
|
||||
io.stdio.registerCommand('BASE64', @Run, 'Perform Base64 Encode/Decode.');
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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->DHClient - DHCP Configuration Management.
|
||||
|
||||
@author(Kieron Morris <[email protected]>)
|
||||
}
|
||||
unit app.dhclient;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.stdio, core.util, arch.x86.util, core.strings, debug.tracer, driver.net.dhcp;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
|
||||
begin
|
||||
debug.tracer.push_trace('dhclient.run');
|
||||
DHCPDiscover();
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
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
@@ -0,0 +1,145 @@
|
||||
{
|
||||
Prog->app.inio - Inline IO
|
||||
|
||||
Usage:
|
||||
app.inio <file> < Read file contents to terminal
|
||||
app.inio <file> > text Write text to file
|
||||
|
||||
@author(Aaron Hance <[email protected]>)
|
||||
}
|
||||
unit app.inio;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.syslog,
|
||||
memory.heap,
|
||||
driver.storage.types,
|
||||
core.strings,
|
||||
io.stdio,
|
||||
debug.tracer,
|
||||
core.util, arch.x86.util,
|
||||
driver.storage.vfs;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
procedure Run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf: POutBuf);
|
||||
var
|
||||
filePath : pchar;
|
||||
absPath : pchar;
|
||||
op : pchar;
|
||||
fError : driver.storage.types.TError;
|
||||
fHandle : driver.storage.vfs.TFileHandle;
|
||||
buf : pchar;
|
||||
bytesRead : uint32;
|
||||
content : pchar;
|
||||
part : pchar;
|
||||
tmp : pchar;
|
||||
i : uint32;
|
||||
pCount : uint32;
|
||||
contentLen : uint32;
|
||||
begin
|
||||
debug.tracer.push_trace('inio.run');
|
||||
|
||||
pCount := paramCount(Params);
|
||||
if pCount < 2 then begin
|
||||
io.syslog.writestringln('Usage: app.inio <file> < | app.inio <file> > text');
|
||||
exit;
|
||||
end;
|
||||
|
||||
filePath := getParam(0, Params);
|
||||
op := getParam(1, Params);
|
||||
|
||||
if filePath = nil then begin
|
||||
io.syslog.writestringln('Error: no file specified.');
|
||||
exit;
|
||||
end;
|
||||
if op = nil then begin
|
||||
io.syslog.writestringln('Error: no operation specified.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
absPath := driver.storage.vfs.MakeAbsolutePath(filePath);
|
||||
|
||||
{ ---- READ ---- }
|
||||
if op[0] = '<' then begin
|
||||
fHandle := driver.storage.vfs.OpenFile(absPath, omReadOnly, wmRewrite, @fError);
|
||||
if (fHandle = 0) or (fError <> eNone) then begin
|
||||
io.syslog.writestringln('Error: cannot open file for reading.');
|
||||
kfree(void(absPath));
|
||||
exit;
|
||||
end;
|
||||
buf := pchar(kalloc(32768));
|
||||
memset(uint32(buf), 0, 32768);
|
||||
bytesRead := driver.storage.vfs.ReadFile(fHandle, 0, puint8(buf), 32767);
|
||||
driver.storage.vfs.CloseFile(fHandle);
|
||||
|
||||
if bytesRead > 0 then begin
|
||||
buf[bytesRead] := char(0);
|
||||
io.syslog.writestring(buf);
|
||||
io.syslog.writestringln(' ');
|
||||
end else begin
|
||||
io.syslog.writestringln('(0 bytes read)');
|
||||
end;
|
||||
kfree(puint32(buf));
|
||||
end
|
||||
|
||||
{ ---- WRITE ---- }
|
||||
else if op[0] = '>' then begin
|
||||
if pCount < 3 then begin
|
||||
io.syslog.writestringln('Error: no content to write.');
|
||||
kfree(void(absPath));
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ Build content string by joining params 2..N with spaces }
|
||||
content := stringCopy(getParam(2, Params));
|
||||
i := 3;
|
||||
while i < pCount do begin
|
||||
part := getParam(i, Params);
|
||||
if part <> nil then begin
|
||||
{ content + ' ' + part }
|
||||
tmp := stringConcat(content, ' ');
|
||||
kfree(void(content));
|
||||
content := stringConcat(tmp, part);
|
||||
kfree(void(tmp));
|
||||
end;
|
||||
i := i + 1;
|
||||
end;
|
||||
|
||||
contentLen := stringSize(content);
|
||||
|
||||
{ Try read-write rewrite first (existing file) }
|
||||
fHandle := driver.storage.vfs.OpenFile(absPath, omReadWrite, wmRewrite, @fError);
|
||||
if (fHandle = 0) or (fError <> eNone) then begin
|
||||
{ Try creating new file }
|
||||
fHandle := driver.storage.vfs.OpenFile(absPath, omWriteOnly, wmNew, @fError);
|
||||
end;
|
||||
|
||||
if (fHandle = 0) or (fError <> eNone) then begin
|
||||
io.syslog.writestringln('Error: cannot open file for writing.');
|
||||
kfree(void(content));
|
||||
kfree(void(absPath));
|
||||
exit;
|
||||
end;
|
||||
|
||||
driver.storage.vfs.WriteFile(fHandle, 0, puint8(content), contentLen);
|
||||
driver.storage.vfs.CloseFile(fHandle);
|
||||
io.syslog.writestringln('Written.');
|
||||
kfree(void(content));
|
||||
end else begin
|
||||
io.syslog.writestringln('Error: operation must be < or >.');
|
||||
end;
|
||||
|
||||
kfree(void(absPath));
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
debug.tracer.push_trace('inio.init');
|
||||
io.stdio.registerCommand('INIO', @Run, 'Inline IO: app.inio <file> < | app.inio <file> > text');
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -0,0 +1,54 @@
|
||||
// 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->MD5Sum - MD5 Checksum of a given string.
|
||||
|
||||
@author(Kieron Morris <[email protected]>)
|
||||
}
|
||||
unit app.md5sum;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.stdio, core.util, arch.x86.util, core.strings, debug.tracer, core.enc.md5;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
|
||||
var
|
||||
md5word : pchar;
|
||||
wordlen : uint32;
|
||||
MD5_Hash : PMD5Digest;
|
||||
i : uint32;
|
||||
|
||||
begin
|
||||
md5word:= getParam(0, Params);
|
||||
wordlen:= stringSize(md5word);
|
||||
MD5_Hash := MD5Buffer(puint8(md5word), wordlen);
|
||||
for i:=0 to 15 do begin
|
||||
io.stdio.bufWriteHexPair(stdout_buf, MD5_Hash^[i]);
|
||||
end;
|
||||
io.stdio.bufWriteStrLn(stdout_buf, ' ');
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
debug.tracer.push_trace('md5sum.init');
|
||||
io.stdio.registerCommand('MD5SUM', @Run, 'Perform MD5SUM on a word.');
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -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.
|
||||
@@ -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.ipv4, driver.net.arp, driver.net.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.arp.terminal_command_arp, 'Get ARP Table.');
|
||||
io.stdio.registerCommand('IFCONFIG', @driver.net.ipv4.terminal_command_ifconfig, 'Configure Network Settings.');
|
||||
io.stdio.registerCommand('TCPCONNECT', @driver.net.tcp.terminal_command_tcpconnect, 'Connect to a TCP host and send Hello World.');
|
||||
io.stdio.registerCommand('TCPLISTEN', @driver.net.tcp.terminal_command_tcplisten, 'Listen on a TCP port and log received data.');
|
||||
io.stdio.registerCommand('TCPHTTP', @driver.net.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
@@ -0,0 +1,145 @@
|
||||
{
|
||||
Prog->Ping - ICMP Ping command.
|
||||
|
||||
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 app.ping
|
||||
concurrently without corrupting each other.
|
||||
|
||||
@author(Kieron Morris <[email protected]>)
|
||||
}
|
||||
unit app.ping;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.stdio, debug.tracer;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
arch.x86.bda, driver.net.types, driver.net.icmp, driver.net.util, core.strings,
|
||||
proc.mgr, core.util, arch.x86.util, memory.heap;
|
||||
|
||||
const
|
||||
PING_TIMEOUT_MS = 5000; { 5-second timeout per app.ping }
|
||||
|
||||
type
|
||||
TPingResult = (prWaiting, prGotReply, prGotError);
|
||||
PPingState = ^TPingState;
|
||||
TPingState = record
|
||||
Result : TPingResult;
|
||||
ReplyTimeMS : uint64;
|
||||
ErrorReason : TARPErrorCode;
|
||||
SendTime : uint64;
|
||||
end;
|
||||
|
||||
{ ---- ICMP callbacks (called from network recv context) ---- }
|
||||
|
||||
procedure on_reply(hdr : PICMPHeader; userData : void);
|
||||
var
|
||||
st : PPingState;
|
||||
t2 : uint64;
|
||||
begin
|
||||
st := PPingState(userData);
|
||||
if st = nil then exit;
|
||||
t2 := Counters.c64;
|
||||
st^.ReplyTimeMS := t2 - st^.SendTime;
|
||||
st^.Result := prGotReply;
|
||||
end;
|
||||
|
||||
procedure on_error(hdr : PICMPHeader; Reason : TARPErrorCode; userData : void);
|
||||
var
|
||||
st : PPingState;
|
||||
begin
|
||||
st := PPingState(userData);
|
||||
if st = nil then exit;
|
||||
st^.ErrorReason := Reason;
|
||||
st^.Result := prGotError;
|
||||
end;
|
||||
|
||||
{ ---- Command entry point (runs as a process) ---- }
|
||||
|
||||
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
|
||||
var
|
||||
ip_str : pchar;
|
||||
ip : puint8;
|
||||
i : uint16;
|
||||
st : PPingState;
|
||||
tStart : uint32;
|
||||
tNow : uint32;
|
||||
elapsed : uint32;
|
||||
timeoutTicks : uint32;
|
||||
begin
|
||||
if ParamCount(Params) < 1 then begin
|
||||
io.stdio.bufWriteStrLn(stderr_buf, 'Usage: PING <ip>');
|
||||
exit;
|
||||
end;
|
||||
|
||||
ip_str := getParam(0, Params);
|
||||
ip := stringToIPv4(ip_str);
|
||||
if ip = nil then begin
|
||||
io.stdio.bufWriteStrLn(stderr_buf, 'Invalid IP address.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ Allocate per-invocation state so concurrent pings are safe }
|
||||
st := PPingState(kalloc(sizeof(TPingState)));
|
||||
timeoutTicks := (PING_TIMEOUT_MS * 1024) div 1000;
|
||||
|
||||
for i := 0 to 9 do begin
|
||||
{ Send ICMP echo request }
|
||||
st^.Result := prWaiting;
|
||||
st^.SendTime := Counters.c64;
|
||||
driver.net.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
|
||||
proc.mgr.proc_yield;
|
||||
tNow := Counters.c32;
|
||||
if tNow >= tStart then
|
||||
elapsed := tNow - tStart
|
||||
else
|
||||
elapsed := ($FFFFFFFF - tStart) + tNow + 1;
|
||||
if elapsed >= timeoutTicks then begin
|
||||
st^.Result := prGotError;
|
||||
st^.ErrorReason := aecTimeout;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Display result }
|
||||
if st^.Result = prGotReply then begin
|
||||
io.stdio.bufWriteStr(stdout_buf, 'Ping Reply: ');
|
||||
io.stdio.bufWriteInt(stdout_buf, st^.ReplyTimeMS);
|
||||
io.stdio.bufWriteStrLn(stdout_buf, 'ms.');
|
||||
end else begin
|
||||
io.stdio.bufWriteStr(stderr_buf, 'Ping Error: ');
|
||||
case st^.ErrorReason of
|
||||
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
|
||||
proc.mgr.proc_sleep_ms(1000);
|
||||
end;
|
||||
|
||||
{ Clean up }
|
||||
kfree(void(st));
|
||||
kfree(void(ip));
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
debug.tracer.push_trace('ping.init');
|
||||
io.stdio.registerCommand('PING', @run, 'Ping a host.');
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -0,0 +1,83 @@
|
||||
{
|
||||
Prog->app.setres - Set display resolution via GPU driver framework.
|
||||
|
||||
Usage: SETRES <width> <height>
|
||||
Example: SETRES 1024 768
|
||||
|
||||
Uses the GPU driver framework to switch display modes. Tries BGA first,
|
||||
then falls back to VBE/VESA.
|
||||
|
||||
@author(Kieron Morris <[email protected]>)
|
||||
}
|
||||
unit app.setres;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.stdio, driver.video.gpu, core.util, arch.x86.util, core.strings, debug.tracer, io.syslog;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
|
||||
var
|
||||
w, h : uint32;
|
||||
wStr, hStr : pchar;
|
||||
info : TGPUModeInfo;
|
||||
|
||||
begin
|
||||
debug.tracer.push_trace('setres.run');
|
||||
|
||||
if paramCount(params) < 2 then begin
|
||||
io.stdio.bufWriteStrLn(stderr_buf, 'Usage: SETRES <width> <height>');
|
||||
io.stdio.bufWriteStrLn(stderr_buf, 'Example: SETRES 1024 768');
|
||||
debug.tracer.pop_trace;
|
||||
exit;
|
||||
end;
|
||||
|
||||
wStr := getParam(0, params);
|
||||
hStr := getParam(1, params);
|
||||
|
||||
w := stringToInt(wStr);
|
||||
h := stringToInt(hStr);
|
||||
|
||||
if (w = 0) or (h = 0) then begin
|
||||
io.stdio.bufWriteStrLn(stderr_buf, 'Error: Invalid resolution values.');
|
||||
debug.tracer.pop_trace;
|
||||
exit;
|
||||
end;
|
||||
|
||||
io.stdio.bufWriteStr(stdout_buf, 'Setting resolution to ');
|
||||
io.stdio.bufWriteInt(stdout_buf, w);
|
||||
io.stdio.bufWriteStr(stdout_buf, 'x');
|
||||
io.stdio.bufWriteInt(stdout_buf, h);
|
||||
io.stdio.bufWriteStrLn(stdout_buf, 'x32...');
|
||||
|
||||
{ Step 1: Set display mode via GPU framework (tries BGA first, then VBE) }
|
||||
if not driver.video.gpu.setMode(w, h, 32, info) then begin
|
||||
io.stdio.bufWriteStrLn(stderr_buf, 'Error: Mode switch failed. Mode may not be supported.');
|
||||
debug.tracer.pop_trace;
|
||||
exit;
|
||||
end;
|
||||
|
||||
io.stdio.bufWriteStr(stdout_buf, 'Mode set via ');
|
||||
io.stdio.bufWriteStrLn(stdout_buf, driver.video.gpu.activeDriverName());
|
||||
|
||||
io.stdio.bufWriteStr(stdout_buf, 'Resolution set to ');
|
||||
io.stdio.bufWriteInt(stdout_buf, w);
|
||||
io.stdio.bufWriteStr(stdout_buf, 'x');
|
||||
io.stdio.bufWriteInt(stdout_buf, h);
|
||||
io.stdio.bufWriteStrLn(stdout_buf, 'x32 successfully.');
|
||||
|
||||
debug.tracer.pop_trace;
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
debug.tracer.push_trace('setres.init');
|
||||
io.stdio.registerCommand('SETRES', @Run, 'Set display resolution. Usage: SETRES <width> <height>');
|
||||
debug.tracer.pop_trace;
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
Prog->TestCmd - Test command that prints 5 lines with 1-second delays.
|
||||
|
||||
Demonstrates a long-running command that writes incrementally to stdout.
|
||||
|
||||
@author(Kieron Morris <[email protected]>)
|
||||
}
|
||||
unit app.testcmd;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.stdio, proc.mgr, debug.tracer;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
|
||||
var
|
||||
i : uint32;
|
||||
begin
|
||||
for i := 1 to 5 do begin
|
||||
case i of
|
||||
1: io.stdio.bufWriteStrLn(stdout_buf, 'Test output 1 of 5');
|
||||
2: io.stdio.bufWriteStrLn(stdout_buf, 'Test output 2 of 5');
|
||||
3: io.stdio.bufWriteStrLn(stdout_buf, 'Test output 3 of 5');
|
||||
4: io.stdio.bufWriteStrLn(stdout_buf, 'Test output 4 of 5');
|
||||
5: io.stdio.bufWriteStrLn(stdout_buf, 'Test output 5 of 5');
|
||||
end;
|
||||
if i < 5 then
|
||||
proc.mgr.proc_sleep_ms(1000);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
debug.tracer.push_trace('testcmd.init');
|
||||
io.stdio.registerCommand('TEST', @run, 'Print 5 lines with 1-second delays.');
|
||||
end;
|
||||
|
||||
end.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,47 @@
|
||||
// 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.vbeinfo - Print out app.vbeinfo (VESA VGA).
|
||||
|
||||
@author(Kieron Morris <[email protected]>)
|
||||
}
|
||||
unit app.vbeinfo;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
io.stdio, driver.video, core.util, arch.x86.util, core.strings, debug.tracer;
|
||||
|
||||
procedure init();
|
||||
|
||||
implementation
|
||||
|
||||
procedure run(Params : PParamList; stdin_buf, stdout_buf, stderr_buf : POutBuf);
|
||||
begin
|
||||
io.stdio.bufWriteStr(stdout_buf, 'Pixel Width: ');
|
||||
io.stdio.bufWriteIntLn(stdout_buf, driver.video.frontBufferWidth);
|
||||
io.stdio.bufWriteStr(stdout_buf, 'Pixel Height: ');
|
||||
io.stdio.bufWriteIntLn(stdout_buf, driver.video.frontBufferHeight);
|
||||
io.stdio.bufWriteStr(stdout_buf, 'Bits Per Pixel: ');
|
||||
io.stdio.bufWriteIntLn(stdout_buf, driver.video.frontBufferBpp);
|
||||
end;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
debug.tracer.push_trace('vbeinfo.init');
|
||||
io.stdio.registerCommand('VBEINFO', @Run, 'Print out app.vbeinfo (VESA VGA).');
|
||||
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
Loaded 20 of 197 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user