Skip to contentSkip to conversation

semihosting tests: add v7m tests

RFC PATCH In review Alex Bennée 2 participants 8 messages Jul 3, 2019 – Jul 9, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 semihosting tests: add v7m tests

M-profile has yet another way of triggering semihosting calls using the BKPT instruction. To support this we need to add a M-profile setup so we use the nice and simple microbit model which has a Cortex-M0 in it.

---
 Makefile         | 24 ++++++++++++++++++++---
 microbit.lds     | 32 ++++++++++++++++++++++++++++++
 semicall.S       |  7 ++++++-
 start-microbit.S | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 4 deletions(-)
 create mode 100644 microbit.lds
 create mode 100644 start-microbit.S
Makefile +21 -3
index 1fea97e..9f04cdd 100644
@@ -40,6 +40,7 @@
 
 A32GCC := arm-linux-gnueabihf-gcc -marm
 T32GCC := arm-linux-gnueabihf-gcc -mthumb
+V7MGCC := arm-none-eabi-gcc -mcpu=cortex-m0 -mfloat-abi=soft
 A64GCC := aarch64-linux-gnu-gcc
 
 A32LD := arm-linux-gnueabihf-ld
@@ -47,7 +48,9 @@ A32LD := arm-linux-gnueabihf-ld
 A32LINKOPTS := -nostdlib -lgcc -Xlinker --script=baremetal.lds -Xlinker --build-id=none
 A64LINKOPTS := -nostdlib -lgcc -Xlinker --script=baremetal-a64.lds -Xlinker --build-id=none
 
-QEMU_BUILDDIR := ~/linaro/qemu-from-laptop/qemu/build/x86
+AV7MLINKOPTS := -nostdlib -lgcc -Xlinker --script=microbit.lds -Xlinker --build-id=none
+
+QEMU_BUILDDIR := ~/lsrc/qemu.git/builds/arm.all
 
 ifdef GDBPORT
 SYSGDB := -gdb tcp::$(GDBPORT)
@@ -60,11 +63,15 @@ QEMU_SYSTEM_ARM = $(QEMU_BUILDDIR)/arm-softmmu/qemu-system-arm $(SYSGDB)
 QEMU_SYSTEM_AARCH64 = $(QEMU_BUILDDIR)/aarch64-softmmu/qemu-system-aarch64 $(SYSGDB)
 
 all: usertest-a32 usertest-a64 usertest-t32 \
-	systest-a32.axf systest-t32.axf systest-a64.axf
+	systest-a32.axf systest-t32.axf \
+	systest-a32-hlt.axf systest-t32-hlt.axf \
+	systest-t32-bkpt.axf \
+	systest-a64.axf
 
 usertest-srcs = usertest.c semihosting.c semicall.S printf/printf.c
 
 systest-srcs = start.S string.c $(usertest-srcs)
+microbit-systest-srcs = start-microbit.S string.c $(usertest-srcs)
 
 usertest-a32: $(usertest-srcs)
 	$(A32GCC) --static -o $@ $^
@@ -93,6 +100,9 @@ systest-a32-hlt.axf: $(systest-srcs)
 systest-t32-hlt.axf: $(systest-srcs)
 	$(T32GCC) -DUSE_HLT -o $@ $^ $(A32LINKOPTS)
 
+systest-t32-bkpt.axf: $(microbit-systest-srcs)
+	$(V7MGCC) -DUSE_BKPT -o $@ $^ $(AV7MLINKOPTS)
+
 systest-a64.axf: $(systest-srcs)
 	$(A64GCC) -nostdlib -o $@ $^ $(A64LINKOPTS)
 
@@ -123,6 +133,9 @@ run-systest-a32-hlt: systest-a32-hlt.axf
 run-systest-t32-hlt: systest-t32-hlt.axf
 	$(QEMU_SYSTEM_ARM) -M virt --display none --semihosting -kernel $^
 
+run-systest-t32-bkpt: systest-t32-bkpt.axf
+	$(QEMU_SYSTEM_ARM) -M microbit --display none --semihosting -kernel $^
+
 run-systest-a64: systest-a64.axf
 	$(QEMU_SYSTEM_AARCH64) -M virt --display none --semihosting \
 		-cpu cortex-a57 -kernel $^
