aboutsummaryrefslogtreecommitdiff
path: root/write_inst_eeprom.py
blob: 224572aaa8791b25bac7a2e961378fb8614dc1df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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()