Skip to content

Commit 74c421a

Browse files
committed
checkpoint
1 parent 25f8e06 commit 74c421a

3 files changed

Lines changed: 63 additions & 26 deletions

File tree

ebox.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const utilFormats = require('./util');
1717
// Read our defines.mic and gobble definitions for fields and
1818
// constants for CRAM and DRAM.
1919
const {CRAMdefinitions, DRAMdefinitions} = require('./cram-defs');
20-
20+
module.exports.CRAMdefinitions = CRAMdefinitions;
2121

2222
// RH sign bit
2323
const SIGN18 = maskForBit(18);
@@ -492,7 +492,7 @@ const BitField = Combinatorial.compose({name: 'BitField'}).init(function({name,
492492
getInputs() {
493493
const v = this.input.get();
494494
assert(typeof this.shift === 'bigint', `${this.name} must define bigint shift`);
495-
const shifted = v >> BigInt(this.shift);
495+
const shifted = v >> this.shift;
496496
return shifted & this.ones;
497497
},
498498
});
@@ -1844,6 +1844,7 @@ function defineBitFields(input, s, ignoreFields = []) {
18441844
const bfName = `${input.name}['${fieldName}']`;
18451845
const inputClosure = input; // Create closure variable
18461846
curField = BitField({name: bfName, s, e, input: inputClosure, bitWidth});
1847+
curField.namesForValues = {};
18471848
const thisField = curField; // Create closure variable for getter
18481849

18491850
Object.defineProperty(input, fieldName, {
@@ -1863,6 +1864,7 @@ function defineBitFields(input, s, ignoreFields = []) {
18631864

18641865
if (curField) {
18651866
curField[defName] = BigInt(parseInt(value, 8));
1867+
curField.namesForValues[parseInt(value, 8)] = defName;
18661868
} else {
18671869
console.error(`ERROR: no field context for value definition in "${line}"`);
18681870
}
@@ -1873,6 +1875,7 @@ function defineBitFields(input, s, ignoreFields = []) {
18731875
}
18741876
});
18751877
}
1878+
module.exports.defineBitFields = defineBitFields;
18761879

18771880
// Export every EBOXUnit
18781881
module.exports = Object.assign(module.exports, Named.units);

kl10-source/define.mic

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,23 +406,23 @@ J/=<1:11>+ ;SYMBOLS WILL BE DEFINED BY TAGS (CRA1&CRA2)
406406
AD/=<12:17> ; (DP03, EXCEPT CARRY IN, ON CTL1)
407407
A+1=40,1
408408
A+XCRY=00,1
409-
; A+ANDCB=01,1
410-
; A+AND=02,1
409+
A+ANDCB=01,1
410+
A+AND=02,1
411411
A*2=03,1
412412
A*2+1=43,1
413-
; OR+1=44,1
414-
; OR+ANDCB=05,1
413+
OR+1=44,1
414+
OR+ANDCB=05,1
415415
A+B=06,1
416416
A+B+1=46,1
417-
; A+OR=07,1
417+
A+OR=07,1
418418
ORCB+1=50,1
419419
A-B-1=11,1
420420
A-B=51,1
421-
; AND+ORCB=52,1
422-
; A+ORCB=53,1
421+
AND+ORCB=52,1
422+
A+ORCB=53,1
423423
XCRY-1=54,1
424-
; ANDCB-1=15,1
425-
; AND-1=16,1
424+
ANDCB-1=15,1
425+
AND-1=16,1
426426
A-1=17,1
427427
;ADDER LOGICAL FUNCTIONS
428428
SETCA=20

read-ram-file.js

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
const _ = require('lodash');
33
const fs = require('fs');
44
const util = require('util');
5-
const {octal, oct6, fieldExtract} = require('./util');
5+
const {octal, oct6, fieldExtract, maskForBit, fieldMask} = require('./util');
66
const {cramFields} = require('./fields-model');
7-
const {unusedCRAMFields, CR} = require('./ebox');
7+
const {unusedCRAMFields, CRAMdefinitions, defineBitFields, EBOX, ConstantUnit} = require('./ebox');
88

99

1010
// List of field names in an array indexed by leftmost bit.
@@ -29,7 +29,7 @@ function decodeSplats(s) {
2929
function joinSplats(a) {
3030
let w = 0n;
3131

32-
for (let k = 0, shift = 0n; shift < 79n; ++k, shift += 16n) {
32+
for (let k = 0, shift = 0n; shift < 80n; ++k, shift += 16n) {
3333
w = (w << shift) | BigInt(a[k]);
3434
}
3535

@@ -49,15 +49,15 @@ function decodeLines(lines) {
4949
switch(recType) {
5050
case 'Z':
5151
const [zWC, zAdr, zCount, zCksum] = decoded;
52-
console.log(`Zero ${zWC}@${octal(zAdr)} count=${zCount}. cksum=${zCksum}.`);
52+
// console.log(`Zero ${zWC}@${octal(zAdr)} count=${zCount}. cksum=${zCksum}.`);
5353
break;
5454

5555
case 'C':
5656
case 'D':
5757
const [wc, adr, ...a] = decoded;
5858
const checksum = a.pop();
5959
const dump = a.map((w, x) => oct6(w) + (x % 6 === 5 ? '\n ' : '')).join(',');
60-
console.log(`${recType === 'C' ? 'CRAM' : 'DRAM'} ${octal(adr)}: ${dump}`);
60+
// console.log(`${recType === 'C' ? 'CRAM' : 'DRAM'} ${octal(adr)}: ${dump}`);
6161

6262
if (recType === 'C') {
6363

@@ -69,7 +69,7 @@ function decodeLines(lines) {
6969
break;
7070

7171
default:
72-
console.log(`Unknown recType: "${recType}"`);
72+
console.error(`Unknown recType: "${recType}"`);
7373
break;
7474
}
7575
});
@@ -78,27 +78,61 @@ function decodeLines(lines) {
7878
}
7979

8080

81+
function maybeSymbolic(field) {
82+
const v = field.get();
83+
return field.namesForValues[v] || octal(v);
84+
}
85+
86+
87+
const W = ConstantUnit({name: 'WORD', bitWidth: 84, value: 0});
88+
defineBitFields(W, CRAMdefinitions);
89+
90+
8191
function disassembleCRAMWord(w, a) {
92+
EBOX.reset();
93+
W.value = w;
8294
const wSplit = _.range(0, 84, 12).reduce((cur, s) => cur.concat([octal(fieldExtract(w, s, s+11, 84))]), []);
83-
CR.value = w;
8495

85-
const dis = fieldsByBit.filter(names => !unusedCRAMFields.includes(names[0])).map(names => {
86-
const name = names[0];
87-
const field = cramFields[name];
88-
return `${names[0]}/${fieldExtract(w, field.s, field.e, 84)}`;
89-
}).join(', ');
96+
// Compute mask of CRAM word bits we need to disassemble. This is
97+
// gradually zeroed as we proceed disassembling this word.
98+
let remainingMask = fieldMask(0, 83, 84);
99+
unusedCRAMFields.forEach(name => {
100+
const {s, e} = cramFields[name];
101+
remainingMask &= ~fieldMask(s, e, 84);
102+
});
103+
104+
// Clear bits for J since we do it at the end
105+
remainingMask &= ~fieldMask(W.J.s, W.J.e);
106+
107+
const pieces = [];
108+
const [ad, ada, adb, ar, arx] = 'AD,ADA,ADB,AR,ARX'.split(/,/).map(f => W[f].get());
109+
110+
if (ad || ada || adb ||
111+
ar === W.AR.AD || ar === W.AR['AD*2'] || ar === W.AR['AD*.25'] ||
112+
arx === W.ARX.AD || arx === W.ARX['ADX*2'] || arx === W.ARX.ADX || arx === W.ARX['ADX*.25'])
113+
{
114+
pieces.push(`AD/${maybeSymbolic(W.AD)}`);
115+
116+
pieces.push(`ADA/${maybeSymbolic(W.ADA)}`);
117+
pieces.push(`ADB/${maybeSymbolic(W.ADB)}`);
118+
if (ar) pieces.push(`AR/${maybeSymbolic(W.AR)}`);
119+
if (arx) pieces.push(`ARX/${maybeSymbolic(W.ARX)}`);
120+
}
121+
122+
// Save the best for last
123+
pieces.push(`J/${octal(W.J.get())}`);
90124

91-
console.log(`U ${octal(a)}: ${wSplit} ${dis}`);
125+
console.log(`U ${octal(a)}: ${wSplit} ${pieces.join(', ')}`);
92126
}
93127

94128

95129
function main() {
96-
const [ramA, ramB] = ['kl10-source/eboxa.ram', 'kl10-source/eboxa.ram']
130+
const [klx, ramA, ramB] = ['kl10-source/klx.ram', 'kl10-source/eboxa.ram', 'kl10-source/eboxa.ram']
97131
.map(fileName => decodeLines(fs.readFileSync(fileName)
98132
.toString()
99133
.split(/\n/)));
100134

101-
ramA.forEach((w, a) => disassembleCRAMWord(w, a));
135+
klx.forEach((w, a) => disassembleCRAMWord(w, a));
102136
}
103137

104138

0 commit comments

Comments
 (0)