@@ -130,4 +143,9 @@ run-systest-a64: systest-a64.axf
 run: run-usertest-a32 run-usertest-t32 run-usertest-a64 \
 	run-systest-a32 run-systest-t32 run-systest-a64 \
 	run-usertest-a32-hlt run-usertest-t32-hlt \
-	run-systest-a32-hlt run-systest-t32-hlt
+	run-systest-a32-hlt run-systest-t32-hlt \
+	run-systest-t32-bkpt
+
+run-alt: run-usertest-a32 run-usertest-t32 run-usertest-a64 \
+	run-systest-a64 \
+	run-usertest-a32-hlt run-usertest-t32-hlt \
microbit.lds new file +32 -0
new file mode 100644
index 0000000..24840a3
@@ -0,0 +1,32 @@
+/*
+ * microbit.lds : simple linker script for baremetal ARM-M test cases
+ *
+ * Copyright (C) 2019 Linaro Limited. All rights reserved.
+ *
+ * Memory layout is for the BBC Microbit board which puts RAM at 0x20000000
+ */
+
+RAMSTART = 0x20000000;
+STACKTOP = 0x20004000;
+
+ENTRY(exc_reset_thumb)
+
+SECTIONS
+{
+    . = 0x0;
+    .text : {
+        *(.text)
+    }
+    .data : {
+        *(.data)
+    }
+    .rodata : {
+        *(.rodata)
+    }
+    .bss : {
+        *(.bss)
+    }
+    /DISCARD/ : {
+        *(.ARM.attributes)
+    }
+}
semicall.S +6 -1
index 1418a42..e6316c4 100644
@@ -51,8 +51,13 @@ __semi_call:
 #else
         /* traditional svc */
 #if defined(__thumb__)
-        /* NB: assumes not M-profile (which is BKPT) */
+#if defined(USE_BKPT)
+        /* M-profile T32 */
+        bkpt 0xab
+#else
+        /* A+R Profile T32 */
         svc 0xab
+#endif
 #else
         svc 0x123456
 #endif
start-microbit.S new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw
Quoted 7 lines · Alex Bennée

M-profile has yet another way of triggering semihosting calls using the BKPT instruction. To support this we need to add a M-profile setup so we use the nice and simple microbit model which has a Cortex-M0 in it.

---

<snip>

Quoted 4 lines
Makefile +0 -0
@@ -40,6 +40,7 @@
 

<snip>

Makefile A32LD := arm-linux-gnueabihf-ld · line 53

Quoted 5 lines
Makefile +3 -1
-QEMU_BUILDDIR := ~/linaro/qemu-from-laptop/qemu/build/x86
+AV7MLINKOPTS := -nostdlib -lgcc -Xlinker --script=microbit.lds -Xlinker --build-id=none
+
+QEMU_BUILDDIR := ~/lsrc/qemu.git/builds/arm.all

Obviously without including my local devel hack for QEMU_BUILDDIR

--
Alex Bennée

#2 lore raw
In reply to Alex Bennée
Quoted 9 lines · Alex Bennée

M-profile has yet another way of triggering semihosting calls using the BKPT instruction. To support this we need to add a M-profile setup so we use the nice and simple microbit model which has a Cortex-M0 in it.

---
 Makefile         | 24 ++++++++++++++++++++---
 microbit.lds     | 32 ++++++++++++++++++++++++++++++

<snip>

Quoted 25 lines
microbit.lds new file +22 -0
@@ -0,0 +1,32 @@
+/*
+ * microbit.lds : simple linker script for baremetal ARM-M test cases
+ *
+ * Copyright (C) 2019 Linaro Limited. All rights reserved.
+ *
+ * Memory layout is for the BBC Microbit board which puts RAM at 0x20000000
+ */
+
+RAMSTART = 0x20000000;
+STACKTOP = 0x20004000;
+
+ENTRY(exc_reset_thumb)
+
+SECTIONS
+{
+    . = 0x0;
+    .text : {
+        *(.text)
+    }
+    .data : {
+        *(.data)
+    }

microbit.lds line 32

Quoted 10 lines
microbit.lds new file +10 -0
+    .rodata : {
+        *(.rodata)
+    }
+    .bss : {
+        *(.bss)
+    }
+    /DISCARD/ : {
+        *(.ARM.attributes)
+    }
+}

