diff options
author | Jacques Comeaux <jacquesrcomeaux@protonmail.com> | 2024-05-20 23:19:14 -0500 |
---|---|---|
committer | Jacques Comeaux <jacquesrcomeaux@protonmail.com> | 2024-05-20 23:19:14 -0500 |
commit | 7388c270069c2d1418539bca1d2789a6d468ecc2 (patch) | |
tree | d3848031f6c2d4d45ec0a7c75b12a9f476680726 /assembler | |
parent | 7f47fc894d43739fb0107fd17e76f65ae2bf46bc (diff) |
Make shared object for setup routines
Diffstat (limited to 'assembler')
-rw-r--r-- | assembler/Makefile | 21 | ||||
-rw-r--r-- | assembler/main.s | 17 | ||||
-rw-r--r-- | assembler/pico_ram_only.ld | 13 | ||||
-rw-r--r-- | assembler/uart.s | 65 |
4 files changed, 116 insertions, 0 deletions
diff --git a/assembler/Makefile b/assembler/Makefile new file mode 100644 index 0000000..96b7971 --- /dev/null +++ b/assembler/Makefile @@ -0,0 +1,21 @@ +all: build + +build: assemble.uf2 + +assemble.uf2: assemble.elf + ../elf/elf2uf2 assemble.elf assemble.uf2 + +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 + +$(objects): %.o: %.s + arm-none-eabi-as -o $@ $< + +clean: + rm assemble.elf assemble.uf2 *.o + +flash: assemble.uf2 + [ -h /dev/disk/by-label/RPI-RP2 ] || sleep 2s + cat assemble.uf2 > /dev/disk/by-label/RPI-RP2 diff --git a/assembler/main.s b/assembler/main.s new file mode 100644 index 0000000..9a7fd89 --- /dev/null +++ b/assembler/main.s @@ -0,0 +1,17 @@ +.syntax unified +.cpu cortex-m0plus +.thumb + +.type main, %function +.global main + +main: + bl start_xosc + bl setup_clocks + bl setup_gpio + bl setup_uart +1: + bl assemble + movs r0, r6 + bl send_hex + b 1b diff --git a/assembler/pico_ram_only.ld b/assembler/pico_ram_only.ld new file mode 100644 index 0000000..eb2450e --- /dev/null +++ b/assembler/pico_ram_only.ld @@ -0,0 +1,13 @@ +ENTRY(main) + +MEMORY { + FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2M + SRAM(rwx) : ORIGIN = 0x20000000, LENGTH = 264K +} + +SECTIONS { + .text : { + *(.text) + . = ALIGN(4); + } > SRAM +} diff --git a/assembler/uart.s b/assembler/uart.s new file mode 100644 index 0000000..b845c8b --- /dev/null +++ b/assembler/uart.s @@ -0,0 +1,65 @@ +.syntax unified +.cpu cortex-m0plus +.thumb + +.equ UART0_BASE, 0x40034000 +.equ UARTDR_OFST, 0x00 +.equ UARTFR_OFST, 0x18 + +.type uart_send, %function +.global uart_send + +uart_send: + ldr r1, =UART0_BASE + movs r3, 0b1 << 5 // TX FIFO full +1: + ldr r2, [r1, UARTFR_OFST] + tst r2, r3 + bne 1b + strb r0, [r1, UARTDR_OFST] + bx lr + +.type uart_recv, %function +.global uart_recv + +uart_recv: + ldr r1, =UART0_BASE + movs r3, 0b1 << 4 // RX FIFO empty +1: + ldr r2, [r1, UARTFR_OFST] + tst r2, r3 + bne 1b + ldrb r0, [r1, UARTDR_OFST] + bx lr + +.type send_hex, %function +.global send_hex + +send_hex: + push {lr} + movs r4, r0 + movs r0, '0 + bl uart_send + movs r0, 'x + bl uart_send + movs r5, 8 // eight nibbles in a word +0: + movs r0, 28 // rotate left 4 + rors r4, r0 + movs r0, 0xF // lowest nibble mask + ands r0, r4 + cmp r0, 0x9 // number or letter? + bhi 1f + adds r0, '0 + b 2f +1: + adds r0, ('A - 0xA) +2: + bl uart_send + subs r5, 1 + bne 0b + movs r0, '\r + bl uart_send + movs r0, '\n + bl uart_send + pop {pc} |