diff options
| author | Benedict <benedict@0xb8000.de> | 2018-04-16 10:23:49 +0200 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2018-04-26 11:19:01 +0200 |
| commit | a34ee32c743b35170777038a4c3ebbabf5686b43 (patch) | |
| tree | 1df2053d6dd64e64626b542532fa0a42dbbaea18 /write_inst_eeprom.py | |
| parent | 831920937a1541d6c15b357d3e0336c3291d8084 (diff) | |
eeprom: control logic: define instructions layout and write out script
Diffstat (limited to 'write_inst_eeprom.py')
| -rw-r--r-- | write_inst_eeprom.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/write_inst_eeprom.py b/write_inst_eeprom.py new file mode 100644 index 0000000..224572a --- /dev/null +++ b/write_inst_eeprom.py @@ -0,0 +1,98 @@ +## This file writes the in inst.py defined instruction to the AT28C EEPROM +## conntected to a raspberry pi via GPIO pins + +import inst +import eeprom_pi as ep + +## for cmd line args access +import sys + +## given an address and an instruction this writes corredsponding bytes to the +## EEPROM +def write_micro_inst_out(address, instruction): + ctl_word_half = 0x00 + if eeprom_n == 1: + ctl_word_half = instruction & 0xff + elif eeprom_n == 2: + ctl_word_half = (instruction >> 8) & 0xff + + print("%s: %s (%s)" % (hex(address), hex(ctl_word_half), + hex(instruction))) + ep.write_data_at(address, ctl_word_half) + + + +## look for cmd line parameter to known which EEPROM we write to currently +if(len(sys.argv) != 2): + print("usage: %s <number eeprom>" % sys.argv[0]) + print("please specify the eeprom you want to write to.") + exit() + +eeprom_n = int(sys.argv[1]) + +if not (eeprom_n == 1 or eeprom_n == 2): + print("error: only two eeproms supported right now") + exit() + +print("writing eeprom %s" % eeprom_n) + +## setup board +ep.init_board() + + +## for every instruction +nr_inst = 1 +for instruction_data in inst.INST: + print("writing instruction %s" % nr_inst) + base_address = instruction_data[0] + mops = instruction_data[1] + n = 0 + + # write fetch instruction micro ops for every instruction + for fi_mop in inst.INST_MICRO_OP_FETCH_INSTRUCTION: + write_micro_inst_out(base_address+n, fi_mop) + n += 1 + + print("------------") + + for mop in mops: + write_micro_inst_out(base_address+n, mop) + n += 1 + + ## insert 0x00 for not used micro instuctions, so all control signals 0 + ## and the pc is not doing some unwanted stuff + while n < inst.MAX_MICRO_OPS: + write_micro_inst_out(base_address+n, 0x0000) + n += 1 + + + nr_inst += 1 + + +## write a fetch instruction at address 0x0, so that after a reset we are +## fetching the first instruction +print("\n") +print("writing inst fetch instruction at address 0x0, so we begin executing" + "after reset:") +n = 0 +base_address = 0x0 +for fi_mop in inst.INST_MICRO_OP_FETCH_INSTRUCTION: + write_micro_inst_out(base_address+n, fi_mop) + n += 1 + +## write NULLs +while n < inst.MAX_MICRO_OPS: + write_micro_inst_out(base_address+n, 0x0000) + n += 1 + +## write HLT instruction aka, everything 0x00, no new instruction fetch cycle +n = 0 +base_address = inst.INST_HLT +while n < inst.MAX_MICRO_OPS: + write_micro_inst_out(base_address+n, 0x0000) + n += 1 + + +trash = raw_input("please unplug the power to the EEPORM now and press any key to continue...") + +ep.cleanup() |