And it would help of course if data was is the read/write area.

- .data : {
- *(.data)
- }

     .rodata : {
         *(.rodata)
     }

+ . = RAMSTART;
+ .data : {
+ *(.data)
+ }

     .bss : {
         *(.bss)
     }

--
Alex Bennée

#3 lore raw
In reply to Alex Bennée
Quoted 7 lines · Alex Bennée

M-profile has yet another way of triggering semihosting calls using the BKPT instruction. To support this we need to add a M-profile setup so we use the nice and simple microbit model which has a Cortex-M0 in it.

Quoted 8 lines
---
 Makefile         | 24 ++++++++++++++++++++---
 microbit.lds     | 32 ++++++++++++++++++++++++++++++
 semicall.S       |  7 ++++++-
 start-microbit.S | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 4 deletions(-)
 create mode 100644 microbit.lds
 create mode 100644 start-microbit.S

Good to have this semihosting mode in the test suite, thanks.

Quoted 13 lines
Makefile +1 -0
index 1fea97e..9f04cdd 100644
@@ -40,6 +40,7 @@
 
 A32GCC := arm-linux-gnueabihf-gcc -marm
 T32GCC := arm-linux-gnueabihf-gcc -mthumb
+V7MGCC := arm-none-eabi-gcc -mcpu=cortex-m0 -mfloat-abi=soft
 A64GCC := aarch64-linux-gnu-gcc
 
 A32LD := arm-linux-gnueabihf-ld

Makefile A32LD := arm-linux-gnueabihf-ld · line 53

Quoted 7 lines
Makefile +3 -1
@@ -47,7 +48,9 @@ A32LD := arm-linux-gnueabihf-ld
 A32LINKOPTS := -nostdlib -lgcc -Xlinker --script=baremetal.lds -Xlinker --build-id=none
 A64LINKOPTS := -nostdlib -lgcc -Xlinker --script=baremetal-a64.lds -Xlinker --build-id=none
 
-QEMU_BUILDDIR := ~/linaro/qemu-from-laptop/qemu/build/x86
+AV7MLINKOPTS := -nostdlib -lgcc -Xlinker --script=microbit.lds -Xlinker --build-id=none
+
+QEMU_BUILDDIR := ~/lsrc/qemu.git/builds/arm.all

My local devel hack for this is obviously more important to have in the git repo than yours :-)

Makefile QEMU_SYSTEM_ARM = $(QEMU_BUILDDIR)/arm-softmmu/qemu-system-arm $(SYSGDB) · line 69

Quoted 11 lines
Makefile +4 -1
 ifdef GDBPORT
 SYSGDB := -gdb tcp::$(GDBPORT)
@@ -60,11 +63,15 @@ QEMU_SYSTEM_ARM = $(QEMU_BUILDDIR)/arm-softmmu/qemu-system-arm $(SYSGDB)
 QEMU_SYSTEM_AARCH64 = $(QEMU_BUILDDIR)/aarch64-softmmu/qemu-system-aarch64 $(SYSGDB)
 
 all: usertest-a32 usertest-a64 usertest-t32 \
-       systest-a32.axf systest-t32.axf systest-a64.axf
+       systest-a32.axf systest-t32.axf \
+       systest-a32-hlt.axf systest-t32-hlt.axf \
+       systest-t32-bkpt.axf \
+       systest-a64.axf

