diff --git a/Makefile b/Makefile index c665a793f23c581aa0c244def5b0027b35ad8462..3e615d0e76d932f2d05158f3a552b89e84039252 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,7 @@ SUBDIRS := miosix ## List here your source files (both .s, .c and .cpp) ## SRC := \ -./miosix/testsuite/testsuite.cpp -#main.cpp +main.cpp ## ## List here additional static libraries with relative path diff --git a/mpu_testsuite/mpu_apps/test1/main.c b/mpu_testsuite/mpu_apps/test1/main.c index 4920d0ffe4cbb44a675ae71f493797323163227c..a528da39061aa7bbd05b705d523f19c148b1422d 100644 --- a/mpu_testsuite/mpu_apps/test1/main.c +++ b/mpu_testsuite/mpu_apps/test1/main.c @@ -7,19 +7,7 @@ #include <stdio.h> int main(){ - //int x[64 * 1024]; - // - //int i = 123; - //unsigned int *p = &i; - // - //p = p - 1; - //*p = 567; - - volatile unsigned int *pointer = 0x63F00000;// + 0xFFFF; + volatile unsigned int *pointer = 0x64100400; *pointer = 456; - //if(*pointer == 456) write(1, "Ok\n", 3); - //write(1, okMsg2, mystrlen(okMsg2)); - - return 123; } diff --git a/mpu_testsuite/mpu_apps/test3/Makefile b/mpu_testsuite/mpu_apps/test3/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..994dae769111406b691bede0d34d103f82607323 --- /dev/null +++ b/mpu_testsuite/mpu_apps/test3/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/mpu_testsuite/mpu_apps/test3/crt0.s b/mpu_testsuite/mpu_apps/test3/crt0.s new file mode 100644 index 0000000000000000000000000000000000000000..7733008e9392ded796006a94a0c1a527a94bfc1a --- /dev/null +++ b/mpu_testsuite/mpu_apps/test3/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/mpu_testsuite/mpu_apps/test3/main.c b/mpu_testsuite/mpu_apps/test3/main.c new file mode 100644 index 0000000000000000000000000000000000000000..4920d0ffe4cbb44a675ae71f493797323163227c --- /dev/null +++ b/mpu_testsuite/mpu_apps/test3/main.c @@ -0,0 +1,25 @@ +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> + +int main(){ + //int x[64 * 1024]; + // + //int i = 123; + //unsigned int *p = &i; + // + //p = p - 1; + //*p = 567; + + volatile unsigned int *pointer = 0x63F00000;// + 0xFFFF; + *pointer = 456; + //if(*pointer == 456) write(1, "Ok\n", 3); + //write(1, okMsg2, mystrlen(okMsg2)); + + + return 123; +} diff --git a/mpu_testsuite/mpu_apps/test3/miosix.ld b/mpu_testsuite/mpu_apps/test3/miosix.ld new file mode 100644 index 0000000000000000000000000000000000000000..c91c803e629040b14233a8f8251a7d9952f68910 --- /dev/null +++ b/mpu_testsuite/mpu_apps/test3/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/mpu_testsuite/mpu_testsuite.cpp b/mpu_testsuite/mpu_testsuite.cpp index 55da32e0b5799c29c6e368e7a86dbfd5cf17f593..2f93bdc6ae50d890230ef88c05ce309cfc123fe7 100644 --- a/mpu_testsuite/mpu_testsuite.cpp +++ b/mpu_testsuite/mpu_testsuite.cpp @@ -4,6 +4,7 @@ #include <stdexcept> #include "miosix.h" #include "kernel/process.h" +#include "kernel/process_pool.h" //Include the test programs #include "mpu_testsuite/altered_elfs/includes.h" @@ -14,9 +15,12 @@ using namespace miosix; void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length); void runMpuTest(const char *name, const unsigned char *filename, unsigned int file_length); +void allocationTest(); int main() { + allocationTest(); + // Altered elfs tests iprintf("\nExecuting ELF tests.\n"); iprintf("--------------------\n"); @@ -80,8 +84,8 @@ int main() // Direct mpu tests iprintf("\n\nExecuting MPU tests.\n"); iprintf("---------------------\n"); - runMpuTest("Test7", test1_elf, test1_elf_len); - runMpuTest("Test8", test2_elf, test2_elf_len); + runMpuTest("Test7", test2_elf, test2_elf_len); + runMpuTest("Test8", test3_elf, test3_elf_len); } void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length) @@ -108,3 +112,23 @@ void runMpuTest(const char *name, const unsigned char *filename, unsigned int fi if(WTERMSIG(ec)==SIGSEGV) iprintf("passed!\n"); } } + +void allocationTest() +{ + iprintf("Executing Allocation test...\n"); + unsigned int *size = ProcessPool::instance().allocate(2048); + iprintf("Allocated mem pointer: %p\n", size); + 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); + if(WIFEXITED(ec)) + { + iprintf("not passed! (Exit status %d)\n", WEXITSTATUS(ec)); + } + else if(WIFSIGNALED(ec)) + { + if(WTERMSIG(ec)==SIGSEGV) iprintf("passed!\n"); + } +}