Selaa lähdekoodia

Fix 2 bugs, one as a result of missing registers in the register map and another where main memory would not be cleared on each bootload

Matt Coles 9 vuotta sitten
vanhempi
commit
e31b654f63
4 muutettua tiedostoa jossa 37 lisäystä ja 30 poistoa
  1. 29 26
      index.js
  2. 4 1
      js/bootload.js
  3. 1 1
      js/encoders.js
  4. 3 2
      memory/memory.js

+ 29 - 26
index.js

20
   'parse': parse
20
   'parse': parse
21
 }
21
 }
22
 
22
 
23
-},{"./encoders.js":3}],2:[function(require,module,exports){
23
+},{"./encoders.js":4}],2:[function(require,module,exports){
24
 // put some stuff into memory
24
 // put some stuff into memory
25
 const memory = require('../memory/memory.js')
25
 const memory = require('../memory/memory.js')
26
 const utils = require('./utils.js')
26
 const utils = require('./utils.js')
32
 const incrAddr = (addr, n) => padAddress((parseInt(addr, 2) + n).toString(2), 32, '0')
32
 const incrAddr = (addr, n) => padAddress((parseInt(addr, 2) + n).toString(2), 32, '0')
33
 
33
 
34
 const baseAddr = '0xbfc00000'
34
 const baseAddr = '0xbfc00000'
35
-const loadBootCode = (code) => code.map((c, i) => memory.storeWord(incrAddr(utils.hex2bin(baseAddr, 32), i*4), utils.hex2bin(c, 32)))
35
+const loadBootCode = (code) => {
36
+  memory.clearMemory()
37
+  code.map((c, i) => memory.storeWord(incrAddr(utils.hex2bin(baseAddr, 32), i*4), utils.hex2bin(c, 32)))
38
+}
36
 
39
 
37
 module.exports = {
40
 module.exports = {
38
   'loadBootCode': loadBootCode
41
   'loadBootCode': loadBootCode
39
 }
42
 }
40
 
43
 
41
 },{"../memory/memory.js":6,"./utils.js":5}],3:[function(require,module,exports){
44
 },{"../memory/memory.js":6,"./utils.js":5}],3:[function(require,module,exports){
45
+// This file should hold the DOM interaction code
46
+let hex = ''
47
+const assembler = require('./assembler.js')
48
+const bootloader = require('./bootload.js')
49
+
50
+const assembleButton = document.getElementById('assemble')
51
+const assembleButtonHandler = event => {
52
+  const code = document.getElementById('code')
53
+  const rawCode = code.value
54
+  hex = assembler.parse(assembler.lines(rawCode))
55
+  bootloader.loadBootCode(hex)
56
+  console.log(hex.join('\n'))
57
+}
58
+  
59
+
60
+assembleButton.addEventListener('click', assembleButtonHandler)
61
+
62
+},{"./assembler.js":1,"./bootload.js":2}],4:[function(require,module,exports){
42
 const utils = require('./utils.js')
63
 const utils = require('./utils.js')
43
 
64
 
44
 const regmap = [
65
 const regmap = [
45
-  'zero', 'at', 'v0', 'v1', 'a0', 'a1', 'a2', 't0', 't1', 't2', 't3', 't4', 't5',
66
+  'zero', 'at', 'v0', 'v1', 'a0', 'a1', 'a2', 'a3', 't0', 't1', 't2', 't3', 't4', 't5',
46
   't6', 't7', 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 't8', 't9', 'k0',
67
   't6', 't7', 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 't8', 't9', 'k0',
47
   'k1', 'gp', 'sp', 's8', 'ra' ]
68
   'k1', 'gp', 'sp', 's8', 'ra' ]
48
 
69
 
82
 
103
 
83
 module.exports = encoders
104
 module.exports = encoders
84
 
105
 
85
-},{"./utils.js":5}],4:[function(require,module,exports){
86
-// This file should hold the DOM interaction code
87
-let hex = ''
88
-const assembler = require('./assembler.js')
89
-const bootloader = require('./bootload.js')
90
-
91
-const assembleButton = document.getElementById('assemble')
92
-const assembleButtonHandler = event => {
93
-  const code = document.getElementById('code')
94
-  const rawCode = code.value
95
-  hex = assembler.parse(assembler.lines(rawCode))
96
-  bootloader.loadBootCode(hex)
97
-  console.log(hex.join('\n'))
98
-}
99
-  
100
-
101
-assembleButton.addEventListener('click', assembleButtonHandler)
102
-
103
-},{"./assembler.js":1,"./bootload.js":2}],5:[function(require,module,exports){
106
+},{"./utils.js":5}],5:[function(require,module,exports){
104
 const error = (error) => console.error(error)
107
 const error = (error) => console.error(error)
105
 
108
 
106
 const dec2binu = (dec, length) => {
109
 const dec2binu = (dec, length) => {
155
 // will not be filling up the array and therefore will not be using much RAM, however if
158
 // will not be filling up the array and therefore will not be using much RAM, however if
156
 // the full 4gb of memory are used, then it might prove problematic, and I will likely
159
 // the full 4gb of memory are used, then it might prove problematic, and I will likely
157
 // move to a server side memory model that persists most data to disk
160
 // move to a server side memory model that persists most data to disk
158
-const mainMemory = {}
161
+let mainMemory = {}
159
 
162
 
160
 // Pads a string with 0's until it is the desired length
163
 // Pads a string with 0's until it is the desired length
161
 const padAddress = (addr, len, ch) => (addr.length >= len) ? 
164
 const padAddress = (addr, len, ch) => (addr.length >= len) ? 
188
 
191
 
189
 // Stores two bytes in memory array, with the lower bytes in the lower addresses
192
 // Stores two bytes in memory array, with the lower bytes in the lower addresses
190
 const storeHalfWord = (addr, data) => {
193
 const storeHalfWord = (addr, data) => {
191
-  console.log(addr)
192
   if (data.length == 16) {
194
   if (data.length == 16) {
193
     if (addr.slice(-1) === '0') {
195
     if (addr.slice(-1) === '0') {
194
       storeByte(addr, data.slice(8))
196
       storeByte(addr, data.slice(8))
214
   storeHalfWord, storeHalfWord,
216
   storeHalfWord, storeHalfWord,
215
   loadByte: loadByte,
217
   loadByte: loadByte,
216
   loadHalfWord: loadHalfWord,
218
   loadHalfWord: loadHalfWord,
217
-  loadWord: loadWord
219
+  loadWord: loadWord,
220
+  clearMemory: () => mainMemory = {}
218
 }
221
 }
219
 
222
 
220
-},{}]},{},[4]);
223
+},{}]},{},[3]);

