Skip to content

Commit da922b7

Browse files
Merge pull request #6 from scopeInfinity/rom
Define boot sequence
2 parents cf568fb + 2b2dd1f commit da922b7

15 files changed

+800
-646
lines changed

README.md

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,28 @@ The eventual goal(?) is to build a general-purpose processor integrated with sim
1212
* Generate resolved assembly: `python3 -m planner asm -r programs/ping_pong.asm` [[example](output/programs/ping_pong_resolved.asm)]
1313
* Generate binary: `python3 -m planner asm -b programs/ping_pong.asm` [[example](output/programs/ping_pong.bin)]
1414
* Run on emulator: `python3 -m planner compile_and_execute ping_pong`
15+
* 16x8 LED display with W/S/Up/Down keyboard controller
16+
* ![image](https://github.com/user-attachments/assets/9fa2f68f-73ae-465c-a29c-cc92b0dc421a)
1517

1618
## Design
1719

18-
This section is not up-to date.
19-
2020
### Specs
2121

22-
* Address Line: 16-bits
22+
* Memory Address Line: 16-bits (points to a byte)
23+
* Memory Value Line: 32-bits (4 bytes)
2324
* Max Memory: 64KB
24-
25-
### Constants
26-
27-
* INSZ = 0x20, independent input bytes
28-
* OUTSZ = 0x20, independent output bytes
29-
* IPC = 0x0100, intial value of `PC` (or Program Counter).
30-
31-
### Memory Allocation
32-
33-
* `RAM[0:INSZ]` is mapped to I/O module input
34-
* `RAM[INSZ:OUTSZ]` is mapped to I/O module output
35-
* `RAM[IPC:IPC+x]` is loaded from ROM. So it essentially contains `.text`, `.data`.
36-
37-
### Sequencing
38-
39-
40-
* At boot
41-
* Load `ROM[0:x]` into `RAM[IPC:IPC+x]`
42-
* TODO: How?
43-
44-
### Assembly
45-
46-
* `.bss` must be the last section.
47-
* Registers don't really exists. `R[0-7]` are mapped to memory location in `.bss` for convenience and some instructions return response.
48-
49-
### Architecture
50-
51-
#### I/O
52-
53-
Hardware interact asynchronously with IOM (I/O Module) which then interact with RAM at program's will. (WE ARE NOT DOING IT)
54-
55-
* Input devices publish state change in IOM and Output devices read from IOM.
56-
* Program use `IN <index>` instructions to read from `IOM_in[index]` and write to `RAM[index]`. `IOM_in` won't cache input and it will be read as real-time value. If a input state needs to be cached, it's the input device responsibility.
57-
* Program use `OUT <index>` instructions to read `RAM[INSZ+index]` and write to `IOM_out[index]`.
58-
59-
60-
61-
# TODO
62-
63-
## Processor
64-
65-
* Address bits: 8
66-
* Register size: 8
67-
* Memory size: 2**8 = 256 bytes
68-
69-
### Idea
70-
71-
To keep number of component small, we would split a single instruction execution period into 4 cycles.
72-
73-
* Reset
74-
* Set `PC = 0`
75-
* sub-cycle clock to cycle-0
76-
* Cycle 0
77-
* Fetch instruction from `ROM[$PC]` into `pin_INS`
78-
* Cycle 1
79-
* Perform first read
80-
81-
## Assembler
82-
83-
### Details
84-
85-
* Registers: R0, R1, R2, R3 or `R{NUM}`
86-
87-
* Input/Output pin: IO0, IO1, ..., IO7 or `IO{NUM}` (8-bits)
88-
89-
### Instructions
90-
91-
* `IN R{NUM}`: short-blocking input with 8-bit response.
92-
* `OUT R{NUM}`: short-blocking 8-bit output.
93-
94-
## Syntax: High Level
95-
96-
Not yet defined.
25+
* Memory layout: [here](planner/memory.py)
26+
27+
#### Boot Sequence
28+
* `programs/boot_sequence.asm` binary (aka `BROM`) is mapped from address_line `BOOTSEQUENCE_LOAD = 0x30`
29+
* Memory Read
30+
* If `BOOTSEQUENCE_ORG <= address_line < DEFAULT_PROGRAM_ORG`, pulls value from `BROM`
31+
* Otherwise, pulls the value from `RAM`
32+
* Execution starts with `PC` at `BOOTSEQUENCE_ORG = 0x34`
33+
* `BROM` goal is to copy `PROM` to RAM at `DEFAULT_PROGRAM_ORG = 0x80`
34+
* Followed by `jmp DEFAULT_PROGRAM_ORG`
35+
36+
#### PROM
37+
* Programs like `programs/ping_pong.asm` are translated into binary and are referred to as `PROM`.
38+
* `PROM` is connected to <chipset> as input-output device.
39+
* The equivalent program is loaded in RAM at `DEFAULT_PROGRAM_ORG = 0x80`, followed by execution after boot sequence.

output/programs/3_led_switch.bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
00000000 00000000 00000000 00001100
1+
00001100 00000000 00000000 00000000
22
00100100 00000010 00000100 00000101
33
00000100 00000100 00000110 00000100
44
00110101 00001001 01000000 00000000

output/programs/boot_sequence.bin

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
00000000 00000000 00000000 00111100
1+
01000000 00000000 00000000 00000000
22
00110100 00000010 00000000 00000000
3-
00000100 00000100 00010000 00000000
4-
00100100 00000010 00000000 00000000
5-
00110100 00000010 00010100 00000000
6-
00110100 00000010 00000100 00000001
7-
00110100 00000010 00001000 01000000
8-
00000100 00000100 00010000 00000100
9-
00100100 00000010 00001100 00100000
3+
00000100 00000100 00000010 00000000
4+
00100100 00000010 00000000 00000010
5+
01110011 00000010 00000000 00000010
6+
00110100 00000010 00000100 00000100
7+
00110100 00000010 00001000 10000000
8+
01110001 00000000 00000000 00000000
9+
00110101 00001011 01110000 00000000
10+
00000100 00000100 00000010 00000100
11+
00100100 00000010 00001100 00000010
1012
01000100 00000110 00001000 00001100
1113
01110000 00000010 00001000 00000100
1214
01110000 00000010 00000100 00000100
13-
01110001 00000010 00000000 00000100
14-
01000001 00000000 00000000 00010100
15-
00110101 00001011 01000000 00000000
16-
00110101 00001001 10011000 00000000
15+
01110001 00000010 00000000 00000001
16+
00110101 00001001 01001100 00000000
17+
00110101 00001001 10000000 00000000
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
PROGRAM_ORG equ 128
2-
080: MOVC [0], 0
3-
084: OUT 16, [0]
4-
088: IN [0], 0
5-
08c: MOVC [20], 0
6-
090: MOVC [4], 1
7-
094: MOVC [8], 64
8-
098: OUT 16, [4]
9-
09c: IN [12], 32
10-
0a0: STORE [[8]], [12]
11-
0a4: ADDC [8], 4
12-
0a8: ADDC [4], 4
13-
0ac: SUBC [0], 4
14-
0b0: CMP [0], [20]
15-
0b4: JZ 64, 0
16-
0b8: JMP 152, 0
1+
PROGRAM_ORG equ 52
2+
034: MOVC [0], 0
3+
038: OUT 2, [0]
4+
03c: IN [0], 2
5+
040: SHRC [0], 2
6+
044: MOVC [4], 4
7+
048: MOVC [8], 128
8+
04c: CMPC [0], 0
9+
050: JZ 112, 0
10+
054: OUT 2, [4]
11+
058: IN [12], 2
12+
05c: STORE [[8]], [12]
13+
060: ADDC [8], 4
14+
064: ADDC [4], 4
15+
068: SUBC [0], 1
16+
06c: JMP 76, 0
17+
070: JMP 128, 0

0 commit comments

Comments
 (0)