commit c1cc08c8b24bd89ab982ad8defdc70d213d3231a
parent 525206b7e0cdf52e6a05926ee6d797f2663d23d4
Author: Lucas Chaloyard <lucas.chaloyard@insa-lyon.fr>
Date: Sat, 7 Jan 2023 11:02:25 -0500
emul/cos/stage: new unit (WIP)
Also, add a new "_unmountdrv" word to the POSIX vm.
Diffstat:
2 files changed, 93 insertions(+), 5 deletions(-)
diff --git a/fs/emul/cos/stage.fs b/fs/emul/cos/stage.fs
@@ -0,0 +1,80 @@
+\ This is a WIP, improvements incoming.
+\ The goal is to port "cvm/stage.c" from Collapse OS
+?f<< /emul/cos/tools/blkpack.fs
+cc<< /emul/cos/cvm.c
+
+S" COSVM" findTypedef CType :export
+
+( Extracted from xcomp/i386/pc/build.fs )
+$200 const SECSZ \ TODO: get from drive
+create _buf SECSZ allot0
+0 value _sec
+0 value _ptr
+: _imgflush ( drv -- )
+ _sec _buf rot Drive :sec! 1 to+ _sec 0 to _ptr _buf SECSZ 0 fill ;
+: _imgwrite ( c drv -- )
+ swap _buf _ptr + c! 1 to+ _ptr _ptr SECSZ = if _imgflush else drop then ;
+
+( Specific to POSIX DuskOS VM )
+0 value xcomp_image
+: imgload ( img-str -- )
+ mountImage to xcomp_image ;
+: imgclose
+ _unmountdrv
+ 0 to xcomp_image ;
+
+( BLK Filesystem loading in CollapseOS VM )
+: blkload ( blkfp-str -- )
+ curpath :find# Path :open blkfp ! ;
+: blkclose
+ blkfp @ File :close
+ 0 blkfp ! ;
+
+( Opening xcomp script )
+0 value xcomp_script
+: xcmpload ( xcomp-str -- )
+ curpath :find# Path :open to xcomp_script ;
+: xcmpclose
+ xcomp_script File :close
+ 0 to xcomp_script ;
+
+S" XORG HERE BYE\r" 1+ value suffix
+: _readsuffix ( -- c )
+ suffix c@ suffix 1+ to suffix ;
+
+: _readxcomp ( -- c )
+ xcomp_script dup
+ if IO :getc
+ dup 0< if drop ['] _readsuffix vm COSVM iord ! then
+ else S" No cross-compilation script loaded, aborting" StdOut IO :printf abort then ;
+
+: stage
+ COS_init
+ vm COSVM mem S" /emul/cos/serial.bin" curpath :find# Path :open
+ tuck File :readall File :close
+ ['] _readxcomp vm COSVM iord ! ( Will read from xcomp script file )
+ ['] stdout vm COSVM iowr !
+ begin 100 COS_steps not until COS_printdbg
+ COS_pop COS_pop ( end start -- ) tuck - ( start length -- )
+ swap ( length start -- ) vm COSVM mem + ( length start -- ) swap
+ >r begin ( start -- ) dup ( start ptr-to-byte -- ) @ ( start byte -- )
+ xcomp_image ( start byte drv -- ) _imgwrite 1+ ( start+1 -- ) next
+ xcomp_image _imgflush ;
+
+: pcat-stage
+ S" /emul/cos/pcat-blkfs" blkload
+ S" /emul/cos/pcat-xcomp.fs" xcmpload
+ S" fs/emul/cos/new.bin" imgload
+ stage
+ blkclose
+ xcmpclose
+ imgclose ;
+
+: serial-update
+ S" /emul/cos/serial-blkfs" blkload
+ S" /emul/cos/serial-comp.fs" xcmpload
+ S" fs/emul/cos/new-serial.bin" imgload
+ stage
+ blkclose
+ xcmpclose
+ imgclose ;
diff --git a/posix/vm.c b/posix/vm.c
@@ -1017,9 +1017,17 @@ static void MOUNTDRV() { // op: 68
}
}
+// ( -- )
+static void UNMOUNTDRV() { // op: 69
+ if (fp) {
+ fclose(fp);
+ fp = NULL;
+ }
+}
+
#define SECSZ 512
// ( sec dst drv -- )
-static void DRVRD() { // op: 69
+static void DRVRD() { // op: 6a
ppop();
dword dst = ppop();
dword sec = ppop();
@@ -1028,7 +1036,7 @@ static void DRVRD() { // op: 69
}
// ( sec src drv -- )
-static void DRVWR() { // op: 6a
+static void DRVWR() { // op: 6b
ppop();
dword src = ppop();
dword sec = ppop();
@@ -1036,7 +1044,7 @@ static void DRVWR() { // op: 6a
fwrite(&vm.mem[src], SECSZ, 1, fp);
}
-#define OPCNT 0x6b
+#define OPCNT 0x6c
static void (*ops[OPCNT])() = {
JUMP, CALL, RET, LIT, BYE, BYEFAIL, QUIT, ABORT_,
EXECUTE, CELL, DOES, SLIT, BR, CBR, NEXT, NULL,
@@ -1051,7 +1059,7 @@ static void (*ops[OPCNT])() = {
STACKCHK, MAYBEWORD, WORD, PARSE, REQ, FIND, APOS, COMPILING,
NULL, STARTCOMP, STOPCOMP, COMPWORD, RUNWORD, NULL, NULL, NULL,
FCHILD, FOPEN, FREADBUF, FCLOSE, FINFO, FITER, FSEEK, NULL,
- MOUNTDRV, DRVRD, DRVWR};
+ MOUNTDRV, UNMOUNTDRV, DRVRD, DRVWR};
static char *opnames[OPCNT] = {
NULL, NULL, NULL, NULL, "bye", "byefail", "quit", "(abort)",
@@ -1067,7 +1075,7 @@ static char *opnames[OPCNT] = {
"stack?", "maybeword", "word", "parse", "[]=", "find", "'", "compiling",
NULL, "]", "[", "compword", "runword", NULL, NULL, NULL,
"_fchild", "_fopen", "_freadbuf", "_fclose", "_finfo", "_fiter", "_fseek", NULL,
- "_mountdrv", "_drv@", "_drv!"};
+ "_mountdrv", "_unmountdrv", "_drv@", "_drv!"};
static void oprun1() { // run next op
if (!memchk(vm.PC)) return;