aboutsummaryrefslogtreecommitdiff
path: root/assembler
diff options
context:
space:
mode:
Diffstat (limited to 'assembler')
-rw-r--r--assembler/Makefile45
-rw-r--r--assembler/assemble.s2
-rw-r--r--assembler/main.s33
-rw-r--r--assembler/pico_bin.ld (renamed from assembler/pico_ram_only.ld)4
-rw-r--r--assembler/slowcat.c11
-rw-r--r--assembler/uart.s86
6 files changed, 123 insertions, 58 deletions
diff --git a/assembler/Makefile b/assembler/Makefile
index 0225069..45988ba 100644
--- a/assembler/Makefile
+++ b/assembler/Makefile
@@ -1,29 +1,38 @@
-PICO = /dev/disk/by-label/RPI-RP2
+DEVICE = /dev/ttyUSB0
-assemble.uf2: assemble.elf
- ../elf/elf2uf2 assemble.elf assemble.uf2
+.PHONY: build
+build: assemble.he
+
+assemble.he: assemble.bin
+ od -An -tx2 -v assemble.bin | sed "s/^ //" | tr " " "\n" | tr [:lower:] [:upper:] | sed "s/^/0x/" > assemble.he
+
+assemble.bin: assemble.elf
+ arm-none-eabi-objcopy -O binary assemble.elf assemble.bin
objects = main.o uart.o assemble.o register.o octal.o opcode.o
-assemble.elf: $(objects)
- arm-none-eabi-ld -T pico_ram_only.ld -o assemble.elf $(objects) ../setup/setup.so
+assemble.elf: pico_bin.ld $(objects)
+ arm-none-eabi-ld -T pico_bin.ld -o assemble.elf $(objects)
$(objects): %.o: %.s
arm-none-eabi-as -o $@ $<
.PHONY: clean
clean:
- rm assemble.elf assemble.uf2 *.o
-
-.PHONY: flash
-flash: $(PICO) assemble.uf2
- cat assemble.uf2 > $(PICO)
-
-.PHONY: check
-check: $(PICO)
- @echo Ready to flash
-
-$(PICO):
- @echo "RPI-RP2 bootloader drive not found"
- @echo Connect the pico with USB cable while holding bootsel button
+ rm assemble.elf assemble.bin assemble.he *.o slowcat
+
+.PHONY: dump
+dump: assemble.bin
+ @od -Ax -tx2 -v assemble.bin
+
+.PHONY: serial
+serial: $(DEVICE) assemble.he slowcat
+ cat assemble.he | tr "\n" "\r" | ./slowcat | picocom -b 115200 -q $(DEVICE)
+ @echo
+ echo -n "G" | picocom -b 115200 -q $(DEVICE)
+ @echo
+
+$(DEVICE):
+ @echo Serial device not found
+ @echo Connect USB cable from USB-UART bridge
@false
diff --git a/assembler/assemble.s b/assembler/assemble.s
index 9f5c022..704b7cf 100644
--- a/assembler/assemble.s
+++ b/assembler/assemble.s
@@ -9,7 +9,6 @@
// - make subroutine addresses explicit
// - test each instruction
// - decide on additional push or pops
-// - add GO to get_char
assemble: PUSH {LR}
LDR R0, =uart_send
@@ -72,4 +71,5 @@ done_stuff: MOV R0, R8 // copy the end_char into R0
BLX R9 // echo the space (or carriage return)
here: LSRS R7, 0x8 // get next parse instruction
BNE main_loop // if it's nonzero there are more things to parse
+ MOVS R0, 0
POP {PC}
diff --git a/assembler/main.s b/assembler/main.s
index 1795823..a9fd109 100644
--- a/assembler/main.s
+++ b/assembler/main.s
@@ -5,22 +5,31 @@
.type main, %function
.global main
-main:
- bl start_xosc
- bl setup_clocks
- bl setup_gpio
- bl setup_uart
- b assembler
-
-assembler: LDR R0, =0x20001000 // SRAM_BASE
- MOV R11, R0
+main: LDR R0, =0x20000000 // SRAM_BASE
+0: MOV R11, R0
ADDS R1, R0, 1 // JUMP ADDRESS
MOV R12, R1
1: BL PROMPT // SHOW PROMPT
BL assemble
- B 2f // TODO condition
+ CMP R0, 1 // SET NEW ADDRESS
+ BNE 2f
+ MOVS R0, '\r // SEND CR
+ BL uart_send
+ MOV R1, R11 // GET ADDRESS
+ LSRS R1, 16 // SHIFT OUT LOWER HALFWORD
+ MOVS R0, R1 // SAVE IN R0
+ LSLS R1, 16 // SHIFT BACK
+ MOV R11, R1 // SAVE ALTERRED ADDRESS
+ MOVS R1, 4 // SEND HEX WITH WIDTH 4
+ BL send_hex
+ BL get_hex // GET HEX INPUT FOR OFFSET
+ MOV R0, R11 // ADD OFFSET TO ADDRESS
+ ADDS R0, R4
+ B 0b
+2: CMP R0, 2 // JUMP TO NEW CODE
+ BNE 3f
BX R12
-2: MOV R7, R11 // STORE INSTRUCTION WORD
+3: MOV R7, R11 // STORE INSTRUCTION WORD
STRH R6, [R7]
MOVS R0, '\r // NEW LINE
BL uart_send
@@ -35,11 +44,13 @@ assembler: LDR R0, =0x20001000 // SRAM_BASE
PROMPT: PUSH {LR}
MOV R0, R11 // CURRENT ADDRESS
+ MOVS R1, 8
BL send_hex
MOVS R0, ' // SPACE
BL uart_send
MOV R1, R11 // CURRENT CONTENTS
LDRH R0, [R1]
+ MOVS R1, 4
BL send_hex
MOVS R0, ' // SPACE
BL uart_send
diff --git a/assembler/pico_ram_only.ld b/assembler/pico_bin.ld
index eb2450e..3059501 100644
--- a/assembler/pico_ram_only.ld
+++ b/assembler/pico_bin.ld
@@ -2,12 +2,12 @@ ENTRY(main)
MEMORY {
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2M
- SRAM(rwx) : ORIGIN = 0x20000000, LENGTH = 264K
+ SRAM(rwx) : ORIGIN = 0x20001000, LENGTH = 260K
}
SECTIONS {
.text : {
- *(.text)
+ *(.text);
. = ALIGN(4);
} > SRAM
}
diff --git a/assembler/slowcat.c b/assembler/slowcat.c
new file mode 100644
index 0000000..99493ae
--- /dev/null
+++ b/assembler/slowcat.c
@@ -0,0 +1,11 @@
+#include <unistd.h>
+#include <stdint.h>
+
+int main() {
+ uint8_t byte;
+ while (read(STDIN_FILENO, &byte, 1)) {
+ write(STDOUT_FILENO, &byte, 1);
+ usleep(1000);
+ }
+ return 0;
+}
diff --git a/assembler/uart.s b/assembler/uart.s
index e1f5e8b..5712268 100644
--- a/assembler/uart.s
+++ b/assembler/uart.s
@@ -10,11 +10,13 @@
.type uart_recv, %function
.type get_char, %function
.type send_hex, %function
+.type get_hex, %function
.global uart_send
.global uart_recv
.global get_char
.global send_hex
+.global get_hex
uart_send: LDR R1, =UART0_BASE // 0x0000 0x4917
MOVS R3, 0b1 << 5 // 0x0002 0x2320 ; TX FIFO FULL
@@ -33,30 +35,62 @@ uart_recv: LDR R1, =UART0_BASE // 0x000E 0x4914
get_char: PUSH {LR} // 0x001C 0xB500
BL uart_recv // 0x001E 0xF7FF
// 0x0020 0xFFF6
- CMP R0, R8 // 0x0022 0x4540
+ CMP R0, '<
+ BNE 1f
+ MOVS R0, 1
+ B 2f
+1: CMP R0, '>
+ BNE 3f
+ MOVS R0, 2
+2: POP {R1}
+ POP {R1}
+3: CMP R0, R8 // 0x0022 0x4540
POP {PC} // 0x0024 0xBD00
-send_hex: PUSH {LR} // 0x0026 0xB500
- LSLS R4, R0, 16 // 0x0028 0x
- MOVS R0, '0 // 0x002A 0x2030
- BL uart_send // 0x002C 0xF7FF
- // 0x002E 0xFFE8
- MOVS R0, 'x // 0x0030 0x2078
- BL uart_send // 0x0032 0xF7FF
- // 0x0034 0xFFE5
- MOVS R5, 4 // 0x0036 0x2504 ; FOUR NIBBLES TO PRINT
-0: MOVS R0, 28 // 0x0038 0x201C ; ROTATE LEFT 4
- RORS R4, R0 // 0x003A 0x41C4
- MOVS R0, 0xF // 0x003C 0x200F ; LOWEST NIBBLE MASK
- ANDS R0, R4 // 0x003E 0x4020
- CMP R0, 0x9 // 0x0040 0x0000 ; NUMBER OR LETTER?
- BHI 1f // 0x0042 0xD801
- ADDS R0, '0 // 0x0044 0x3030
- B 2f // 0x0046 0xE000
-1: ADDS R0, ('A - 0xA) // 0x0048 0x3037
-2: BL uart_send // 0x004A 0xF7FF
- // 0x004C 0xFFD9
- SUBS R5, 1 // 0x004E 0x3D01
- BNE 0b // 0x0050 0xD1F2
- POP {PC} // 0x0052 0xBD00
- // 0x0054 0x4000 ; UART0_BASE
- // 0x0056 0x4003
+send_hex: PUSH {LR} // 000350 132400 B500
+ MOVS R4, R0 // 000352 000004 0004
+ MOVS R5, R1 // 000354 000015 000D
+ LSLS R1, 0x2 // 000356 000211 0049
+ RORS R4, R1 // 000360 040714 41CC
+ MOVS R0, 0x30 // 000362 020060 2030 ASCII 0
+ BL uart_send // 000364 043710 UARTTX
+ MOVS R0, 0x78 // 000366 020170 ASCII x
+ BL uart_send // 000370 043710 UARTTX
+0: MOVS R0, 0x1C // 000372 020034
+ RORS R4, R0 // 000374 040704
+ MOVS R0, 0x0F // 000376 020017
+ ANDS R0, R4 // 000400 040040
+ CMP R0, 0x9 // 000402 024011
+ BHI 1f // 000404 154001
+ ADDS R0, 0x30 // 000406 030060 ASCII 0
+ B 2f // 000410 160000
+1: ADDS R0, 0x37 // 000412 030067 ASCII A MINUS 10
+2: BL uart_send // 000414 043710 UARTTX
+ SUBS R5, 1 // 000416 036401
+ BNE 0b // 000420 150763
+ POP {PC} // 000422 136400
+get_hex: PUSH {LR} // 000224 132400
+ MOVS R4, 0x0 // 000226 022000
+ MOVS R5, 0x4 // 000230 022404
+10: BL uart_recv // 000232 043700 HEX LOOP, UARTRX
+ CMP R0, 0x30 // 000234 024060 ASCII 0
+ BLO 10b // 000236 151774
+ CMP R0, 0x39 // 000240 024071 ASCII 9
+ BLS 20f // 000242 154406
+ CMP R0, 0x41 // 000244 024101 ASCII A
+ BLO 10b // 000246 151770
+ CMP R0, 0x46 // 000250 024106 ASCII F
+ BHI 10b // 000252 154366
+ BL uart_send // 000254 043710 UARTTX
+ SUBS R0, 0x37 // 000256 034067 ASCII A MINUS 10
+ B 30f // 000260 160001
+20: BL uart_send // 000262 043710 UARTTX
+ SUBS R0, 0x30 // 000264 034060 ASCII 0
+30: LSLS R4, 0x4 // 000266 000444
+ ADDS R4, R0 // 000270 014044
+ SUBS R5, 0x1 // 000272 036401
+ BNE 10b // 000274 150755
+40: BL uart_recv // 000276 043700 UARTRX
+ CMP R0, '\r // 000300 024015 CARRIAGE RETURN
+ BNE 40b // 000302 150774
+ BL uart_send // 000304 043710 UARTTX
+ POP {PC} // 000306 136400