+ 4 - 1
js/bootload.js

9
 const incrAddr = (addr, n) => padAddress((parseInt(addr, 2) + n).toString(2), 32, '0')
9
 const incrAddr = (addr, n) => padAddress((parseInt(addr, 2) + n).toString(2), 32, '0')
10
 
10
 
11
 const baseAddr = '0xbfc00000'
11
 const baseAddr = '0xbfc00000'
12
-const loadBootCode = (code) => code.map((c, i) => memory.storeWord(incrAddr(utils.hex2bin(baseAddr, 32), i*4), utils.hex2bin(c, 32)))
12
+const loadBootCode = (code) => {
13
+  memory.clearMemory()
14
+  code.map((c, i) => memory.storeWord(incrAddr(utils.hex2bin(baseAddr, 32), i*4), utils.hex2bin(c, 32)))
15
+}
13
 
16
 
14
 module.exports = {
17
 module.exports = {
15
   'loadBootCode': loadBootCode
18
   'loadBootCode': loadBootCode

+ 1 - 1
js/encoders.js

1
 const utils = require('./utils.js')
1
 const utils = require('./utils.js')
2
 
2
 
3
 const regmap = [
3
 const regmap = [
4
-  'zero', 'at', 'v0', 'v1', 'a0', 'a1', 'a2', 't0', 't1', 't2', 't3', 't4', 't5',
4
+  'zero', 'at', 'v0', 'v1', 'a0', 'a1', 'a2', 'a3', 't0', 't1', 't2', 't3', 't4', 't5',
5
   't6', 't7', 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 't8', 't9', 'k0',
5
   't6', 't7', 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 't8', 't9', 'k0',
6
   'k1', 'gp', 'sp', 's8', 'ra' ]
6
   'k1', 'gp', 'sp', 's8', 'ra' ]
7
 
7
 

+ 3 - 2
memory/memory.js

2
 // will not be filling up the array and therefore will not be using much RAM, however if
2
 // will not be filling up the array and therefore will not be using much RAM, however if
3
 // the full 4gb of memory are used, then it might prove problematic, and I will likely
3
 // the full 4gb of memory are used, then it might prove problematic, and I will likely
4
 // move to a server side memory model that persists most data to disk
4
 // move to a server side memory model that persists most data to disk
5
-const mainMemory = {}
5
+let mainMemory = {}
6
 
6
 
7
 // Pads a string with 0's until it is the desired length
7
 // Pads a string with 0's until it is the desired length
8
 const padAddress = (addr, len, ch) => (addr.length >= len) ? 
8
 const padAddress = (addr, len, ch) => (addr.length >= len) ? 
60
   storeHalfWord, storeHalfWord,
60
   storeHalfWord, storeHalfWord,
61
   loadByte: loadByte,
61
   loadByte: loadByte,
62
   loadHalfWord: loadHalfWord,
62
   loadHalfWord: loadHalfWord,
63
-  loadWord: loadWord
63
+  loadWord: loadWord,
64
+  clearMemory: () => mainMemory = {}
64
 }
65
 }