From 5bbad5026cb810f61c2466d5c4bf3438ba820842 Mon Sep 17 00:00:00 2001 From: Jacques Comeaux Date: Sun, 26 May 2024 14:21:59 -0500 Subject: Finish hexedit and update README --- README.md | 29 ++++++++++++++++++++++++++--- assembler/assemble.s | 1 - hexedit/Makefile | 18 +++++++++--------- hexedit/hexedit.s | 42 ++++++++++++++++++++++++++---------------- hexedit/main.s | 7 +++---- hexedit/pico_persist.ld | 11 +++++++++++ hexedit/pico_ram_only.ld | 13 ------------- hexedit/uart.s | 32 -------------------------------- 8 files changed, 75 insertions(+), 78 deletions(-) create mode 100644 hexedit/pico_persist.ld delete mode 100644 hexedit/pico_ram_only.ld diff --git a/README.md b/README.md index 032ff5b..8ebd951 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,37 @@ of the Raspberry Pi Pico's on-board flash. Most of the space is dedicated to setting up the clocks, GPIO, and UART. -Current status: almost complete. -Right now it simply echos characters received over UART. +Enter a series of octal halfwords +then press G to jump to the beginning of SRAM +and begin executing them as instructions. + +This is the first step in bootstrapping the whole system. + +%% Better editor + +%% A more robust and user-friendly hex-editor. +%% It can duplicate itself. ## Assembler -An assembler that can assemble itself (WIP) +This is a single-pass assembler +supporting most of the ARMv6-M instruction set +using a simplified instruction syntax +in which there are +no labels, +only octal literals, +and unambiguous instruction mnemonics. + +It does not allow the user to type invalid instructions. + +## Better Assembler Goals: - A subset of GNU `as` syntax - Reasonably extensible - Small code size + +%% ## LISP Interpreter + +%% A LISP interpreter for the Raspberry Pi Pico, +%% developed ON a raspberry pi pico diff --git a/assembler/assemble.s b/assembler/assemble.s index 7dec597..6ef1436 100644 --- a/assembler/assemble.s +++ b/assembler/assemble.s @@ -8,7 +8,6 @@ // TODO: // - test each instruction // - decide on additional push or pops -// - add data literal "instructions" // - redo_line is problematic // - PP and PL are broken (end char) diff --git a/hexedit/Makefile b/hexedit/Makefile index 2ff0812..d862c25 100644 --- a/hexedit/Makefile +++ b/hexedit/Makefile @@ -1,21 +1,21 @@ all: build -build: echo.uf2 +build: hexedit.uf2 -echo.uf2: echo.elf - ../elf/elf2uf2 echo.elf echo.uf2 +hexedit.uf2: hexedit.elf + ../elf/elf2uf2 hexedit.elf hexedit.uf2 -objects = main.o uart.o +objects = main.o uart.o hexedit.o -echo.elf: $(objects) - arm-none-eabi-ld -T pico_ram_only.ld -o echo.elf $(objects) ../setup/setup.so +hexedit.elf: $(objects) + arm-none-eabi-ld -T pico_persist.ld -o hexedit.elf $(objects) ../setup/setup.so $(objects): %.o: %.s arm-none-eabi-as -o $@ $< clean: - rm echo.elf echo.uf2 *.o + rm hexedit.elf hexedit.uf2 *.o -flash: echo.uf2 +flash: hexedit.uf2 [ -h /dev/disk/by-label/RPI-RP2 ] || sleep 3s - cat echo.uf2 > /dev/disk/by-label/RPI-RP2 + cat hexedit.uf2 > /dev/disk/by-label/RPI-RP2 diff --git a/hexedit/hexedit.s b/hexedit/hexedit.s index 0bc03a9..26bc84b 100644 --- a/hexedit/hexedit.s +++ b/hexedit/hexedit.s @@ -2,24 +2,34 @@ .cpu cortex-m0plus .thumb +.equ SRAM_BASE, 0x20000000 + .type hexedit, %function .global hexedit hexedit: - ldr r2, =0x20000100 - movs r1, 0 -getchar: + ldr r6, =SRAM_BASE + adds r5, r6, 1 +10: + movs r4, 0 +20: bl uart_recv - cmp r0, 'g - beq stop - subs r0, '0 // The ASCII char '0' - bmi next - lsls r1, 4 - adds r1, r0 - b getchar -next: - ldr r0, [r2, 0] - adds r2, 4 - b hexedit -stop: - b 0x20000100 + cmp r0, '\r + beq 30f + cmp r0, 'G + beq 40f + bl uart_send + subs r0, '0 + lsls r4, 3 + adds r4, r0 + b 20b +30: + movs r0, '\r + bl uart_send + movs r0, '\n + bl uart_send + strh r4, [r6] + adds r6, 2 + b 10b +40: + bx r5 diff --git a/hexedit/main.s b/hexedit/main.s index 5e294d4..f2f6126 100644 --- a/hexedit/main.s +++ b/hexedit/main.s @@ -2,6 +2,8 @@ .cpu cortex-m0plus .thumb +.section .entry, "ax" + .type main, %function .global main @@ -10,7 +12,4 @@ main: bl setup_clocks bl setup_gpio bl setup_uart -1: - bl uart_recv - bl uart_send - b 1b + b hexedit diff --git a/hexedit/pico_persist.ld b/hexedit/pico_persist.ld new file mode 100644 index 0000000..32cc42f --- /dev/null +++ b/hexedit/pico_persist.ld @@ -0,0 +1,11 @@ +MEMORY { + FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2M + SRAM(rx) : ORIGIN = 0x20041f00, LENGTH = 252 +} + +SECTIONS { + .text : { + *(.entry) + *(.text) + } >SRAM AT>FLASH +} diff --git a/hexedit/pico_ram_only.ld b/hexedit/pico_ram_only.ld deleted file mode 100644 index eb2450e..0000000 --- a/hexedit/pico_ram_only.ld +++ /dev/null @@ -1,13 +0,0 @@ -ENTRY(main) - -MEMORY { - FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2M - SRAM(rwx) : ORIGIN = 0x20000000, LENGTH = 264K -} - -SECTIONS { - .text : { - *(.text) - . = ALIGN(4); - } > SRAM -} diff --git a/hexedit/uart.s b/hexedit/uart.s index b845c8b..e79cbdc 100644 --- a/hexedit/uart.s +++ b/hexedit/uart.s @@ -31,35 +31,3 @@ uart_recv: 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} -- cgit v1.2.3