Time to define some test data to test if our string macro's actually work as expected.
Unit tests will in the end not be part of the the release code, just for now until we know that the code actually does what we think it should do.
We define some Read-Only data constants.
# rodata.s
.align 2
# Read only data
.section .rodata
VERSION_INFO: .string "SparkFun Red-V bare metal v26b.\n\r"
CRLF: .string "\n\r"
SEPARATOR_SINGLE_LINE: .string "------------------------------------------------------------\n\r"
SEPARATOR_DOUBLE_LINE: .string "============================================================\n\r"
.section .rodata.tests
# String testing code
STRINGS_TEST_START_MSG: .string "Starting strings test.\n\r"
STRINGS_TEST_END_MSG: .string "Ended strings test.\n\r"
STRINGS_TEST_STRCPY_MSG: .string "STRCPY test = "
STRINGS_TEST_STRNCPY_MSG: .string "STRNCPY test = "
STRINGS_TEST_FILL_BYTES_MSG: .string "FILL_BYTES test = "
STRING_TEST_MSG: .string "rodata line string test data message.\n\r"
.byte 0
In the strings-macros.s I also defined a PRINT macro statement that directly sends to the UART
The idea is to have macro's that makes the assembler code more human friendly, we are basically starting to create some kind of language from scratch.
# ----------------------------------------------------------------------- # print message # ----------------------------------------------------------------------- .macro PRINT message_ptr la a0, \message_ptr jal puts .endm
We need a bss.s that defines a memory block (1024 bytes) that we can use as scratch buffer (We do not yet have memory management)
# bss.s
.align 2
# Uninitialized data
.section .bss
scratch1024:
.skip 1024,0
We have now a system that can test the string macros from the previous post.
This becomes part of our logging in the future.
# strings-tests.s
.align 2
.include "./src/data/data.s"
.include "./src/data/rodata.s"
.include "./src/data/bss.s"
.include "./src/include/string-macros.s"
.section .text
.globl _strings_tests
_strings_tests:
PRINT STRINGS_TEST_START_MSG
PRINT SEPARATOR_DOUBLE_LINE
PRINT STRINGS_TEST_STRCPY_MSG
STRCPY scratch1024, STRING_TEST_MSG
PRINT scratch1024
PRINT STRINGS_TEST_STRNCPY_MSG
STRNCPY scratch1024, STRING_TEST_MSG, 5
PRINT scratch1024
PRINT CRLF
PRINT STRINGS_TEST_FILL_BYTES_MSG
FILL_BYTES scratch1024, '*', 5
PRINT scratch1024
PRINT CRLF
STRNCPY scratch1024, destmsg2, 10
PRINT scratch1024
PRINT CRLF
FILL_BYTES scratch1024, '-', 2
PRINT scratch1024
PRINT CRLF
STRNCPY scratch1024, destmsg2, 10
PRINT scratch1024
PRINT CRLF
FILL_STRING scratch1024, '=', 10
PRINT scratch1024
PRINT CRLF
PRINT SEPARATOR_SINGLE_LINE
PRINT STRINGS_TEST_END_MSG
ret
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.