Skip to content

Commit 40d763d

Browse files
fixes, added hex documentation and firmware dump
1 parent 7eed46a commit 40d763d

22 files changed

+16523
-151
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ MANIFEST
88
PySimAvr/Core/parser.out
99
PySimAvr/Core/parsetab.py
1010
doc/sphinx/build/
11+
#
12+
data/blink-led/.build_ano/
13+
data/blink-led/asm/
14+
data/blink-led/ino-env
15+
data/blink-led/make-asm
16+
data/blink-led/make.log
17+
data/blink-led/sketch/
18+
data/blink-led/trash/

PySimAvr/Avr/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
#
1919
####################################################################################################
2020

21+
"""Load AVR Instruction Set from YAML file.
22+
"""
23+
24+
# Fixme:
25+
# and: & ∧ •
26+
# or: | ∨ +
27+
# xor: ^ ⊻ ⊗
28+
# not: ! ¬
29+
2130
####################################################################################################
2231

2332
__all__ = ['instruction_set']

PySimAvr/Avr/opcodes.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ BRCC:
122122
description: Branch if Carry Cleared
123123
alias_of: BRBC
124124
alias_substitution: s = 0
125-
125+
126126
BRCS:
127127
description: Branch if Carry Set
128128
alias_of: BRBS
@@ -325,8 +325,8 @@ CLZ:
325325
alias_substitution: s = 1
326326

327327
COM:
328-
description: One's Complement
329-
alternate: One\u2019s Complement
328+
description: One s Complement
329+
alternate: One s Complement
330330
operations:
331331
-
332332
opcode: 1001 010d dddd 0000
@@ -679,8 +679,8 @@ MULSU:
679679
cycles: 2
680680

681681
NEG:
682-
description: Two's Complement
683-
alternate: Two\u2019s Complement
682+
description: Two s Complement
683+
alternate: Two s Complement
684684
operations:
685685
-
686686
opcode: 1001 010d dddd 0001
@@ -789,7 +789,7 @@ ROL:
789789
alternate: Rotate Left Through Carry
790790
alias_of: ADC
791791
alias_substitution: Rr = Rd
792-
792+
793793
ROR:
794794
description: Rotate Right through Carry
795795
alternate: Rotate Right Through Carry

PySimAvr/BinaryFormat/HexFile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#
1919
####################################################################################################
2020

21+
"""Read Intel HEX file format
22+
23+
See https://en.wikipedia.org/wiki/Intel_HEX
24+
"""
25+
2126
####################################################################################################
2227

2328
import logging
@@ -34,7 +39,7 @@
3439

3540
####################################################################################################
3641

37-
class HexFile(object):
42+
class HexFile:
3843

3944
_logger = _module_logger.getChild('Hex')
4045

PySimAvr/Core/CoreHdlParser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,12 @@ def t_DECIMAL_NUMBER(self, t):
204204
)
205205

206206
def p_error(self, p):
207-
self._logger.error("Syntax error at '%s'", p.value)
208-
raise NameError('Parser error')
207+
if p:
208+
self._logger.error("Syntax error at '%s'", p.value)
209+
raise NameError('Syntax Error')
210+
else:
211+
self._logger.error("Syntax Error at End Of File")
212+
raise NameError("Syntax Error at End Of File" )
209213

210214
start = 'program'
211215

bin/read-firmwares.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,31 @@
2020
#
2121
####################################################################################################
2222

23-
# Fixme:
23+
"""Read a firmware in Intel HEX format and dump disassembled instructions.
24+
25+
How to disassemble using GNU Binutils::
26+
27+
avr-objdump -D --prefix-addresses firmware.elf
28+
avr-objdump -d -j .sec1 -m avr6 firmware.hex
29+
"""
30+
31+
####################################################################################################
32+
33+
# Fixme: End of program issue
34+
#
2435
# 0x066E: 0xCFFF
2536
# RJMP 1100 kkkk kkkk kkkk
2637
# {'k': 4095}
2738
# 0x0670: 0x000D
2839
# Illegal instruction
40+
#
41+
# objdump output is:
42+
#
43+
# 66a: f8 94 cli
44+
# 66c: ff cf rjmp .-2 ; 0x66c
45+
# 66e: 0d 00 .word 0x000d ; ????
46+
47+
# Fixme: What is this word ???
2948

