mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 09:38:06 +11:00
cvm: initialize memory with random garbage
This should help spot bugs due to bad initialization.
This commit is contained in:
parent
ddb934813e
commit
ba8a9c2647
10
cvm/vm.c
10
cvm/vm.c
@ -1,3 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "vm.h"
|
||||
@ -284,8 +285,6 @@ VM* VM_init() {
|
||||
return NULL;
|
||||
}
|
||||
fseek(blkfp, 0, SEEK_SET);
|
||||
// initialize memory
|
||||
memset(vm.mem, 0, 0x10000);
|
||||
FILE *bfp = fopen(FBIN_PATH, "r");
|
||||
if (!bfp) {
|
||||
fprintf(stderr, "Can't open forth.bin\n");
|
||||
@ -298,6 +297,13 @@ VM* VM_init() {
|
||||
c = getc(bfp);
|
||||
}
|
||||
fclose(bfp);
|
||||
// initialize rest of memory with random data. Many, many bugs we've seen in
|
||||
// Collapse OS were caused by bad initialization and weren't reproducable
|
||||
// in CVM because it has a neat zeroed-out memory. Let's make bugs easier
|
||||
// to spot.
|
||||
while (i<0x10000) {
|
||||
vm.mem[i++] = random();
|
||||
}
|
||||
vm.SP = SP_ADDR;
|
||||
vm.RS = RS_ADDR;
|
||||
vm.minSP = SP_ADDR;
|
||||
|
15
cvm/xcomp.fs
15
cvm/xcomp.fs
@ -6,23 +6,24 @@ RS_ADDR 0x80 - CONSTANT SYSVARS
|
||||
VARIABLE ORG
|
||||
CREATE BIN( 0 ,
|
||||
: PC H@ ORG @ - ;
|
||||
155 LOAD ( ALLOT0 )
|
||||
262 LOAD ( xcomp )
|
||||
270 LOAD ( xcomp overrides )
|
||||
|
||||
H@ ORG !
|
||||
ORG @ 0x0b + HERE !
|
||||
0x0b ALLOT0
|
||||
0 C, 0 C, ( EXIT )
|
||||
ORG @ 0x23 + HERE !
|
||||
0x16 ALLOT0
|
||||
0 C, 0x05 C, ( (n) )
|
||||
ORG @ 0x2b + HERE !
|
||||
0x6 ALLOT0
|
||||
0 C, 0x06 C, ( (s) )
|
||||
ORG @ 0x33 + HERE !
|
||||
0x6 ALLOT0
|
||||
0 C, 0x04 C, ( 2>R )
|
||||
ORG @ 0x3b + HERE !
|
||||
0x6 ALLOT0
|
||||
0 C, 0x01 C, ( (br) )
|
||||
ORG @ 0x3f + HERE !
|
||||
0x2 ALLOT0
|
||||
0 C, 0x02 C, ( (?br) )
|
||||
ORG @ 0x43 + HERE !
|
||||
0x2 ALLOT0
|
||||
0 C, 0x03 C, ( (loop) )
|
||||
( END OF STABLE ABI )
|
||||
H@ 4 + XCURRENT ! ( make next CODE have 0 prev field )
|
||||
|
Loading…
Reference in New Issue
Block a user