diff options
| author | Jacques Comeaux <jacquesrcomeaux@protonmail.com> | 2024-05-26 14:21:59 -0500 | 
|---|---|---|
| committer | Jacques Comeaux <jacquesrcomeaux@protonmail.com> | 2024-05-26 14:21:59 -0500 | 
| commit | 5bbad5026cb810f61c2466d5c4bf3438ba820842 (patch) | |
| tree | 1fa99f91c1af046d812485ac52abf7b83eb2acdc | |
| parent | 7388c270069c2d1418539bca1d2789a6d468ecc2 (diff) | |
Finish hexedit and update README
| -rw-r--r-- | README.md | 29 | ||||
| -rw-r--r-- | assembler/assemble.s | 1 | ||||
| -rw-r--r-- | hexedit/Makefile | 18 | ||||
| -rw-r--r-- | hexedit/hexedit.s | 42 | ||||
| -rw-r--r-- | hexedit/main.s | 7 | ||||
| -rw-r--r-- | hexedit/pico_persist.ld (renamed from hexedit/pico_ram_only.ld) | 8 | ||||
| -rw-r--r-- | hexedit/uart.s | 32 | 
7 files changed, 67 insertions, 70 deletions
| @@ -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_ram_only.ld b/hexedit/pico_persist.ld index eb2450e..32cc42f 100644 --- a/hexedit/pico_ram_only.ld +++ b/hexedit/pico_persist.ld @@ -1,13 +1,11 @@ -ENTRY(main) -  MEMORY {    FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2M -  SRAM(rwx) : ORIGIN = 0x20000000, LENGTH = 264K +  SRAM(rx) : ORIGIN = 0x20041f00, LENGTH = 252  }  SECTIONS {    .text : { +    *(.entry)      *(.text) -    . = ALIGN(4); -  } > SRAM +  } >SRAM AT>FLASH  } 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} | 