3049
####################################################################################################
3150

@@ -35,7 +54,11 @@
3554

3655
####################################################################################################
3756

57+
# Fixme: use argparse ...
3858
path = 'data/blink-led-mega2560-firmware.hex'
59+
60+
####################################################################################################
61+
3962
hex_file = HexFile(path)
4063

4164
decision_tree = instruction_set.decision_tree
@@ -58,5 +81,3 @@
5881
print(' ', opcode.decode(bytecode))
5982
except DecodeError:
6083
print(" Illegal instruction")
61-
62-
# avr-objdump -D --prefix-addresses firmware.elf

bin/test-core-hdl-parser.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,10 @@
2020
#
2121
####################################################################################################
2222

23-
# Fixme: <- is not implemented in parser ???
24-
#
25-
# Generating LALR tables
26-
# WARNING: 7 shift/reduce conflicts
27-
#
28-
# ================================================================================
29-
# 1 : C <- 0
30-
# 2017-05-21 14:31:19,562 - PySimAvr.Core.CoreHdlParser.Parser - CoreHdlParser.p_error - ERROR - Syntax error at '<'
31-
# Traceback (most recent call last):
32-
# File "bin/test-core-hdl-parser.py", line 50, in <module>
33-
# program = parser.parse(line)
34-
# File "/home/fabrice/home/developpement/PySimAvr/PySimAvr/Core/CoreHdlParser.py", line 417, in parse
35-
# self._parser.parse(text, lexer=self._lexer)
36-
# File "/opt/python-virtual-env/py35/lib/python3.5/site-packages/ply/yacc.py", line 331, in parse
37-
# return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
38-
# File "/opt/python-virtual-env/py35/lib/python3.5/site-packages/ply/yacc.py", line 1199, in parseopt_notrack
39-
# tok = call_errorfunc(self.errorfunc, errtoken, self)
40-
# File "/opt/python-virtual-env/py35/lib/python3.5/site-packages/ply/yacc.py", line 193, in call_errorfunc
41-
# r = errorfunc(token)
42-
# File "/home/fabrice/home/developpement/PySimAvr/PySimAvr/Core/CoreHdlParser.py", line 208, in p_error
43-
# raise NameError('Parser error')
44-
# NameError: Parser error
23+
"""Test the HDL parser for instruction operations.
24+
"""
25+
26+
# Fixme: Some operations are supported !!!
4527

4628
####################################################################################################
4729
#
@@ -70,6 +52,9 @@
7052
print(line_number, ':', line)
7153
# print()
7254
# parser.test_lexer(line)
73-
program = parser.parse(line)
55+
# try:
56+
program = parser.parse(line + ';')
7457
print()
7558
print(program)
59+
# except:
60+
# print("Parse error")

bin/test-core.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,20 @@
104104
R2 = 4;
105105
Y = 23;
106106
'''
107+
108+
109+
rule = '\n' + '-'*100 + '\n'
110+
107111
print(source)
112+
108113
# micro_code_parser.test_lexer(source)
114+
109115
ast_program = micro_code_parser.parse(source)
116+
110117
# print()
111118
# print(ast_program)
112-
print()
119+
120+
print(rule)
113121
core.run_ast_program(ast_program)
114122

115123
print(ram[:10])

bin/test-hex-file.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

bin/test-instruction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#
1919
####################################################################################################
2020

21+
"""Test the bytecode decoder.
22+
"""
23+
2124
####################################################################################################
2225

2326
from PySimAvr.Avr import instruction_set
@@ -137,6 +140,8 @@
137140
# Bytecode Interval (but code is wrong)
138141
#
139142

143+
# Fixme: what means (but code is wrong) ???
144+
140145
if True:
141146
bytecode_interval_pool = []
142147
for instruction in instruction_set.iter_on_instructions():

0 commit comments

Comments
 (0)