(The omission of the -hlt axfs from this target is a separate bug, strictly speaking, but I don't think we need to be too picky about this kind of thing given this is just a test suite.)

Quoted 28 lines
Makefile +7 -0
 usertest-srcs = usertest.c semihosting.c semicall.S printf/printf.c
 
 systest-srcs = start.S string.c $(usertest-srcs)
+microbit-systest-srcs = start-microbit.S string.c $(usertest-srcs)
 
 usertest-a32: $(usertest-srcs)
        $(A32GCC) --static -o $@ $^
@@ -93,6 +100,9 @@ systest-a32-hlt.axf: $(systest-srcs)
 systest-t32-hlt.axf: $(systest-srcs)
        $(T32GCC) -DUSE_HLT -o $@ $^ $(A32LINKOPTS)
 
+systest-t32-bkpt.axf: $(microbit-systest-srcs)
+       $(V7MGCC) -DUSE_BKPT -o $@ $^ $(AV7MLINKOPTS)
+
 systest-a64.axf: $(systest-srcs)
        $(A64GCC) -nostdlib -o $@ $^ $(A64LINKOPTS)
 
@@ -123,6 +133,9 @@ run-systest-a32-hlt: systest-a32-hlt.axf
 run-systest-t32-hlt: systest-t32-hlt.axf
        $(QEMU_SYSTEM_ARM) -M virt --display none --semihosting -kernel $^
 
+run-systest-t32-bkpt: systest-t32-bkpt.axf
+       $(QEMU_SYSTEM_ARM) -M microbit --display none --semihosting -kernel $^
+
 run-systest-a64: systest-a64.axf
        $(QEMU_SYSTEM_AARCH64) -M virt --display none --semihosting \
                -cpu cortex-a57 -kernel $^

Makefile run-systest-a64: systest-a64.axf · line 151

Quoted 10 lines
Makefile +6 -1
@@ -130,4 +143,9 @@ run-systest-a64: systest-a64.axf
 run: run-usertest-a32 run-usertest-t32 run-usertest-a64 \
        run-systest-a32 run-systest-t32 run-systest-a64 \
        run-usertest-a32-hlt run-usertest-t32-hlt \
-       run-systest-a32-hlt run-systest-t32-hlt
+       run-systest-a32-hlt run-systest-t32-hlt \
+       run-systest-t32-bkpt
+
+run-alt: run-usertest-a32 run-usertest-t32 run-usertest-a64 \
+       run-systest-a64 \
+       run-usertest-a32-hlt run-usertest-t32-hlt \

What's this target for, and why does it end the makefile with a '\' ?

microbit.lds line 7

Quoted 13 lines
microbit.lds new file +7 -0
new file mode 100644
index 0000000..24840a3
@@ -0,0 +1,32 @@
+/*
+ * microbit.lds : simple linker script for baremetal ARM-M test cases
+ *
+ * Copyright (C) 2019 Linaro Limited. All rights reserved.
+ *
+ * Memory layout is for the BBC Microbit board which puts RAM at 0x20000000
+ */

I know this is just copied from the baremetal.lds, but we really should have a license statement in every source file (and I should fix the ones which don't have a license at the moment).

microbit.lds line 10

Quoted 3 lines
microbit.lds new file +3 -0
+
+RAMSTART = 0x20000000;
+STACKTOP = 0x20004000;

That puts stacktop really close to the start of the heap -- isn't there more space to give ourselves some safety margin?

Quoted 83 lines
microbit.lds new file +22 -0
+
+ENTRY(exc_reset_thumb)
+
+SECTIONS
+{
+    . = 0x0;
+    .text : {
+        *(.text)
+    }
+    .data : {
+        *(.data)
+    }
+    .rodata : {
+        *(.rodata)
+    }
+    .bss : {
+        *(.bss)
+    }
+    /DISCARD/ : {
+        *(.ARM.attributes)
+    }
+}
semicall.S +6 -1
index 1418a42..e6316c4 100644
@@ -51,8 +51,13 @@ __semi_call:
 #else
         /* traditional svc */
 #if defined(__thumb__)
-        /* NB: assumes not M-profile (which is BKPT) */
+#if defined(USE_BKPT)
+        /* M-profile T32 */
+        bkpt 0xab
+#else
+        /* A+R Profile T32 */
         svc 0xab
+#endif
 #else
         svc 0x123456
 #endif
start-microbit.S new file +36 -0
new file mode 100644
index 0000000..db1f06e
@@ -0,0 +1,51 @@
+/*
+ * start-microbit.S - assembly code for startup on baremetal M-profile tests
+ *
+ * Copyright (c) 2015 Linaro Limited
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of Linaro Limited nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ */
+
+        .syntax unified
+        .cpu cortex-m0
+        .thumb
+
+        .text
+
+vector_table:
+        .word STACKTOP          /* 0. SP_main */
+        .word exc_reset_thumb   /* 1. Reset */
+        .word 0                 /* 2. NMI */
+        .word 0                 /* 3. HardFault */
+        .rept 7
+        .word 0                 /* 4-10. Reserved */
+        .endr
+        .word 0                 /* 11. SVCall */
+        .word 0                 /* 12. Reserved */

start-microbit.S line 46

Quoted 10 lines
start-microbit.S new file +10 -0
+        .word 0                 /* 13. Reserved */
+        .word 0                 /* 14. PendSV */
+        .word 0                 /* 15. SysTick */
+        .rept 32
+        .word 0                 /* 16-47. External Interrupts */
+        .endr
+
+exc_reset:
+.equ exc_reset_thumb, exc_reset + 1
+.global exc_reset_thumb

There must be a better way than this to declare an asm label for a thumb entrypoint...

start-microbit.S

Quoted 6 lines
start-microbit.S new file +5 -1
+
+        bl main
+        bl semi_exit
+        # not reached
+1:      b 1b
--

thanks
-- PMM

#4 lore raw
Quoted 91 lines · Peter Maydell
Quoted 7 lines · Alex Bennée

M-profile has yet another way of triggering semihosting calls using the BKPT instruction. To support this we need to add a M-profile setup so we use the nice and simple microbit model which has a Cortex-M0 in it.

Quoted 8 lines
---
 Makefile         | 24 ++++++++++++++++++++---
 microbit.lds     | 32 ++++++++++++++++++++++++++++++
 semicall.S       |  7 ++++++-
 start-microbit.S | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 4 deletions(-)
 create mode 100644 microbit.lds
 create mode 100644 start-microbit.S

Good to have this semihosting mode in the test suite, thanks.

Quoted 13 lines
Makefile +1 -0
index 1fea97e..9f04cdd 100644
@@ -40,6 +40,7 @@
 
 A32GCC := arm-linux-gnueabihf-gcc -marm
 T32GCC := arm-linux-gnueabihf-gcc -mthumb
+V7MGCC := arm-none-eabi-gcc -mcpu=cortex-m0 -mfloat-abi=soft
 A64GCC := aarch64-linux-gnu-gcc
 
 A32LD := arm-linux-gnueabihf-ld

Makefile A32LD := arm-linux-gnueabihf-ld · line 53

Quoted 7 lines
Makefile +3 -1
@@ -47,7 +48,9 @@ A32LD := arm-linux-gnueabihf-ld
 A32LINKOPTS := -nostdlib -lgcc -Xlinker --script=baremetal.lds -Xlinker --build-id=none
 A64LINKOPTS := -nostdlib -lgcc -Xlinker --script=baremetal-a64.lds -Xlinker --build-id=none
 
-QEMU_BUILDDIR := ~/linaro/qemu-from-laptop/qemu/build/x86
+AV7MLINKOPTS := -nostdlib -lgcc -Xlinker --script=microbit.lds -Xlinker --build-id=none
+
+QEMU_BUILDDIR := ~/lsrc/qemu.git/builds/arm.all

My local devel hack for this is obviously more important to have in the git repo than yours :-)

Makefile QEMU_SYSTEM_ARM = $(QEMU_BUILDDIR)/arm-softmmu/qemu-system-arm $(SYSGDB) · line 69

Quoted 11 lines
Makefile +4 -1
 ifdef GDBPORT
 SYSGDB := -gdb tcp::$(GDBPORT)
@@ -60,11 +63,15 @@ QEMU_SYSTEM_ARM = $(QEMU_BUILDDIR)/arm-softmmu/qemu-system-arm $(SYSGDB)
 QEMU_SYSTEM_AARCH64 = $(QEMU_BUILDDIR)/aarch64-softmmu/qemu-system-aarch64 $(SYSGDB)
 
 all: usertest-a32 usertest-a64 usertest-t32 \
-       systest-a32.axf systest-t32.axf systest-a64.axf
+       systest-a32.axf systest-t32.axf \
+       systest-a32-hlt.axf systest-t32-hlt.axf \
+       systest-t32-bkpt.axf \
+       systest-a64.axf

(The omission of the -hlt axfs from this target is a separate bug, strictly speaking, but I don't think we need to be too picky about this kind of thing given this is just a test suite.)

Quoted 32 lines
Makefile +7 -1
 usertest-srcs = usertest.c semihosting.c semicall.S printf/printf.c
 
 systest-srcs = start.S string.c $(usertest-srcs)
+microbit-systest-srcs = start-microbit.S string.c $(usertest-srcs)
 
 usertest-a32: $(usertest-srcs)
        $(A32GCC) --static -o $@ $^
@@ -93,6 +100,9 @@ systest-a32-hlt.axf: $(systest-srcs)
 systest-t32-hlt.axf: $(systest-srcs)
        $(T32GCC) -DUSE_HLT -o $@ $^ $(A32LINKOPTS)
 
+systest-t32-bkpt.axf: $(microbit-systest-srcs)
+       $(V7MGCC) -DUSE_BKPT -o $@ $^ $(AV7MLINKOPTS)
+
 systest-a64.axf: $(systest-srcs)
        $(A64GCC) -nostdlib -o $@ $^ $(A64LINKOPTS)
 
@@ -123,6 +133,9 @@ run-systest-a32-hlt: systest-a32-hlt.axf
 run-systest-t32-hlt: systest-t32-hlt.axf
        $(QEMU_SYSTEM_ARM) -M virt --display none --semihosting -kernel $^
 
+run-systest-t32-bkpt: systest-t32-bkpt.axf
+       $(QEMU_SYSTEM_ARM) -M microbit --display none --semihosting -kernel $^
+
 run-systest-a64: systest-a64.axf
        $(QEMU_SYSTEM_AARCH64) -M virt --display none --semihosting \
                -cpu cortex-a57 -kernel $^
@@ -130,4 +143,9 @@ run-systest-a64: systest-a64.axf
 run: run-usertest-a32 run-usertest-t32 run-usertest-a64 \
        run-systest-a32 run-systest-t32 run-systest-a64 \
        run-usertest-a32-hlt run-usertest-t32-hlt \
-       run-systest-a32-hlt run-systest-t32-hlt
Quoted 8 lines

Makefile run-systest-a64: systest-a64.axf · line 151

Quoted 6 lines
Makefile +6 -0
+       run-systest-a32-hlt run-systest-t32-hlt \
+       run-systest-t32-bkpt
+
+run-alt: run-usertest-a32 run-usertest-t32 run-usertest-a64 \
+       run-systest-a64 \
+       run-usertest-a32-hlt run-usertest-t32-hlt \

What's this target for, and why does it end the makefile with a '\' ?

Ignore that - it was a alternative run while I was working around the tests that wouldn't build.

Quoted 19 lines
Quoted 7 lines
microbit.lds new file +0 -0
new file mode 100644
index 0000000..24840a3

microbit.lds line 7

Quoted 7 lines
microbit.lds new file +7 -0
@@ -0,0 +1,32 @@
+/*
+ * microbit.lds : simple linker script for baremetal ARM-M test cases
+ *
+ * Copyright (C) 2019 Linaro Limited. All rights reserved.
+ *
+ * Memory layout is for the BBC Microbit board which puts RAM at 0x20000000
+ */

I know this is just copied from the baremetal.lds, but we really should have a license statement in every source file (and I should fix the ones which don't have a license at the moment).

Quoted 6 lines

microbit.lds line 10

Quoted 3 lines
microbit.lds new file +3 -0
+
+RAMSTART = 0x20000000;
+STACKTOP = 0x20004000;

That puts stacktop really close to the start of the heap -- isn't there more space to give ourselves some safety margin?

We could - do we actually use any heap in this - I thought it was all static .data?

Quoted 11 lines
Quoted 11 lines
microbit.lds new file +10 -0
+
+ENTRY(exc_reset_thumb)
+
+SECTIONS
+{
+    . = 0x0;
+    .text : {
+        *(.text)
+    }
+    .data : {
Quoted 8 lines

microbit.lds line 28

Quoted 8 lines
microbit.lds new file +8 -0
+        *(.data)
+    }
+    .rodata : {
+        *(.rodata)
+    }
+    .bss : {
+        *(.bss)
+    }

I wonder if there are runes for setting STACKTOP as end of .bss + something? I guess it would help if we could tell the linker what the top of microbit memory was.

Quoted 70 lines
Quoted 70 lines
microbit.lds new file +4 -0
+    /DISCARD/ : {
+        *(.ARM.attributes)
+    }
+}
semicall.S +6 -1
index 1418a42..e6316c4 100644
@@ -51,8 +51,13 @@ __semi_call:
 #else
         /* traditional svc */
 #if defined(__thumb__)
-        /* NB: assumes not M-profile (which is BKPT) */
+#if defined(USE_BKPT)
+        /* M-profile T32 */
+        bkpt 0xab
+#else
+        /* A+R Profile T32 */
         svc 0xab
+#endif
 #else
         svc 0x123456
 #endif
start-microbit.S new file +41 -0
new file mode 100644
index 0000000..db1f06e
@@ -0,0 +1,51 @@
+/*
+ * start-microbit.S - assembly code for startup on baremetal M-profile tests
+ *
+ * Copyright (c) 2015 Linaro Limited
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of Linaro Limited nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ */
+
+        .syntax unified
+        .cpu cortex-m0
+        .thumb
+
+        .text
+
+vector_table:
+        .word STACKTOP          /* 0. SP_main */
+        .word exc_reset_thumb   /* 1. Reset */
+        .word 0                 /* 2. NMI */
+        .word 0                 /* 3. HardFault */
+        .rept 7
+        .word 0                 /* 4-10. Reserved */
+        .endr
+        .word 0                 /* 11. SVCall */
+        .word 0                 /* 12. Reserved */
+        .word 0                 /* 13. Reserved */
+        .word 0                 /* 14. PendSV */
+        .word 0                 /* 15. SysTick */
+        .rept 32
+        .word 0                 /* 16-47. External Interrupts */
Quoted 8 lines

start-microbit.S line 46

Quoted 5 lines
start-microbit.S new file +5 -0
+        .endr
+
+exc_reset:
+.equ exc_reset_thumb, exc_reset + 1
+.global exc_reset_thumb

There must be a better way than this to declare an asm label for a thumb entrypoint...

That may not be needed any more - I'll drop it and see.

Quoted 10 lines

start-microbit.S

Quoted 7 lines
start-microbit.S new file +5 -1
+
+        bl main
+        bl semi_exit
+        # not reached
+1:      b 1b
--

thanks
-- PMM

--
Alex Bennée

#5 lore raw
Quoted 30 lines · Alex Bennée
Quoted 19 lines · Peter Maydell

microbit.lds line 7

Quoted 13 lines · Alex Bennée
microbit.lds new file +7 -0
new file mode 100644
index 0000000..24840a3
@@ -0,0 +1,32 @@
+/*
+ * microbit.lds : simple linker script for baremetal ARM-M test cases
+ *
+ * Copyright (C) 2019 Linaro Limited. All rights reserved.
+ *
+ * Memory layout is for the BBC Microbit board which puts RAM at 0x20000000
+ */

I know this is just copied from the baremetal.lds, but we really should have a license statement in every source file (and I should fix the ones which don't have a license at the moment).

Quoted 6 lines

microbit.lds line 10

Quoted 3 lines
microbit.lds new file +3 -0
+
+RAMSTART = 0x20000000;
+STACKTOP = 0x20004000;

That puts stacktop really close to the start of the heap -- isn't there more space to give ourselves some safety margin?

Quoted 2 lines

We could - do we actually use any heap in this - I thought it was all static .data?

By 'heap' here I mean everything that goes after RAMSTART, which is the whole of the .text, .data and .bss sections. Mostly I just think we should give ourselves a reasonable amount of elbow room so we don't find out the hard way that we've expanded the code/data to the point where it runs into the stack...

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
microbit.lds new file +14 -0
+
+ENTRY(exc_reset_thumb)
+
+SECTIONS
+{
+    . = 0x0;
+    .text : {
+        *(.text)
+    }
+    .data : {
+        *(.data)
+    }
+    .rodata : {
+        *(.rodata)
Quoted 8 lines
Quoted 4 lines

microbit.lds line 28

Quoted 4 lines
microbit.lds new file +4 -0
+    }
+    .bss : {
+        *(.bss)
+    }

I wonder if there are runes for setting STACKTOP as end of .bss + something? I guess it would help if we could tell the linker what the top of microbit memory was.

In the baremetal.lds and baremetal-a64.lds files I use
". = RAMSTART;" and ". = STACKTOP;" lines, which means that the linker will detect whether we've put too much stuff
in and run past STACKTOP. Your file here seems to be missing those...

(Also, why do you need a .rodata here when the other lds files don't?)

Quoted 8 lines
Quoted 6 lines

microbit.lds line 31

Quoted 3 lines
microbit.lds new file +3 -0
+exc_reset:
+.equ exc_reset_thumb, exc_reset + 1
+.global exc_reset_thumb

There must be a better way than this to declare an asm label for a thumb entrypoint...

That may not be needed any more - I'll drop it and see.

You do definitely need the vector table entry to have the low bit set. I just suspect there's a way to say "this label is a code entry point for Thumb mode" which avoids the need for the manual addition.

thanks
-- PMM

#6 lore raw
Quoted 65 lines · Peter Maydell
Quoted 30 lines · Alex Bennée
Quoted 19 lines · Peter Maydell

microbit.lds line 7

Quoted 13 lines · Alex Bennée
microbit.lds new file +7 -0
new file mode 100644
index 0000000..24840a3
@@ -0,0 +1,32 @@
+/*
+ * microbit.lds : simple linker script for baremetal ARM-M test cases
+ *
+ * Copyright (C) 2019 Linaro Limited. All rights reserved.
+ *
+ * Memory layout is for the BBC Microbit board which puts RAM at 0x20000000
+ */

I know this is just copied from the baremetal.lds, but we really should have a license statement in every source file (and I should fix the ones which don't have a license at the moment).

Quoted 6 lines

microbit.lds line 10

Quoted 3 lines
microbit.lds new file +3 -0
+
+RAMSTART = 0x20000000;
+STACKTOP = 0x20004000;

That puts stacktop really close to the start of the heap -- isn't there more space to give ourselves some safety margin?

Quoted 2 lines

We could - do we actually use any heap in this - I thought it was all static .data?

By 'heap' here I mean everything that goes after RAMSTART, which is the whole of the .text, .data and .bss sections. Mostly I just think we should give ourselves a reasonable amount of elbow room so we don't find out the hard way that we've expanded the code/data to the point where it runs into the stack...

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
microbit.lds new file +14 -0
+
+ENTRY(exc_reset_thumb)
+
+SECTIONS
+{
+    . = 0x0;
+    .text : {
+        *(.text)
+    }
+    .data : {
+        *(.data)
+    }
+    .rodata : {
+        *(.rodata)
Quoted 8 lines
Quoted 4 lines

microbit.lds line 28

Quoted 4 lines
microbit.lds new file +4 -0
+    }
+    .bss : {
+        *(.bss)
+    }

I wonder if there are runes for setting STACKTOP as end of .bss + something? I guess it would help if we could tell the linker what the top of microbit memory was.

Quoted 6 lines

In the baremetal.lds and baremetal-a64.lds files I use
". = RAMSTART;" and ". = STACKTOP;" lines, which means that the linker will detect whether we've put too much stuff
in and run past STACKTOP. Your file here seems to be missing those...

(Also, why do you need a .rodata here when the other lds files don't?)

In case we add any? Also see the other reply after rth figured out what was breaking due to attempts to write to the ROM.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

microbit.lds line 31

Quoted 4 lines
microbit.lds new file +3 -0
+exc_reset:
+.equ exc_reset_thumb, exc_reset + 1
+.global exc_reset_thumb

There must be a better way than this to declare an asm label for a thumb entrypoint...

Quoted 6 lines
Quoted 1 line

That may not be needed any more - I'll drop it and see.

You do definitely need the vector table entry to have the low bit set. I just suspect there's a way to say "this label is a code entry point for Thumb mode" which avoids the need for the manual addition.

Ahh I misread - I added:

.type __semi_call, function

to semi.s - maybe that would do as well?

Quoted 3 lines

thanks
-- PMM

--
Alex Bennée

#7 lore raw
In reply to Peter Maydell
Quoted 3 lines · Peter Maydell

I know this is just copied from the baremetal.lds, but we really should have a license statement in every source file (and I should fix the ones which don't have a license at the moment).

I just pushed a new revision to the semihosting-tests repo which adds the missing copyright/license comments to the current set of files.

thanks
-- PMM