diff --git a/app_mpu_test/Readme.txt b/app_mpu_test/Readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..d984b5d6009f60b687cbb311aee58c1ce76b4951 --- /dev/null +++ b/app_mpu_test/Readme.txt @@ -0,0 +1,14 @@ + +To run the testsuite, run build.sh, then copy mpu_testsuite.cpp +from this directory into the top level directory and modify the +Makefile from + +SRC := \ +main.cpp + +to + +SRC := \ +mpu_testsuite.cpp + +Run cleanup.sh from this directory to clean compilation files. \ No newline at end of file diff --git a/app_mpu_test/build.sh b/app_mpu_test/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..090ec6d021254ec87df6eabedb994c807b7e064e --- /dev/null +++ b/app_mpu_test/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +echo > includes.h +echo "#ifndef _APP_MPU_TESTS_" >> includes.h +echo "#define _APP_MPU_TESTS_" >> includes.h + +for i in *; +do + if test -d $i; then + cd $i && make clean && make && cp mpuTest.h "../$i.h" && cd .. + echo "#include \"app_mpu_test/$i.h\"" >> includes.h + sed "s/test_elf/$i\_elf/" $i.h -i + fi; +done; + +echo "#endif //_APP_MPU_TESTS_" >> includes.h diff --git a/app_mpu_test/cleanup.sh b/app_mpu_test/cleanup.sh new file mode 100755 index 0000000000000000000000000000000000000000..450e08d3c8d68e1ca8d52d2f7fe882cd4b9904ea --- /dev/null +++ b/app_mpu_test/cleanup.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +rm includes.h + +for i in *; +do + if test -d $i; then + rm "$i.h" + cd $i && make clean && cd .. + fi; +done; diff --git a/app_mpu_test/mpu_testsuite.cpp b/app_mpu_test/mpu_testsuite.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd63372dce4783a099f0bfbfe77e7b1cdb30ebf7 --- /dev/null +++ b/app_mpu_test/mpu_testsuite.cpp @@ -0,0 +1,30 @@ +#include <cstdio> +#include <sys/wait.h> +#include <signal.h> +#include "miosix.h" +#include "kernel/process.h" + +//Include the test programs +#include "app_mpu_test/includes.h" + +using namespace std; +using namespace miosix; + +int main() +{ + ElfProgram prog(reinterpret_cast<const unsigned int*>(test1_elf),test1_elf_len); + pid_t child=Process::create(prog); + int ec; + pid_t pid; + pid=Process::waitpid(child,&ec,0); + iprintf("Process %d terminated\n",pid); + if(WIFEXITED(ec)) + { + iprintf("Exit code is %d\n",WEXITSTATUS(ec)); + } + else if(WIFSIGNALED(ec)) + { + if(WTERMSIG(ec)==SIGSEGV) iprintf("\nProcess segfaulted. The system is safe!!\n"); + } + return 0; +} diff --git a/app_mpu_test/Makefile b/app_mpu_test/test1/Makefile similarity index 100% rename from app_mpu_test/Makefile rename to app_mpu_test/test1/Makefile diff --git a/app_mpu_test/crt0.s b/app_mpu_test/test1/crt0.s similarity index 100% rename from app_mpu_test/crt0.s rename to app_mpu_test/test1/crt0.s diff --git a/app_mpu_test/main.c b/app_mpu_test/test1/main.c similarity index 100% rename from app_mpu_test/main.c rename to app_mpu_test/test1/main.c diff --git a/app_mpu_test/miosix.ld b/app_mpu_test/test1/miosix.ld similarity index 100% rename from app_mpu_test/miosix.ld rename to app_mpu_test/test1/miosix.ld diff --git a/app_mpu_test/test2/Makefile b/app_mpu_test/test2/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..994dae769111406b691bede0d34d103f82607323 --- /dev/null +++ b/app_mpu_test/test2/Makefile @@ -0,0 +1,50 @@ +## +## Makefile for writing PROGRAMS for the Miosix embedded OS +## TFT:Terraneo Federico Technlogies +## + +SRC := \ +main.c + +## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o" +OBJ := $(addsuffix .o, $(basename $(SRC))) + +AS := arm-miosix-eabi-as +CC := arm-miosix-eabi-gcc +CXX := arm-miosix-eabi-g++ +SZ := arm-miosix-eabi-size + +AFLAGS := -mcpu=cortex-m3 -mthumb +CFLAGS := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \ + -ffunction-sections -O2 -Wall -c +CXXFLAGS := $(CFLAGS) +LFLAGS := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \ + -Wl,--gc-sections,-Map,test.map,-T./miosix.ld,-n,-pie,--spare-dynamic-tags,3 \ + -O2 -nostdlib +DFLAGS := -MM + +LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group + +all: $(OBJ) crt0.o + $(CXX) $(LFLAGS) -o test.elf $(OBJ) crt0.o $(LINK_LIBS) + $(SZ) test.elf + @arm-miosix-eabi-objdump -Dslx test.elf > test.txt + @mx-postlinker test.elf --ramsize=16384 --stacksize=2048 --strip-sectheader + @xxd -i test.elf | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > mpuTest.h + +clean: + -rm $(OBJ) crt0.o test.elf test.map test.txt mpuTest.h *.d + +#pull in dependecy info for existing .o files +-include $(OBJ:.o=.d) + +%.o: %.s + $(AS) $(AFLAGS) $< -o $@ + +%.o : %.c + $(CC) $(CFLAGS) $< -o $@ + $(CC) $(DFLAGS) $(CFLAGS) $*.c > $*.d + +%.o : %.cpp + $(CXX) $(CXXFLAGS) $< -o $@ + $(CXX) $(DFLAGS) $(CXXFLAGS) $*.cpp > $*.d diff --git a/app_mpu_test/test2/crt0.s b/app_mpu_test/test2/crt0.s new file mode 100644 index 0000000000000000000000000000000000000000..7733008e9392ded796006a94a0c1a527a94bfc1a --- /dev/null +++ b/app_mpu_test/test2/crt0.s @@ -0,0 +1,130 @@ +/* + * Startup script for writing PROGRAMS for the Miosix embedded OS + * TFT:Terraneo Federico Technlogies + */ + +.syntax unified +.cpu cortex-m3 +.thumb + +.section .text + +/** + * _start, program entry point + */ +.global _start +.type _start, %function +_start: + /* TODO: .ctor */ + bl main + /* TODO: .dtor */ + bl _exit + +/** + * _exit, terminate process + * \param v exit value + */ +.section .text._exit +.global _exit +.type _exit, %function +_exit: + movs r3, #2 + svc 0 + +/** + * open, open a file + * \param fd file descriptor + * \param file access mode + * \param xxx access permisions + * \return file descriptor or -1 if errors + */ +.section .text.open +.global open +.type open, %function +open: + movs r3, #6 + svc 0 + bx lr + +/** + * close, close a file + * \param fd file descriptor + */ +.section .text.close +.global close +.type close, %function +close: + movs r3, #7 + svc 0 + bx lr + +/** + * lseek + * \param fd file descriptor + * \param pos moving offset + * \param start position, SEEK_SET, SEEK_CUR or SEEK_END + +.section .text.lseek +.global lseek +.type lseek, %function + + movs r3, #8 + svc 0 + bx lr +*/ + +/** + * system, fork and execture a program, blocking + * \param program to execute + */ +.section .text.system +.global system +.type system, %function +system: + movs r3, #9 + svc 0 + bx lr +/** + * write, write to file + * \param fd file descriptor + * \param buf data to be written + * \param len buffer length + * \return number of written bytes or -1 if errors + */ +.section .text.write +.global write +.type write, %function +write: + movs r3, #3 + svc 0 + bx lr + +/** + * read, read from file + * \param fd file descriptor + * \param buf data to be read + * \param len buffer length + * \return number of read bytes or -1 if errors + */ +.section .text.read +.global read +.type read, %function +read: + movs r3, #4 + svc 0 + bx lr + +/** + * usleep, sleep a specified number of microseconds + * \param us number of microseconds to sleep + * \return 0 on success or -1 if errors + */ +.section .text.usleep +.global usleep +.type usleep, %function +usleep: + movs r3, #5 + svc 0 + bx lr + +.end diff --git a/app_mpu_test/test2/includes.h b/app_mpu_test/test2/includes.h new file mode 100644 index 0000000000000000000000000000000000000000..3bb3cba397f7634d677c6d1f1547f79700a518ed --- /dev/null +++ b/app_mpu_test/test2/includes.h @@ -0,0 +1,4 @@ +#include "app_mpu_test/test2.h" +#endif //_APP_MPU_TESTS_ +#include "app_mpu_test/test2.h" +#endif //_APP_MPU_TESTS_ diff --git a/app_mpu_test/test2/main.c b/app_mpu_test/test2/main.c new file mode 100644 index 0000000000000000000000000000000000000000..a59e604038d179b36aab09e0f0ea4671c013a7a8 --- /dev/null +++ b/app_mpu_test/test2/main.c @@ -0,0 +1,12 @@ +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> + +int main() +{ + return 0; +} diff --git a/app_mpu_test/test2/miosix.ld b/app_mpu_test/test2/miosix.ld new file mode 100644 index 0000000000000000000000000000000000000000..c91c803e629040b14233a8f8251a7d9952f68910 --- /dev/null +++ b/app_mpu_test/test2/miosix.ld @@ -0,0 +1,66 @@ +/* + * Linker script for writing PROGRAMS for the Miosix embedded OS + * TFT:Terraneo Federico Technlogies + */ + +OUTPUT_FORMAT("elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(_start) + +SECTIONS +{ + /* Here starts the first elf segment, that stays in flash */ + . = 0 + SIZEOF_HEADERS; + + .text : ALIGN(8) + { + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + } + + .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } + .rel.got : { *(.rel.got) } + + /* Here starts the second segment, that is copied in RAM and relocated */ + . = 0x10000000; + + .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } + + /* FIXME: If this is put in the other segment, it makes it writable */ + .dynamic : { *(.dynamic) } + + /* FIXME: The compiler insists in addressing rodata relative to r9 */ + .rodata : ALIGN(8) + { + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + } + + .data : ALIGN(8) + { + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + } + + .bss : ALIGN(8) + { + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + } + + /* These are removed since are unused and increase binary size */ + /DISCARD/ : + { + *(.interp) + *(.dynsym) + *(.dynstr) + *(.hash) + *(.comment) + *(.ARM.attributes) + } +} diff --git a/app_template/main.c b/app_template/main.c index 8890d5a8a408148836901d736db8faa613e23f3e..e5889bd459df9938ea57c3d6e75b4431f363ebdb 100644 --- a/app_template/main.c +++ b/app_template/main.c @@ -20,24 +20,7 @@ int main() static const char str[]="Test application:\n0=divzero\n1=sleep 5s\n2=exit\n3=bkpt\n4=dangling\n5=open\n6=system\n"; static const char str2[]="Unexpected command\n"; static const char okMsg[] = "Everything's shiny, Cap'n\n"; - - - char strTest[1500] = {'a'}; - - strTest[0] = 0; - - //void *ptr = malloc(10000); - - int c = (int)strTest[0]; - - unsigned int *p = &i; - - p -= 10; - - *p = 0x00; - - //return 0; - + for(;;) { char result[100]; diff --git a/main.cpp b/main.cpp index 27b83cd5cba105ad2c1116faec7e29d3325ec7be..c11b63e18d905dcd0f432f16fefc170a170fcbfb 100644 --- a/main.cpp +++ b/main.cpp @@ -8,8 +8,6 @@ #include "app_template/prog3.h" -#include "system_app_test/prog3.h" - using namespace std; using namespace miosix; @@ -28,11 +26,11 @@ int main() { Thread::create(ledThread,STACK_MIN); - SystemMap::instance().addElfProgram("test", reinterpret_cast<const unsigned int*>(test_elf), test_elf_len); + //SystemMap::instance().addElfProgram("test", reinterpret_cast<const unsigned int*>(test_elf), test_elf_len); - iprintf("SystemMap::size: %d\n", SystemMap::instance().getElfCount()); - std::pair<const unsigned int*, unsigned int> res = SystemMap::instance().getElfProgram("test"); - iprintf("SystemMap test entry size: %X %d\n", res.first, res.second); + //iprintf("SystemMap::size: %d\n", SystemMap::instance().getElfCount()); + //std::pair<const unsigned int*, unsigned int> res = SystemMap::instance().getElfProgram("test"); + //iprintf("SystemMap test entry size: %X %d\n", res.first, res.second); ElfProgram prog(reinterpret_cast<const unsigned int*>(main_elf),main_elf_len); for(int i=0;;i++)