From 8de8eac87fbaa18f65593b3d9c1e1299d057094a Mon Sep 17 00:00:00 2001 From: Andrea Pontecorvo <andrea.ponte1987@gmail.com> Date: Tue, 15 Jan 2013 15:22:02 +0100 Subject: [PATCH] Added more tests, fixed others --- .directory | 3 +- Makefile | 4 +- .../common/interfaces-impl/portability.cpp | 16 ++ .../common/interfaces-impl/portability_impl.h | 1 + miosix/interfaces/portability.h | 13 ++ miosix/kernel/SystemMap.cpp | 20 +- miosix/kernel/SystemMap.h | 8 +- miosix/kernel/process.cpp | 65 +++++- miosix/testsuite/testsuite.cpp | 191 +++++++++++++++--- miosix/testsuite/testsuite_file.h | 33 --- miosix/testsuite/testsuite_file/main.c | 39 ---- miosix/testsuite/testsuite_file/prog3.h | 33 --- miosix/testsuite/testsuite_file/test.txt | 151 -------------- miosix/testsuite/testsuite_file1.h | 34 ++-- miosix/testsuite/testsuite_file1/main.c | 59 +++++- miosix/testsuite/testsuite_file1/prog3.h | 34 ++-- miosix/testsuite/testsuite_file1/test.txt | 128 ++++++------ miosix/testsuite/testsuite_file2.h | 34 ++-- miosix/testsuite/testsuite_file2/main.c | 59 +++++- miosix/testsuite/testsuite_file2/prog3.h | 34 ++-- miosix/testsuite/testsuite_file2/test.txt | 128 ++++++------ miosix/testsuite/testsuite_simple/main.c | 1 + miosix/testsuite/testsuite_syscall/main.c | 17 +- miosix/testsuite/testsuite_syscall_mpu.h | 24 +++ miosix/testsuite/testsuite_syscall_mpu_open.h | 24 +++ .../Makefile | 3 +- .../crt0.s | 0 .../testsuite_syscall_mpu_open/main.c | 13 ++ .../miosix.ld | 0 .../testsuite_syscall_mpu_open/prog3.h | 24 +++ .../testsuite_syscall_mpu_open/test.txt | 91 +++++++++ miosix/testsuite/testsuite_syscall_mpu_read.h | 26 +++ .../testsuite_syscall_mpu_read/Makefile | 45 +++++ .../testsuite_syscall_mpu_read/crt0.s | 131 ++++++++++++ .../testsuite_syscall_mpu_read/main.c | 15 ++ .../testsuite_syscall_mpu_read/miosix.ld | 66 ++++++ .../testsuite_syscall_mpu_read/prog3.h | 26 +++ .../testsuite_syscall_mpu_read/test.txt | 115 +++++++++++ .../testsuite/testsuite_syscall_mpu_write.h | 26 +++ .../testsuite_syscall_mpu_write/Makefile | 45 +++++ .../testsuite_syscall_mpu_write/crt0.s | 131 ++++++++++++ .../testsuite_syscall_mpu_write/main.c | 15 ++ .../testsuite_syscall_mpu_write/miosix.ld | 66 ++++++ .../testsuite_syscall_mpu_write/prog3.h | 26 +++ .../testsuite_syscall_mpu_write/test.txt | 115 +++++++++++ miosix/testsuite/testsuite_system.h | 25 +++ miosix/testsuite/testsuite_system/Makefile | 45 +++++ miosix/testsuite/testsuite_system/crt0.s | 130 ++++++++++++ miosix/testsuite/testsuite_system/main.c | 12 ++ miosix/testsuite/testsuite_system/miosix.ld | 66 ++++++ miosix/testsuite/testsuite_system/prog3.h | 25 +++ miosix/testsuite/testsuite_system/test.txt | 101 +++++++++ .../nbproject/configurations.xml | 102 +++++++++- 53 files changed, 2116 insertions(+), 522 deletions(-) delete mode 100644 miosix/testsuite/testsuite_file.h delete mode 100644 miosix/testsuite/testsuite_file/main.c delete mode 100644 miosix/testsuite/testsuite_file/prog3.h delete mode 100644 miosix/testsuite/testsuite_file/test.txt create mode 100644 miosix/testsuite/testsuite_syscall_mpu.h create mode 100644 miosix/testsuite/testsuite_syscall_mpu_open.h rename miosix/testsuite/{testsuite_file => testsuite_syscall_mpu_open}/Makefile (89%) rename miosix/testsuite/{testsuite_file => testsuite_syscall_mpu_open}/crt0.s (100%) create mode 100644 miosix/testsuite/testsuite_syscall_mpu_open/main.c rename miosix/testsuite/{testsuite_file => testsuite_syscall_mpu_open}/miosix.ld (100%) create mode 100644 miosix/testsuite/testsuite_syscall_mpu_open/prog3.h create mode 100644 miosix/testsuite/testsuite_syscall_mpu_open/test.txt create mode 100644 miosix/testsuite/testsuite_syscall_mpu_read.h create mode 100644 miosix/testsuite/testsuite_syscall_mpu_read/Makefile create mode 100644 miosix/testsuite/testsuite_syscall_mpu_read/crt0.s create mode 100644 miosix/testsuite/testsuite_syscall_mpu_read/main.c create mode 100644 miosix/testsuite/testsuite_syscall_mpu_read/miosix.ld create mode 100644 miosix/testsuite/testsuite_syscall_mpu_read/prog3.h create mode 100644 miosix/testsuite/testsuite_syscall_mpu_read/test.txt create mode 100644 miosix/testsuite/testsuite_syscall_mpu_write.h create mode 100644 miosix/testsuite/testsuite_syscall_mpu_write/Makefile create mode 100644 miosix/testsuite/testsuite_syscall_mpu_write/crt0.s create mode 100644 miosix/testsuite/testsuite_syscall_mpu_write/main.c create mode 100644 miosix/testsuite/testsuite_syscall_mpu_write/miosix.ld create mode 100644 miosix/testsuite/testsuite_syscall_mpu_write/prog3.h create mode 100644 miosix/testsuite/testsuite_syscall_mpu_write/test.txt create mode 100644 miosix/testsuite/testsuite_system.h create mode 100644 miosix/testsuite/testsuite_system/Makefile create mode 100644 miosix/testsuite/testsuite_system/crt0.s create mode 100644 miosix/testsuite/testsuite_system/main.c create mode 100644 miosix/testsuite/testsuite_system/miosix.ld create mode 100644 miosix/testsuite/testsuite_system/prog3.h create mode 100644 miosix/testsuite/testsuite_system/test.txt diff --git a/.directory b/.directory index caec0434..51b4d802 100644 --- a/.directory +++ b/.directory @@ -1,3 +1,4 @@ [Dolphin] -Timestamp=2013,1,8,14,55,19 +PreviewsShown=true +Timestamp=2013,1,10,14,48,3 Version=3 diff --git a/Makefile b/Makefile index 3e615d0e..5a131363 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,9 @@ SUBDIRS := miosix ## List here your source files (both .s, .c and .cpp) ## SRC := \ -main.cpp +miosix/testsuite/testsuite.cpp +#main.cpp + ## ## List here additional static libraries with relative path diff --git a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp index fdfb9264..47d2f0ad 100644 --- a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp +++ b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp @@ -300,6 +300,22 @@ void MPUConfiguration::dumpConfiguration() } } +bool MPUConfiguration::within(const unsigned int ptr) const { + + unsigned int base = regValues[2] & (~0x1f); + unsigned int end = base + (1 << (((regValues[3] >> 1) & 31) + 1)); + + return ptr >= base && ptr < end; +} + +unsigned int MPUConfiguration::getBaseDataAddress() const { + return regValues[2] & (~0x1f); +} + +unsigned int MPUConfiguration::getDataSize() const { + return (1 << (((regValues[3] >> 1) & 31) + 1)); +} + #endif //WITH_PROCESSES void IRQportableStartKernel() diff --git a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h index 63af6584..47c48a26 100644 --- a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h +++ b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h @@ -194,6 +194,7 @@ inline void MPUConfiguration::IRQdisable() __set_CONTROL(2); } + #endif //WITH_PROCESSES /** diff --git a/miosix/interfaces/portability.h b/miosix/interfaces/portability.h index 6d30928a..b9ce7fc8 100644 --- a/miosix/interfaces/portability.h +++ b/miosix/interfaces/portability.h @@ -261,6 +261,19 @@ class MPUConfiguration * Print the MPU configuration for debugging purposes */ void dumpConfiguration(); + + /** + * Check if the address is within the data segment + * @param ptr the addresso of the pointer + * @return true if the pointer points within the data segment, false otherwise. + */ + bool within(const unsigned int ptr) const; + + /** + * \internal + */ + unsigned int getBaseDataAddress() const; + unsigned int getDataSize() const; //Uses default copy constructor and operator= private: diff --git a/miosix/kernel/SystemMap.cpp b/miosix/kernel/SystemMap.cpp index 2d76507e..6cb534c4 100644 --- a/miosix/kernel/SystemMap.cpp +++ b/miosix/kernel/SystemMap.cpp @@ -27,15 +27,22 @@ SystemMap &SystemMap::instance(){ return *pSingleton; } -void SystemMap::addElfProgram(const char* name, const unsigned int *elf, unsigned int size){ - unsigned int hash = hashString(name); +void SystemMap::addElfProgram(const char* name, const unsigned int *elf, unsigned int size){ + string sName(name); + if(mPrograms.find(sName) == mPrograms.end()) + mPrograms.insert(make_pair(sName, make_pair(elf, size))); +} + +void SystemMap::removeElfProgram(const char* name){ + string sName(name); + ProgramsMap::iterator it = mPrograms.find(sName); - if(mPrograms.find(hash) == mPrograms.end()) - mPrograms.insert(make_pair(hash, make_pair(elf, size))); + if(it != mPrograms.end()) + mPrograms.erase(it); } pair<const unsigned int*, unsigned int> SystemMap::getElfProgram(const char* name) const { - ProgramsMap::const_iterator it = mPrograms.find(hashString(name)); + ProgramsMap::const_iterator it = mPrograms.find(string(name)); if(it == mPrograms.end()) return make_pair<const unsigned int*, unsigned int>(0, 0); @@ -47,7 +54,7 @@ unsigned int SystemMap::getElfCount() const{ return mPrograms.size(); } -unsigned int SystemMap::hashString(const char* pStr) const { +/*unsigned int SystemMap::hashString(const char* pStr) const { unsigned int hash = 0; for(; *pStr != '\0'; ++pStr){ @@ -62,5 +69,6 @@ unsigned int SystemMap::hashString(const char* pStr) const { return hash; } +*/ } \ No newline at end of file diff --git a/miosix/kernel/SystemMap.h b/miosix/kernel/SystemMap.h index 1e82ed0b..34212cb7 100644 --- a/miosix/kernel/SystemMap.h +++ b/miosix/kernel/SystemMap.h @@ -4,6 +4,7 @@ #include "kernel/sync.h" #include <map> +#include <string> namespace miosix { @@ -16,16 +17,15 @@ public: //Privata ? and friendly void addElfProgram(const char *name, const unsigned int *elf, unsigned int size); + void removeElfProgram(const char *name); std::pair<const unsigned int*, unsigned int> getElfProgram(const char *name) const; unsigned int getElfCount() const; -private: - unsigned int hashString(const char *pStr) const; - +private: SystemMap(const SystemMap& orig); - typedef std::map<unsigned int, std::pair<const unsigned int*, unsigned int> > ProgramsMap; + typedef std::map<std::string, std::pair<const unsigned int*, unsigned int> > ProgramsMap; ProgramsMap mPrograms; }; diff --git a/miosix/kernel/process.cpp b/miosix/kernel/process.cpp index 469b3078..cfdb1d3a 100644 --- a/miosix/kernel/process.cpp +++ b/miosix/kernel/process.cpp @@ -29,8 +29,11 @@ #include <memory> #include <cstdio> #include <cstring> +#include <algorithm> #include <sys/wait.h> #include <signal.h> +#include <limits.h> + #include "sync.h" #include "process_pool.h" #include "process.h" @@ -307,15 +310,43 @@ void *Process::start(void *argv) break; case 3: //FIXME: check that the pointer belongs to the process - sp.setReturnValue(write(sp.getFirstParameter(), - reinterpret_cast<const char*>(sp.getSecondParameter()), - sp.getThirdParameter())); + + if((sp.getFirstParameter() >= 0 && sp.getFirstParameter() < 3) || //stdio + proc->mFiles.find(sp.getFirstParameter()) != proc->mFiles.end()){ //only on my files + + //check if pointer and pointer + size is within the mpu data region + if(!proc->mpu.within(sp.getSecondParameter()) || + !proc->mpu.within(sp.getSecondParameter() + sp.getThirdParameter())){ + running = false; + proc->exitCode = SIGSYS; + break; + } + + sp.setReturnValue(write(sp.getFirstParameter(), + reinterpret_cast<const char*>(sp.getSecondParameter()), + sp.getThirdParameter())); + } else + sp.setReturnValue(-1); + break; - case 4: - //FIXME: check that the pointer belongs to the process - sp.setReturnValue(read(sp.getFirstParameter(), - reinterpret_cast<char*>(sp.getSecondParameter()), - sp.getThirdParameter())); + case 4: + if((sp.getFirstParameter() >= 0 && sp.getFirstParameter() < 3) || //stdio + proc->mFiles.find(sp.getFirstParameter())!= proc->mFiles.end()){ //only on my files + + //check if pointer and pointer + size is within the mpu data region + if(!proc->mpu.within(sp.getSecondParameter()) || + !proc->mpu.within(sp.getSecondParameter() + sp.getThirdParameter())){ + running = false; + proc->exitCode = SIGSYS; + break; + } + + sp.setReturnValue(read(sp.getFirstParameter(), + reinterpret_cast<char*>(sp.getSecondParameter()), + sp.getThirdParameter())); + } else + sp.setReturnValue(-1); + break; case 5: sp.setReturnValue(usleep(sp.getFirstParameter())); @@ -323,6 +354,22 @@ void *Process::start(void *argv) case 6: //open { + unsigned int base = proc->mpu.getBaseDataAddress(); + unsigned int size = proc->mpu.getDataSize(); + + unsigned int maxLen = min(base + size - sp.getFirstParameter(), (unsigned int)PATH_MAX); + size_t filenameLen = strnlen(reinterpret_cast<const char*>(sp.getFirstParameter()), maxLen); + + if(!proc->mpu.within(sp.getFirstParameter()) || + !proc->mpu.within(sp.getFirstParameter() + filenameLen)){ + + proc->mpu.dumpConfiguration(); + + running = false; + proc->exitCode = SIGSYS; + break; + } + int fd = open(reinterpret_cast<const char*>(sp.getFirstParameter()), //filename sp.getSecondParameter(), //flags sp.getThirdParameter()); //permission, used? @@ -371,7 +418,7 @@ void *Process::start(void *argv) pid_t child = Process::create(program); Process::waitpid(child, &ret, 0); - sp.setReturnValue(ret); + sp.setReturnValue(WEXITSTATUS(ret)); } break; default: diff --git a/miosix/testsuite/testsuite.cpp b/miosix/testsuite/testsuite.cpp index 078de3e3..6f927227 100644 --- a/miosix/testsuite/testsuite.cpp +++ b/miosix/testsuite/testsuite.cpp @@ -51,14 +51,24 @@ #include "miosix/kernel/process.h" #ifdef WITH_PROCESSES + #include "kernel/SystemMap.h" + #include "testsuite_syscall.h" #include "testsuite_simple.h" #include "testsuite_sleep.h" - #include "testsuite_file1.h" - #include "testsuite_file2.h" + #include "testsuite_system.h" + + #ifdef WITH_FILESYSTEM + #include "testsuite_file1.h" + #include "testsuite_file2.h" + #include "testsuite_syscall_mpu_open.h" + #include "testsuite_syscall_mpu_read.h" + #include "testsuite_syscall_mpu_write.h" + #endif #endif -#define WEXITSTATUS(x) (((x) & 0xFF00) >> 8) +#include <sys/wait.h> +#include <signal.h> using namespace miosix; @@ -111,11 +121,20 @@ static void exception_test(); #endif //__NO_EXCEPTIONS #ifdef WITH_PROCESSES -void syscall_test_files(); -void syscall_test_sleep(); -void syscall_test_process_ret(); -void syscall_test_file_concurrency(); + void syscall_test_sleep(); + void process_test_process_ret(); + void syscall_test_system(); + + #ifdef WITH_FILESYSTEM + void syscall_test_files(); + void process_test_file_concurrency(); + void syscall_test_mpu_open(); + void syscall_test_mpu_read(); + void syscall_test_mpu_write(); + #endif #endif + + //main(), calls all tests int main() { @@ -203,11 +222,15 @@ int main() #ifdef WITH_PROCESSES #ifdef WITH_FILESYSTEM syscall_test_files(); + syscall_test_mpu_open(); + syscall_test_mpu_read(); + syscall_test_mpu_write(); #else iprintf("Error, filesystem support is disabled\n"); #endif syscall_test_sleep(); + syscall_test_system(); #else iprintf("Error, process support is disabled\n"); #endif @@ -216,8 +239,8 @@ int main() case 'p': #ifdef WITH_PROCESSES ledOn(); - syscall_test_process_ret(); - syscall_test_file_concurrency(); + process_test_process_ret(); + process_test_file_concurrency(); ledOff(); #endif break; @@ -259,7 +282,7 @@ static void fail(const char *cause) reboot(); } -void syscall_test_file_concurrency(){ +void process_test_file_concurrency(){ test_name("Process file concurrency"); remove("/file1.bin"); @@ -286,41 +309,50 @@ void syscall_test_file_concurrency(){ if(!f2) fail("Unable to open second file"); - char buffer1[1024] = {0}; + /*char buffer1[1024] = {0}; char buffer2[1024] = {0}; int len1 = fread(buffer1, 1, 1024, f1); int len2 = fread(buffer2, 1, 1024, f2); - iprintf("File 1: %s, len = %d\n", buffer1, len1); -; iprintf("File 2: %s, len = %d\n", buffer2, len2); + iprintf("File 1 len = %d\n", len1); + iprintf("File 2 len = %d\n", len2); - if(len1 != 9){ + if(len1 != 900){ fclose(f1); fclose(f2); fail("Wrong data size read from file 1"); } - if(len2 != 9){ + if(len2 != 900){ fclose(f1); fclose(f2); fail("Wrong data size read from file 2"); - } + }*/ - if(strncmp(buffer1, "file1.bin", len1) != 0){ - fclose(f1); - fclose(f2); - - fail("Wrong data from file 1"); - } + char buffer1[100] = {0}, + buffer2[100] = {0}; - if(strncmp(buffer2, "file2.bin", len2) != 0){ - fclose(f1); - fclose(f2); + for(int i = 0; i < 1000; i++){ + fread(buffer1, 1, 9, f1); + if(strncmp(buffer1, "file1.bin", 9) != 0){ + fclose(f1); + fclose(f2); - fail("Wrong data from file 2"); + fail("Wrong data from file 1"); + } + } + + for(int i = 0; i < 1000; i++){ + fread(buffer2, 1, 9, f2); + if(strncmp(buffer2, "file2.bin", 9) != 0){ + fclose(f1); + fclose(f2); + + fail("Wrong data from file 2"); + } } fclose(f1); @@ -329,7 +361,7 @@ void syscall_test_file_concurrency(){ pass(); } -void syscall_test_process_ret(){ +void process_test_process_ret(){ test_name("Process return value"); ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_simple_elf),testsuite_simple_elf_len); @@ -343,27 +375,122 @@ void syscall_test_process_ret(){ fail("Wrong returned value"); } +void syscall_test_mpu_open(){ + test_name("open and MPU"); + + ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_syscall_mpu_open_elf), testsuite_syscall_mpu_open_elf_len); + + int ret = 0; + pid_t p = Process::create(prog); + Process::waitpid(p, &ret, 0); + + iprintf("Returned value is %d\n", ret); + + if((ret & 0xFF) == SIGSYS) + iprintf("The invalid pointer to filename has been handled correctly.\n"); + else + fail("0x00000000 is not a valid address!"); + + pass(); +} + +void syscall_test_mpu_read(){ + test_name("read calls and MPU"); + + ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_syscall_mpu_read_elf), testsuite_syscall_mpu_read_elf_len); + + int ret = 0; + pid_t p = Process::create(prog); + Process::waitpid(p, &ret, 0); + + iprintf("Returned value is %d\n", ret); + + if((ret & 0xFF) == SIGSYS) + iprintf("The invalid buffer pointer been handled correctly.\n"); + else + fail("0x00000000 is not a valid address!"); + + pass(); +} + +void syscall_test_mpu_write(){ + test_name("write and MPU"); + + ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_syscall_mpu_write_elf), testsuite_syscall_mpu_write_elf_len); + + int ret = 0; + pid_t p = Process::create(prog); + Process::waitpid(p, &ret, 0); + + iprintf("Returned value is %d\n", ret); + + if((ret & 0xFF) == SIGSYS) + iprintf("The invalid pointer to filename has been handled correctly.\n"); + else + fail("0x00000000 is not a valid address!"); + + pass(); +} + +void syscall_test_system(){ + + if(SystemMap::instance().getElfCount() != 0) + fail("The system lookup table should be empty"); + else + iprintf("The system lookup table is empty. Correct.\n"); + + SystemMap::instance().addElfProgram("test", reinterpret_cast<const unsigned int*>(testsuite_simple_elf), testsuite_simple_elf_len); + + if(SystemMap::instance().getElfCount() != 1) + fail("Now the system lookup table should contain 1 program"); + else + iprintf("The system lookup table contain one program. Correct.\n"); + + std::pair<const unsigned int*, unsigned int> sysret = SystemMap::instance().getElfProgram("test"); + + if(sysret.first == 0 || sysret.second == 0) + fail("The system lookup table has returned an invalid process size or an invalid elf pointer for the process"); + + ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_system_elf), testsuite_system_elf_len); + + int ret = 0; + pid_t p = Process::create(prog); + Process::waitpid(p, &ret, 0); + + if(WEXITSTATUS(ret) != 42){ + iprintf("Host process returned: %d\n", WEXITSTATUS(ret)); + fail("The system inside a process has failed"); + } + + SystemMap::instance().removeElfProgram("test"); + + if(SystemMap::instance().getElfCount() != 0) + fail("The system lookup table now should be empty.\n"); + + pass(); +} + void syscall_test_sleep(){ test_name("System Call: sleep"); ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_sleep_elf),testsuite_sleep_elf_len); - iprintf("diff was: %d\n", (unsigned int)getTick()); +// iprintf("diff was: %d\n", (unsigned int)getTick()); int ret = 0; long long time = getTick(); pid_t p = Process::create(prog); Process::waitpid(p, &ret, 0); - long long diff = abs((getTick() - time)); + long long diff = llabs((getTick() - time)); - if (diff > 10) - fail("sleep"); + if (llabs(diff - 5*TICK_FREQ) > static_cast<long long>(TICK_FREQ * 0.02)) + fail("The sleep should have only a little more than 5 seconds."); pass(); } void syscall_test_files(){ - test_name("System Call: open, read, write, seek, close, sytem"); + test_name("System Call: open, read, write, seek, close, system"); ElfProgram prog(reinterpret_cast<const unsigned int*>(testsuite_syscall_elf),testsuite_syscall_elf_len); int ret = 0; diff --git a/miosix/testsuite/testsuite_file.h b/miosix/testsuite/testsuite_file.h deleted file mode 100644 index 3afa448a..00000000 --- a/miosix/testsuite/testsuite_file.h +++ /dev/null @@ -1,33 +0,0 @@ -const unsigned char __attribute__((aligned(8))) testsuite_file_elf[] = { - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, - 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, - 0x76, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x10, 0x50, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, - 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, - 0x00, 0xf0, 0x2c, 0xf8, 0xf8, 0xb5, 0x13, 0x4f, 0x00, 0x24, 0x09, 0xeb, - 0x07, 0x03, 0x13, 0xf8, 0x01, 0x5f, 0x01, 0x34, 0x00, 0x2d, 0xfa, 0xd1, - 0x0f, 0x48, 0x40, 0xf2, 0x02, 0x41, 0x48, 0x44, 0x2a, 0x46, 0x00, 0xf0, - 0x1d, 0xf8, 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x0b, 0xd0, 0x09, 0xeb, - 0x07, 0x01, 0x22, 0x46, 0x00, 0xf0, 0x1a, 0xf8, 0xa0, 0x42, 0x06, 0xd0, - 0x30, 0x46, 0x00, 0xf0, 0x12, 0xf8, 0x02, 0x20, 0xf8, 0xbd, 0x01, 0x20, - 0xfc, 0xe7, 0x30, 0x46, 0x00, 0xf0, 0x0b, 0xf8, 0x28, 0x46, 0xf7, 0xe7, - 0x38, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, - 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x07, 0x23, 0x00, 0xdf, 0x70, 0x47, - 0x03, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, - 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x61, 0x73, 0x64, 0x00, 0x74, 0x65, 0x73, 0x74, - 0x73, 0x75, 0x69, 0x74, 0x65, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x62, - 0x69, 0x6e, 0x00, 0x00 -}; -unsigned int testsuite_file_elf_len = 352; diff --git a/miosix/testsuite/testsuite_file/main.c b/miosix/testsuite/testsuite_file/main.c deleted file mode 100644 index 303edf28..00000000 --- a/miosix/testsuite/testsuite_file/main.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <unistd.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <stdio.h> - -#define error(x) (x) - -#define SIZE 1024 - -int mystrlen(const char *s){ - int result=0; - while(*s++) result++; - return result; -} - -void print(const char *s){ - write(1, s, mystrlen(s)); -} - -int main(){ - int len = mystrlen(TEST_STRING); - - int fd = open(TEST_FILE, O_RDWR|O_TRUNC, 0); - - if(fd == -1) - return 1; - - if(write(fd, TEST_STRING, len) != len){ - close(fd); - return 2; - } - - close(fd); - - return 0; -} diff --git a/miosix/testsuite/testsuite_file/prog3.h b/miosix/testsuite/testsuite_file/prog3.h deleted file mode 100644 index 3afa448a..00000000 --- a/miosix/testsuite/testsuite_file/prog3.h +++ /dev/null @@ -1,33 +0,0 @@ -const unsigned char __attribute__((aligned(8))) testsuite_file_elf[] = { - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, - 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, - 0x76, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x10, 0x50, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, - 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, - 0x00, 0xf0, 0x2c, 0xf8, 0xf8, 0xb5, 0x13, 0x4f, 0x00, 0x24, 0x09, 0xeb, - 0x07, 0x03, 0x13, 0xf8, 0x01, 0x5f, 0x01, 0x34, 0x00, 0x2d, 0xfa, 0xd1, - 0x0f, 0x48, 0x40, 0xf2, 0x02, 0x41, 0x48, 0x44, 0x2a, 0x46, 0x00, 0xf0, - 0x1d, 0xf8, 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x0b, 0xd0, 0x09, 0xeb, - 0x07, 0x01, 0x22, 0x46, 0x00, 0xf0, 0x1a, 0xf8, 0xa0, 0x42, 0x06, 0xd0, - 0x30, 0x46, 0x00, 0xf0, 0x12, 0xf8, 0x02, 0x20, 0xf8, 0xbd, 0x01, 0x20, - 0xfc, 0xe7, 0x30, 0x46, 0x00, 0xf0, 0x0b, 0xf8, 0x28, 0x46, 0xf7, 0xe7, - 0x38, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, - 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x07, 0x23, 0x00, 0xdf, 0x70, 0x47, - 0x03, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, - 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x61, 0x73, 0x64, 0x00, 0x74, 0x65, 0x73, 0x74, - 0x73, 0x75, 0x69, 0x74, 0x65, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x62, - 0x69, 0x6e, 0x00, 0x00 -}; -unsigned int testsuite_file_elf_len = 352; diff --git a/miosix/testsuite/testsuite_file/test.txt b/miosix/testsuite/testsuite_file/test.txt deleted file mode 100644 index e5a14a87..00000000 --- a/miosix/testsuite/testsuite_file/test.txt +++ /dev/null @@ -1,151 +0,0 @@ - -testsuite_file.elf: file format elf32-littlearm -testsuite_file.elf -architecture: arm, flags 0x00000050: -HAS_SYMS, DYNAMIC -start address 0x00000099 - -Program Header: - LOAD off 0x00000098 vaddr 0x00000098 paddr 0x00000098 align 2**3 - filesz 0x00000076 memsz 0x00000076 flags r-x - LOAD off 0x00000110 vaddr 0x10000000 paddr 0x10000000 align 2**3 - filesz 0x00000050 memsz 0x00000050 flags rw- - DYNAMIC off 0x0000011c vaddr 0x1000000c paddr 0x1000000c align 2**2 - filesz 0x00000028 memsz 0x00000028 flags rw- - -Dynamic Section: - DEBUG 0x00000000 -private flags = 5000002: [Version5 EABI] [has entry point] - -Sections: -Idx Name Size VMA LMA File off Algn - 0 .text 00000076 00000098 00000098 00000098 2**3 - CONTENTS, ALLOC, LOAD, READONLY, CODE - 1 .got 0000000c 10000000 10000000 00000110 2**2 - CONTENTS, ALLOC, LOAD, DATA - 2 .dynamic 00000028 1000000c 1000000c 0000011c 2**2 - CONTENTS, ALLOC, LOAD, DATA - 3 .rodata 00000018 10000038 10000038 00000148 2**3 - CONTENTS, ALLOC, LOAD, READONLY, DATA -SYMBOL TABLE: -00000098 l d .text 00000000 .text -10000000 l d .got 00000000 .got -1000000c l d .dynamic 00000000 .dynamic -10000038 l d .rodata 00000000 .rodata -00000000 l df *ABS* 00000000 main.c -1000000c l O *ABS* 00000000 _DYNAMIC -10000000 l O *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ -00000108 g F .text 00000000 write -00000098 g F .text 00000000 _start -000000a0 g F .text 00000058 main -000000f8 g F .text 00000000 _exit -000000fc g F .text 00000000 open -00000102 g F .text 00000000 close - - -Contents of section .text: - 0098 00f002f8 00f02cf8 f8b5134f 002409eb ......,....O.$.. - 00a8 070313f8 015f0134 002dfad1 0f4840f2 ....._.4.-...H@. - 00b8 02414844 2a4600f0 1df8b0f1 ff3f0646 .AHD*F.......?.F - 00c8 0bd009eb 07012246 00f01af8 a04206d0 ......"F.....B.. - 00d8 304600f0 12f80220 f8bd0120 fce73046 0F..... ... ..0F - 00e8 00f00bf8 2846f7e7 38000000 3c000000 ....(F..8...<... - 00f8 022300df 062300df 70470723 00df7047 .#...#..pG.#..pG - 0108 032300df 7047 .#..pG -Contents of section .got: - 10000000 0c000010 00000000 00000000 ............ -Contents of section .dynamic: - 1000000c 15000000 00000000 00000000 00000000 ................ - 1000001c 00000000 00000000 00000000 00000000 ................ - 1000002c 00000000 00000000 ........ -Contents of section .rodata: - 10000038 61736400 74657374 73756974 655f6669 asd.testsuite_fi - 10000048 6c652e62 696e0000 le.bin.. - -Disassembly of section .text: - -00000098 <_start>: -_start(): - 98: f000 f802 bl a0 <main> - 9c: f000 f82c bl f8 <_exit> - -000000a0 <main>: -main(): - a0: b5f8 push {r3, r4, r5, r6, r7, lr} - a2: 4f13 ldr r7, [pc, #76] ; (f0 <main+0x50>) - a4: 2400 movs r4, #0 - a6: eb09 0307 add.w r3, r9, r7 - aa: f813 5f01 ldrb.w r5, [r3, #1]! - ae: 3401 adds r4, #1 - b0: 2d00 cmp r5, #0 - b2: d1fa bne.n aa <main+0xa> - b4: 480f ldr r0, [pc, #60] ; (f4 <main+0x54>) - b6: f240 4102 movw r1, #1026 ; 0x402 - ba: 4448 add r0, r9 - bc: 462a mov r2, r5 - be: f000 f81d bl fc <open> - c2: f1b0 3fff cmp.w r0, #4294967295 ; 0xffffffff - c6: 4606 mov r6, r0 - c8: d00b beq.n e2 <main+0x42> - ca: eb09 0107 add.w r1, r9, r7 - ce: 4622 mov r2, r4 - d0: f000 f81a bl 108 <write> - d4: 42a0 cmp r0, r4 - d6: d006 beq.n e6 <main+0x46> - d8: 4630 mov r0, r6 - da: f000 f812 bl 102 <close> - de: 2002 movs r0, #2 - e0: bdf8 pop {r3, r4, r5, r6, r7, pc} - e2: 2001 movs r0, #1 - e4: e7fc b.n e0 <main+0x40> - e6: 4630 mov r0, r6 - e8: f000 f80b bl 102 <close> - ec: 4628 mov r0, r5 - ee: e7f7 b.n e0 <main+0x40> - f0: 00000038 andeq r0, r0, r8, lsr r0 - f4: 0000003c andeq r0, r0, ip, lsr r0 - -000000f8 <_exit>: -_exit(): - f8: 2302 movs r3, #2 - fa: df00 svc 0 - -000000fc <open>: -open(): - fc: 2306 movs r3, #6 - fe: df00 svc 0 - 100: 4770 bx lr - -00000102 <close>: -close(): - 102: 2307 movs r3, #7 - 104: df00 svc 0 - 106: 4770 bx lr - -00000108 <write>: -write(): - 108: 2303 movs r3, #3 - 10a: df00 svc 0 - 10c: 4770 bx lr - -Disassembly of section .got: - -10000000 <.got>: -10000000: 1000000c andne r0, r0, ip - ... - -Disassembly of section .dynamic: - -1000000c <.dynamic>: -1000000c: 00000015 andeq r0, r0, r5, lsl r0 - ... - -Disassembly of section .rodata: - -10000038 <.rodata>: -10000038: 00647361 rsbeq r7, r4, r1, ror #6 -1000003c: 74736574 ldrbtvc r6, [r3], #-1396 ; 0x574 -10000040: 74697573 strbtvc r7, [r9], #-1395 ; 0x573 -10000044: 69665f65 stmdbvs r6!, {r0, r2, r5, r6, r8, r9, sl, fp, ip, lr}^ -10000048: 622e656c eorvs r6, lr, #452984832 ; 0x1b000000 -1000004c: 00006e69 andeq r6, r0, r9, ror #28 diff --git a/miosix/testsuite/testsuite_file1.h b/miosix/testsuite/testsuite_file1.h index c040f50b..8cc918ff 100644 --- a/miosix/testsuite/testsuite_file1.h +++ b/miosix/testsuite/testsuite_file1.h @@ -4,29 +4,29 @@ const unsigned char __attribute__((aligned(8))) testsuite_file1_elf[] = { 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, - 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, - 0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, + 0x7e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x24, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, - 0x00, 0xf0, 0x2a, 0xf8, 0xf8, 0xb5, 0x13, 0x4f, 0x00, 0x24, 0x09, 0xeb, - 0x07, 0x03, 0x13, 0xf8, 0x01, 0x5f, 0x01, 0x34, 0x00, 0x2d, 0xfa, 0xd1, - 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x2a, 0x46, 0x00, 0xf0, - 0x1b, 0xf8, 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x0a, 0xd0, 0x39, 0x46, - 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0x06, 0xd0, 0x30, 0x46, + 0x00, 0xf0, 0x30, 0xf8, 0xf8, 0xb5, 0x16, 0x4f, 0x00, 0x24, 0x09, 0xeb, + 0x07, 0x03, 0x13, 0xf8, 0x01, 0x2f, 0x01, 0x34, 0x00, 0x2a, 0xfa, 0xd1, + 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x00, 0xf0, 0x22, 0xf8, + 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x11, 0xd0, 0x4f, 0xf4, 0x7a, 0x75, + 0x02, 0xe0, 0x15, 0xf1, 0xff, 0x35, 0x0d, 0xd0, 0x30, 0x46, 0x39, 0x46, + 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0xf5, 0xd0, 0x30, 0x46, 0x00, 0xf0, 0x11, 0xf8, 0x02, 0x20, 0xf8, 0xbd, 0x01, 0x20, 0xfc, 0xe7, 0x30, 0x46, 0x00, 0xf0, 0x0a, 0xf8, 0x28, 0x46, 0xf7, 0xe7, 0x00, 0xbf, 0x38, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x07, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x03, 0x23, 0x00, 0xdf, - 0x70, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, - 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6c, 0x65, 0x31, 0x2e, 0x62, 0x69, - 0x6e, 0x00, 0x00, 0x00 + 0x70, 0x47, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x66, 0x69, 0x6c, 0x65, 0x31, 0x2e, 0x62, 0x69, 0x6e, 0x00, 0x00, 0x00 }; -unsigned int testsuite_file1_elf_len = 340; +unsigned int testsuite_file1_elf_len = 348; diff --git a/miosix/testsuite/testsuite_file1/main.c b/miosix/testsuite/testsuite_file1/main.c index 303edf28..050cb85d 100644 --- a/miosix/testsuite/testsuite_file1/main.c +++ b/miosix/testsuite/testsuite_file1/main.c @@ -20,6 +20,48 @@ void print(const char *s){ write(1, s, mystrlen(s)); } + +char *strrev(char *str, unsigned int len){ + if(str == 0 || *str == '\0') + return str; + + char tmp = 0, *p1, *p2; + for(*p1 = str, *p2 = str + len - 1; p2 > p1; ++p1, --p2){ + tmp = *p1; + *p1 = *p2; + *p2 = tmp; + } + + return str; +} + +int fast_itoa(int value, char *pBuffer){ + char *pTmp = pBuffer; + unsigned int digitCount = 0; + + if(value == 0){ + *pTmp = '0'; + return 1; + } + + if(value < 0){ + value = -value; + *pTmp++ = '-'; + ++digitCount; + } + + while(value > 0){ + *pTmp++ = (value % 10) + '0'; + value /= 10; + ++digitCount; + } + + *pTmp = '\0'; + + strrev(pBuffer, digitCount); + return digitCount; +} + int main(){ int len = mystrlen(TEST_STRING); @@ -28,9 +70,20 @@ int main(){ if(fd == -1) return 1; - if(write(fd, TEST_STRING, len) != len){ - close(fd); - return 2; + char buffer[30] = {0}; + + int i = 0; + for(i = 0; i < 1000; i++){ +/* if(i % 10 == 0){ + fast_itoa(i, buffer); + print("\nProcess 1: "); + print(buffer); + } +*/ + if(write(fd, TEST_STRING, len) != len){ + close(fd); + return 2; + } } close(fd); diff --git a/miosix/testsuite/testsuite_file1/prog3.h b/miosix/testsuite/testsuite_file1/prog3.h index c040f50b..8cc918ff 100644 --- a/miosix/testsuite/testsuite_file1/prog3.h +++ b/miosix/testsuite/testsuite_file1/prog3.h @@ -4,29 +4,29 @@ const unsigned char __attribute__((aligned(8))) testsuite_file1_elf[] = { 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, - 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, - 0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, + 0x7e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x24, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, - 0x00, 0xf0, 0x2a, 0xf8, 0xf8, 0xb5, 0x13, 0x4f, 0x00, 0x24, 0x09, 0xeb, - 0x07, 0x03, 0x13, 0xf8, 0x01, 0x5f, 0x01, 0x34, 0x00, 0x2d, 0xfa, 0xd1, - 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x2a, 0x46, 0x00, 0xf0, - 0x1b, 0xf8, 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x0a, 0xd0, 0x39, 0x46, - 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0x06, 0xd0, 0x30, 0x46, + 0x00, 0xf0, 0x30, 0xf8, 0xf8, 0xb5, 0x16, 0x4f, 0x00, 0x24, 0x09, 0xeb, + 0x07, 0x03, 0x13, 0xf8, 0x01, 0x2f, 0x01, 0x34, 0x00, 0x2a, 0xfa, 0xd1, + 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x00, 0xf0, 0x22, 0xf8, + 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x11, 0xd0, 0x4f, 0xf4, 0x7a, 0x75, + 0x02, 0xe0, 0x15, 0xf1, 0xff, 0x35, 0x0d, 0xd0, 0x30, 0x46, 0x39, 0x46, + 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0xf5, 0xd0, 0x30, 0x46, 0x00, 0xf0, 0x11, 0xf8, 0x02, 0x20, 0xf8, 0xbd, 0x01, 0x20, 0xfc, 0xe7, 0x30, 0x46, 0x00, 0xf0, 0x0a, 0xf8, 0x28, 0x46, 0xf7, 0xe7, 0x00, 0xbf, 0x38, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x07, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x03, 0x23, 0x00, 0xdf, - 0x70, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, - 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6c, 0x65, 0x31, 0x2e, 0x62, 0x69, - 0x6e, 0x00, 0x00, 0x00 + 0x70, 0x47, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x66, 0x69, 0x6c, 0x65, 0x31, 0x2e, 0x62, 0x69, 0x6e, 0x00, 0x00, 0x00 }; -unsigned int testsuite_file1_elf_len = 340; +unsigned int testsuite_file1_elf_len = 348; diff --git a/miosix/testsuite/testsuite_file1/test.txt b/miosix/testsuite/testsuite_file1/test.txt index 8a4d3185..29e18099 100644 --- a/miosix/testsuite/testsuite_file1/test.txt +++ b/miosix/testsuite/testsuite_file1/test.txt @@ -7,10 +7,10 @@ start address 0x00000099 Program Header: LOAD off 0x00000098 vaddr 0x00000098 paddr 0x00000098 align 2**3 - filesz 0x00000072 memsz 0x00000072 flags r-x - LOAD off 0x00000110 vaddr 0x10000000 paddr 0x10000000 align 2**3 + filesz 0x0000007e memsz 0x0000007e flags r-x + LOAD off 0x00000118 vaddr 0x10000000 paddr 0x10000000 align 2**3 filesz 0x00000044 memsz 0x00000044 flags rw- - DYNAMIC off 0x0000011c vaddr 0x1000000c paddr 0x1000000c align 2**2 + DYNAMIC off 0x00000124 vaddr 0x1000000c paddr 0x1000000c align 2**2 filesz 0x00000028 memsz 0x00000028 flags rw- Dynamic Section: @@ -19,13 +19,13 @@ private flags = 5000002: [Version5 EABI] [has entry point] Sections: Idx Name Size VMA LMA File off Algn - 0 .text 00000072 00000098 00000098 00000098 2**3 + 0 .text 0000007e 00000098 00000098 00000098 2**3 CONTENTS, ALLOC, LOAD, READONLY, CODE - 1 .got 0000000c 10000000 10000000 00000110 2**2 + 1 .got 0000000c 10000000 10000000 00000118 2**2 CONTENTS, ALLOC, LOAD, DATA - 2 .dynamic 00000028 1000000c 1000000c 0000011c 2**2 + 2 .dynamic 00000028 1000000c 1000000c 00000124 2**2 CONTENTS, ALLOC, LOAD, DATA - 3 .rodata 0000000c 10000038 10000038 00000148 2**3 + 3 .rodata 0000000c 10000038 10000038 00000150 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA SYMBOL TABLE: 00000098 l d .text 00000000 .text @@ -35,23 +35,23 @@ SYMBOL TABLE: 00000000 l df *ABS* 00000000 main.c 1000000c l O *ABS* 00000000 _DYNAMIC 10000000 l O *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ -00000104 g F .text 00000000 write +00000110 g F .text 00000000 write 00000098 g F .text 00000000 _start -000000a0 g F .text 00000054 main -000000f4 g F .text 00000000 _exit -000000f8 g F .text 00000000 open -000000fe g F .text 00000000 close +000000a0 g F .text 00000060 main +00000100 g F .text 00000000 _exit +00000104 g F .text 00000000 open +0000010a g F .text 00000000 close Contents of section .text: - 0098 00f002f8 00f02af8 f8b5134f 002409eb ......*....O.$.. - 00a8 070313f8 015f0134 002dfad1 4f443846 ....._.4.-..OD8F - 00b8 40f20241 2a4600f0 1bf8b0f1 ff3f0646 @..A*F.......?.F - 00c8 0ad03946 224600f0 19f8a042 06d03046 ..9F"F.....B..0F - 00d8 00f011f8 0220f8bd 0120fce7 304600f0 ..... ... ..0F.. - 00e8 0af82846 f7e700bf 38000000 022300df ..(F....8....#.. - 00f8 062300df 70470723 00df7047 032300df .#..pG.#..pG.#.. - 0108 7047 pG + 0098 00f002f8 00f030f8 f8b5164f 002409eb ......0....O.$.. + 00a8 070313f8 012f0134 002afad1 4f443846 ...../.4.*..OD8F + 00b8 40f20241 00f022f8 b0f1ff3f 064611d0 @..A.."....?.F.. + 00c8 4ff47a75 02e015f1 ff350dd0 30463946 O.zu.....5..0F9F + 00d8 224600f0 19f8a042 f5d03046 00f011f8 "F.....B..0F.... + 00e8 0220f8bd 0120fce7 304600f0 0af82846 . ... ..0F....(F + 00f8 f7e700bf 38000000 022300df 062300df ....8....#...#.. + 0108 70470723 00df7047 032300df 7047 pG.#..pG.#..pG Contents of section .got: 10000000 0c000010 00000000 00000000 ............ Contents of section .dynamic: @@ -66,66 +66,70 @@ Disassembly of section .text: 00000098 <_start>: _start(): 98: f000 f802 bl a0 <main> - 9c: f000 f82a bl f4 <_exit> + 9c: f000 f830 bl 100 <_exit> 000000a0 <main>: main(): a0: b5f8 push {r3, r4, r5, r6, r7, lr} - a2: 4f13 ldr r7, [pc, #76] ; (f0 <main+0x50>) + a2: 4f16 ldr r7, [pc, #88] ; (fc <main+0x5c>) a4: 2400 movs r4, #0 a6: eb09 0307 add.w r3, r9, r7 - aa: f813 5f01 ldrb.w r5, [r3, #1]! + aa: f813 2f01 ldrb.w r2, [r3, #1]! ae: 3401 adds r4, #1 - b0: 2d00 cmp r5, #0 + b0: 2a00 cmp r2, #0 b2: d1fa bne.n aa <main+0xa> b4: 444f add r7, r9 b6: 4638 mov r0, r7 b8: f240 4102 movw r1, #1026 ; 0x402 - bc: 462a mov r2, r5 - be: f000 f81b bl f8 <open> - c2: f1b0 3fff cmp.w r0, #4294967295 ; 0xffffffff - c6: 4606 mov r6, r0 - c8: d00a beq.n e0 <main+0x40> - ca: 4639 mov r1, r7 - cc: 4622 mov r2, r4 - ce: f000 f819 bl 104 <write> - d2: 42a0 cmp r0, r4 - d4: d006 beq.n e4 <main+0x44> - d6: 4630 mov r0, r6 - d8: f000 f811 bl fe <close> - dc: 2002 movs r0, #2 - de: bdf8 pop {r3, r4, r5, r6, r7, pc} - e0: 2001 movs r0, #1 - e2: e7fc b.n de <main+0x3e> - e4: 4630 mov r0, r6 - e6: f000 f80a bl fe <close> - ea: 4628 mov r0, r5 - ec: e7f7 b.n de <main+0x3e> - ee: bf00 nop - f0: 00000038 andeq r0, r0, r8, lsr r0 - -000000f4 <_exit>: + bc: f000 f822 bl 104 <open> + c0: f1b0 3fff cmp.w r0, #4294967295 ; 0xffffffff + c4: 4606 mov r6, r0 + c6: d011 beq.n ec <main+0x4c> + c8: f44f 757a mov.w r5, #1000 ; 0x3e8 + cc: e002 b.n d4 <main+0x34> + ce: f115 35ff adds.w r5, r5, #4294967295 ; 0xffffffff + d2: d00d beq.n f0 <main+0x50> + d4: 4630 mov r0, r6 + d6: 4639 mov r1, r7 + d8: 4622 mov r2, r4 + da: f000 f819 bl 110 <write> + de: 42a0 cmp r0, r4 + e0: d0f5 beq.n ce <main+0x2e> + e2: 4630 mov r0, r6 + e4: f000 f811 bl 10a <close> + e8: 2002 movs r0, #2 + ea: bdf8 pop {r3, r4, r5, r6, r7, pc} + ec: 2001 movs r0, #1 + ee: e7fc b.n ea <main+0x4a> + f0: 4630 mov r0, r6 + f2: f000 f80a bl 10a <close> + f6: 4628 mov r0, r5 + f8: e7f7 b.n ea <main+0x4a> + fa: bf00 nop + fc: 00000038 andeq r0, r0, r8, lsr r0 + +00000100 <_exit>: _exit(): - f4: 2302 movs r3, #2 - f6: df00 svc 0 + 100: 2302 movs r3, #2 + 102: df00 svc 0 -000000f8 <open>: +00000104 <open>: open(): - f8: 2306 movs r3, #6 - fa: df00 svc 0 - fc: 4770 bx lr + 104: 2306 movs r3, #6 + 106: df00 svc 0 + 108: 4770 bx lr -000000fe <close>: +0000010a <close>: close(): - fe: 2307 movs r3, #7 - 100: df00 svc 0 - 102: 4770 bx lr + 10a: 2307 movs r3, #7 + 10c: df00 svc 0 + 10e: 4770 bx lr -00000104 <write>: +00000110 <write>: write(): - 104: 2303 movs r3, #3 - 106: df00 svc 0 - 108: 4770 bx lr + 110: 2303 movs r3, #3 + 112: df00 svc 0 + 114: 4770 bx lr Disassembly of section .got: diff --git a/miosix/testsuite/testsuite_file2.h b/miosix/testsuite/testsuite_file2.h index f3119c34..ddab5d4c 100644 --- a/miosix/testsuite/testsuite_file2.h +++ b/miosix/testsuite/testsuite_file2.h @@ -4,29 +4,29 @@ const unsigned char __attribute__((aligned(8))) testsuite_file2_elf[] = { 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, - 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, - 0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, + 0x7e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x24, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, - 0x00, 0xf0, 0x2a, 0xf8, 0xf8, 0xb5, 0x13, 0x4f, 0x00, 0x24, 0x09, 0xeb, - 0x07, 0x03, 0x13, 0xf8, 0x01, 0x5f, 0x01, 0x34, 0x00, 0x2d, 0xfa, 0xd1, - 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x2a, 0x46, 0x00, 0xf0, - 0x1b, 0xf8, 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x0a, 0xd0, 0x39, 0x46, - 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0x06, 0xd0, 0x30, 0x46, + 0x00, 0xf0, 0x30, 0xf8, 0xf8, 0xb5, 0x16, 0x4f, 0x00, 0x24, 0x09, 0xeb, + 0x07, 0x03, 0x13, 0xf8, 0x01, 0x2f, 0x01, 0x34, 0x00, 0x2a, 0xfa, 0xd1, + 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x00, 0xf0, 0x22, 0xf8, + 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x11, 0xd0, 0x4f, 0xf4, 0x7a, 0x75, + 0x02, 0xe0, 0x15, 0xf1, 0xff, 0x35, 0x0d, 0xd0, 0x30, 0x46, 0x39, 0x46, + 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0xf5, 0xd0, 0x30, 0x46, 0x00, 0xf0, 0x11, 0xf8, 0x02, 0x20, 0xf8, 0xbd, 0x01, 0x20, 0xfc, 0xe7, 0x30, 0x46, 0x00, 0xf0, 0x0a, 0xf8, 0x28, 0x46, 0xf7, 0xe7, 0x00, 0xbf, 0x38, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x07, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x03, 0x23, 0x00, 0xdf, - 0x70, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, - 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6c, 0x65, 0x32, 0x2e, 0x62, 0x69, - 0x6e, 0x00, 0x00, 0x00 + 0x70, 0x47, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x66, 0x69, 0x6c, 0x65, 0x32, 0x2e, 0x62, 0x69, 0x6e, 0x00, 0x00, 0x00 }; -unsigned int testsuite_file2_elf_len = 340; +unsigned int testsuite_file2_elf_len = 348; diff --git a/miosix/testsuite/testsuite_file2/main.c b/miosix/testsuite/testsuite_file2/main.c index 303edf28..93f4b2d1 100644 --- a/miosix/testsuite/testsuite_file2/main.c +++ b/miosix/testsuite/testsuite_file2/main.c @@ -20,6 +20,48 @@ void print(const char *s){ write(1, s, mystrlen(s)); } + +char *strrev(char *str, unsigned int len){ + if(str == 0 || *str == '\0') + return str; + + char tmp = 0, *p1, *p2; + for(*p1 = str, *p2 = str + len - 1; p2 > p1; ++p1, --p2){ + tmp = *p1; + *p1 = *p2; + *p2 = tmp; + } + + return str; +} + +int fast_itoa(int value, char *pBuffer){ + char *pTmp = pBuffer; + unsigned int digitCount = 0; + + if(value == 0){ + *pTmp = '0'; + return 1; + } + + if(value < 0){ + value = -value; + *pTmp++ = '-'; + ++digitCount; + } + + while(value > 0){ + *pTmp++ = (value % 10) + '0'; + value /= 10; + ++digitCount; + } + + *pTmp = '\0'; + + strrev(pBuffer, digitCount); + return digitCount; +} + int main(){ int len = mystrlen(TEST_STRING); @@ -28,9 +70,20 @@ int main(){ if(fd == -1) return 1; - if(write(fd, TEST_STRING, len) != len){ - close(fd); - return 2; + char buffer[30] = {0}; + + int i = 0; + for(i = 0; i < 1000; i++){ +/* if(i % 10 == 0){ + fast_itoa(i, buffer); + print("\nProcess 2: "); + print(buffer); + } + */ + if(write(fd, TEST_STRING, len) != len){ + close(fd); + return 2; + } } close(fd); diff --git a/miosix/testsuite/testsuite_file2/prog3.h b/miosix/testsuite/testsuite_file2/prog3.h index f3119c34..ddab5d4c 100644 --- a/miosix/testsuite/testsuite_file2/prog3.h +++ b/miosix/testsuite/testsuite_file2/prog3.h @@ -4,29 +4,29 @@ const unsigned char __attribute__((aligned(8))) testsuite_file2_elf[] = { 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, - 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, - 0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, + 0x7e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x24, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, - 0x00, 0xf0, 0x2a, 0xf8, 0xf8, 0xb5, 0x13, 0x4f, 0x00, 0x24, 0x09, 0xeb, - 0x07, 0x03, 0x13, 0xf8, 0x01, 0x5f, 0x01, 0x34, 0x00, 0x2d, 0xfa, 0xd1, - 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x2a, 0x46, 0x00, 0xf0, - 0x1b, 0xf8, 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x0a, 0xd0, 0x39, 0x46, - 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0x06, 0xd0, 0x30, 0x46, + 0x00, 0xf0, 0x30, 0xf8, 0xf8, 0xb5, 0x16, 0x4f, 0x00, 0x24, 0x09, 0xeb, + 0x07, 0x03, 0x13, 0xf8, 0x01, 0x2f, 0x01, 0x34, 0x00, 0x2a, 0xfa, 0xd1, + 0x4f, 0x44, 0x38, 0x46, 0x40, 0xf2, 0x02, 0x41, 0x00, 0xf0, 0x22, 0xf8, + 0xb0, 0xf1, 0xff, 0x3f, 0x06, 0x46, 0x11, 0xd0, 0x4f, 0xf4, 0x7a, 0x75, + 0x02, 0xe0, 0x15, 0xf1, 0xff, 0x35, 0x0d, 0xd0, 0x30, 0x46, 0x39, 0x46, + 0x22, 0x46, 0x00, 0xf0, 0x19, 0xf8, 0xa0, 0x42, 0xf5, 0xd0, 0x30, 0x46, 0x00, 0xf0, 0x11, 0xf8, 0x02, 0x20, 0xf8, 0xbd, 0x01, 0x20, 0xfc, 0xe7, 0x30, 0x46, 0x00, 0xf0, 0x0a, 0xf8, 0x28, 0x46, 0xf7, 0xe7, 0x00, 0xbf, 0x38, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x07, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x03, 0x23, 0x00, 0xdf, - 0x70, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, - 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6c, 0x65, 0x32, 0x2e, 0x62, 0x69, - 0x6e, 0x00, 0x00, 0x00 + 0x70, 0x47, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x66, 0x69, 0x6c, 0x65, 0x32, 0x2e, 0x62, 0x69, 0x6e, 0x00, 0x00, 0x00 }; -unsigned int testsuite_file2_elf_len = 340; +unsigned int testsuite_file2_elf_len = 348; diff --git a/miosix/testsuite/testsuite_file2/test.txt b/miosix/testsuite/testsuite_file2/test.txt index 1a481986..f7d07106 100644 --- a/miosix/testsuite/testsuite_file2/test.txt +++ b/miosix/testsuite/testsuite_file2/test.txt @@ -7,10 +7,10 @@ start address 0x00000099 Program Header: LOAD off 0x00000098 vaddr 0x00000098 paddr 0x00000098 align 2**3 - filesz 0x00000072 memsz 0x00000072 flags r-x - LOAD off 0x00000110 vaddr 0x10000000 paddr 0x10000000 align 2**3 + filesz 0x0000007e memsz 0x0000007e flags r-x + LOAD off 0x00000118 vaddr 0x10000000 paddr 0x10000000 align 2**3 filesz 0x00000044 memsz 0x00000044 flags rw- - DYNAMIC off 0x0000011c vaddr 0x1000000c paddr 0x1000000c align 2**2 + DYNAMIC off 0x00000124 vaddr 0x1000000c paddr 0x1000000c align 2**2 filesz 0x00000028 memsz 0x00000028 flags rw- Dynamic Section: @@ -19,13 +19,13 @@ private flags = 5000002: [Version5 EABI] [has entry point] Sections: Idx Name Size VMA LMA File off Algn - 0 .text 00000072 00000098 00000098 00000098 2**3 + 0 .text 0000007e 00000098 00000098 00000098 2**3 CONTENTS, ALLOC, LOAD, READONLY, CODE - 1 .got 0000000c 10000000 10000000 00000110 2**2 + 1 .got 0000000c 10000000 10000000 00000118 2**2 CONTENTS, ALLOC, LOAD, DATA - 2 .dynamic 00000028 1000000c 1000000c 0000011c 2**2 + 2 .dynamic 00000028 1000000c 1000000c 00000124 2**2 CONTENTS, ALLOC, LOAD, DATA - 3 .rodata 0000000c 10000038 10000038 00000148 2**3 + 3 .rodata 0000000c 10000038 10000038 00000150 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA SYMBOL TABLE: 00000098 l d .text 00000000 .text @@ -35,23 +35,23 @@ SYMBOL TABLE: 00000000 l df *ABS* 00000000 main.c 1000000c l O *ABS* 00000000 _DYNAMIC 10000000 l O *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ -00000104 g F .text 00000000 write +00000110 g F .text 00000000 write 00000098 g F .text 00000000 _start -000000a0 g F .text 00000054 main -000000f4 g F .text 00000000 _exit -000000f8 g F .text 00000000 open -000000fe g F .text 00000000 close +000000a0 g F .text 00000060 main +00000100 g F .text 00000000 _exit +00000104 g F .text 00000000 open +0000010a g F .text 00000000 close Contents of section .text: - 0098 00f002f8 00f02af8 f8b5134f 002409eb ......*....O.$.. - 00a8 070313f8 015f0134 002dfad1 4f443846 ....._.4.-..OD8F - 00b8 40f20241 2a4600f0 1bf8b0f1 ff3f0646 @..A*F.......?.F - 00c8 0ad03946 224600f0 19f8a042 06d03046 ..9F"F.....B..0F - 00d8 00f011f8 0220f8bd 0120fce7 304600f0 ..... ... ..0F.. - 00e8 0af82846 f7e700bf 38000000 022300df ..(F....8....#.. - 00f8 062300df 70470723 00df7047 032300df .#..pG.#..pG.#.. - 0108 7047 pG + 0098 00f002f8 00f030f8 f8b5164f 002409eb ......0....O.$.. + 00a8 070313f8 012f0134 002afad1 4f443846 ...../.4.*..OD8F + 00b8 40f20241 00f022f8 b0f1ff3f 064611d0 @..A.."....?.F.. + 00c8 4ff47a75 02e015f1 ff350dd0 30463946 O.zu.....5..0F9F + 00d8 224600f0 19f8a042 f5d03046 00f011f8 "F.....B..0F.... + 00e8 0220f8bd 0120fce7 304600f0 0af82846 . ... ..0F....(F + 00f8 f7e700bf 38000000 022300df 062300df ....8....#...#.. + 0108 70470723 00df7047 032300df 7047 pG.#..pG.#..pG Contents of section .got: 10000000 0c000010 00000000 00000000 ............ Contents of section .dynamic: @@ -66,66 +66,70 @@ Disassembly of section .text: 00000098 <_start>: _start(): 98: f000 f802 bl a0 <main> - 9c: f000 f82a bl f4 <_exit> + 9c: f000 f830 bl 100 <_exit> 000000a0 <main>: main(): a0: b5f8 push {r3, r4, r5, r6, r7, lr} - a2: 4f13 ldr r7, [pc, #76] ; (f0 <main+0x50>) + a2: 4f16 ldr r7, [pc, #88] ; (fc <main+0x5c>) a4: 2400 movs r4, #0 a6: eb09 0307 add.w r3, r9, r7 - aa: f813 5f01 ldrb.w r5, [r3, #1]! + aa: f813 2f01 ldrb.w r2, [r3, #1]! ae: 3401 adds r4, #1 - b0: 2d00 cmp r5, #0 + b0: 2a00 cmp r2, #0 b2: d1fa bne.n aa <main+0xa> b4: 444f add r7, r9 b6: 4638 mov r0, r7 b8: f240 4102 movw r1, #1026 ; 0x402 - bc: 462a mov r2, r5 - be: f000 f81b bl f8 <open> - c2: f1b0 3fff cmp.w r0, #4294967295 ; 0xffffffff - c6: 4606 mov r6, r0 - c8: d00a beq.n e0 <main+0x40> - ca: 4639 mov r1, r7 - cc: 4622 mov r2, r4 - ce: f000 f819 bl 104 <write> - d2: 42a0 cmp r0, r4 - d4: d006 beq.n e4 <main+0x44> - d6: 4630 mov r0, r6 - d8: f000 f811 bl fe <close> - dc: 2002 movs r0, #2 - de: bdf8 pop {r3, r4, r5, r6, r7, pc} - e0: 2001 movs r0, #1 - e2: e7fc b.n de <main+0x3e> - e4: 4630 mov r0, r6 - e6: f000 f80a bl fe <close> - ea: 4628 mov r0, r5 - ec: e7f7 b.n de <main+0x3e> - ee: bf00 nop - f0: 00000038 andeq r0, r0, r8, lsr r0 - -000000f4 <_exit>: + bc: f000 f822 bl 104 <open> + c0: f1b0 3fff cmp.w r0, #4294967295 ; 0xffffffff + c4: 4606 mov r6, r0 + c6: d011 beq.n ec <main+0x4c> + c8: f44f 757a mov.w r5, #1000 ; 0x3e8 + cc: e002 b.n d4 <main+0x34> + ce: f115 35ff adds.w r5, r5, #4294967295 ; 0xffffffff + d2: d00d beq.n f0 <main+0x50> + d4: 4630 mov r0, r6 + d6: 4639 mov r1, r7 + d8: 4622 mov r2, r4 + da: f000 f819 bl 110 <write> + de: 42a0 cmp r0, r4 + e0: d0f5 beq.n ce <main+0x2e> + e2: 4630 mov r0, r6 + e4: f000 f811 bl 10a <close> + e8: 2002 movs r0, #2 + ea: bdf8 pop {r3, r4, r5, r6, r7, pc} + ec: 2001 movs r0, #1 + ee: e7fc b.n ea <main+0x4a> + f0: 4630 mov r0, r6 + f2: f000 f80a bl 10a <close> + f6: 4628 mov r0, r5 + f8: e7f7 b.n ea <main+0x4a> + fa: bf00 nop + fc: 00000038 andeq r0, r0, r8, lsr r0 + +00000100 <_exit>: _exit(): - f4: 2302 movs r3, #2 - f6: df00 svc 0 + 100: 2302 movs r3, #2 + 102: df00 svc 0 -000000f8 <open>: +00000104 <open>: open(): - f8: 2306 movs r3, #6 - fa: df00 svc 0 - fc: 4770 bx lr + 104: 2306 movs r3, #6 + 106: df00 svc 0 + 108: 4770 bx lr -000000fe <close>: +0000010a <close>: close(): - fe: 2307 movs r3, #7 - 100: df00 svc 0 - 102: 4770 bx lr + 10a: 2307 movs r3, #7 + 10c: df00 svc 0 + 10e: 4770 bx lr -00000104 <write>: +00000110 <write>: write(): - 104: 2303 movs r3, #3 - 106: df00 svc 0 - 108: 4770 bx lr + 110: 2303 movs r3, #3 + 112: df00 svc 0 + 114: 4770 bx lr Disassembly of section .got: diff --git a/miosix/testsuite/testsuite_simple/main.c b/miosix/testsuite/testsuite_simple/main.c index 7ccc8c5f..00ea56a6 100644 --- a/miosix/testsuite/testsuite_simple/main.c +++ b/miosix/testsuite/testsuite_simple/main.c @@ -5,6 +5,7 @@ #include <fcntl.h> #include <string.h> #include <stdio.h> +#include <stdlib.h> int main(){ return RETURN_VALUE; diff --git a/miosix/testsuite/testsuite_syscall/main.c b/miosix/testsuite/testsuite_syscall/main.c index 05f48659..042e8da8 100644 --- a/miosix/testsuite/testsuite_syscall/main.c +++ b/miosix/testsuite/testsuite_syscall/main.c @@ -6,6 +6,7 @@ #include <string.h> #include <stdio.h> + #define error(x) (x) #define SIZE 1024 @@ -24,7 +25,7 @@ void print(const char *s){ int main(){ unsigned char buffer[SIZE], - buffer2[SIZE]; + buffer2[SIZE]; int i = 0; int fd = 0; @@ -55,19 +56,19 @@ int main(){ return error(4); print("Write file: Passed\n"); - + seek(fd, SEEK_SET, 0); - + if(read(fd, buffer2, SIZE) != SIZE) return error(5); - + for(i = 0; i < SIZE; i++){ if(buffer[i] != buffer2[i]) return error(6); } print("Read: Passed\n"); - + if(close(fd) != 0) return error(7); @@ -79,10 +80,10 @@ int main(){ return error(8); print("Open of an existing file: Passed\n"); - + if(read(fd, buffer2, SIZE) != SIZE) return error(9); - + for(i = 0; i < SIZE; i++){ if(buffer[i] != buffer2[i]) return error(10); @@ -96,4 +97,4 @@ int main(){ print("close: passed\n"); return 0; -} +} \ No newline at end of file diff --git a/miosix/testsuite/testsuite_syscall_mpu.h b/miosix/testsuite/testsuite_syscall_mpu.h new file mode 100644 index 00000000..2d53a3c2 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu.h @@ -0,0 +1,24 @@ +const unsigned char __attribute__((aligned(8))) testsuite_syscall_mpu_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, + 0x26, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xcc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x0a, 0xf8, 0x00, 0x20, 0x08, 0xb5, 0x40, 0xf2, 0x02, 0x41, + 0x02, 0x46, 0x00, 0xf0, 0x05, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x00, 0xbf, + 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, + 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; +unsigned int testsuite_syscall_mpu_elf_len = 244; diff --git a/miosix/testsuite/testsuite_syscall_mpu_open.h b/miosix/testsuite/testsuite_syscall_mpu_open.h new file mode 100644 index 00000000..796bcc61 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_open.h @@ -0,0 +1,24 @@ +const unsigned char __attribute__((aligned(8))) testsuite_syscall_mpu_open_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, + 0x26, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xcc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x0a, 0xf8, 0x00, 0x20, 0x08, 0xb5, 0x40, 0xf2, 0x02, 0x41, + 0x02, 0x46, 0x00, 0xf0, 0x05, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x00, 0xbf, + 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, + 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; +unsigned int testsuite_syscall_mpu_open_elf_len = 244; diff --git a/miosix/testsuite/testsuite_file/Makefile b/miosix/testsuite/testsuite_syscall_mpu_open/Makefile similarity index 89% rename from miosix/testsuite/testsuite_file/Makefile rename to miosix/testsuite/testsuite_syscall_mpu_open/Makefile index dc36819f..34f92e72 100644 --- a/miosix/testsuite/testsuite_file/Makefile +++ b/miosix/testsuite/testsuite_syscall_mpu_open/Makefile @@ -9,7 +9,6 @@ main.c ## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o" OBJ := $(addsuffix .o, $(basename $(SRC))) ELF := $(addsuffix .elf, $(NAME)) -OUT_FILE := $(addsuffix .bin, $(NAME)) AS := arm-miosix-eabi-as CC := arm-miosix-eabi-gcc @@ -18,7 +17,7 @@ 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 -DTEST_STRING='$(TEST_STRING)' -DTEST_FILE='"$(OUT_FILE)"' + -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 \ diff --git a/miosix/testsuite/testsuite_file/crt0.s b/miosix/testsuite/testsuite_syscall_mpu_open/crt0.s similarity index 100% rename from miosix/testsuite/testsuite_file/crt0.s rename to miosix/testsuite/testsuite_syscall_mpu_open/crt0.s diff --git a/miosix/testsuite/testsuite_syscall_mpu_open/main.c b/miosix/testsuite/testsuite_syscall_mpu_open/main.c new file mode 100644 index 00000000..376be3d7 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_open/main.c @@ -0,0 +1,13 @@ +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> + +int main(){ + int fd = open(0x00000000, O_RDWR|O_TRUNC, 0); + return 0; +} + diff --git a/miosix/testsuite/testsuite_file/miosix.ld b/miosix/testsuite/testsuite_syscall_mpu_open/miosix.ld similarity index 100% rename from miosix/testsuite/testsuite_file/miosix.ld rename to miosix/testsuite/testsuite_syscall_mpu_open/miosix.ld diff --git a/miosix/testsuite/testsuite_syscall_mpu_open/prog3.h b/miosix/testsuite/testsuite_syscall_mpu_open/prog3.h new file mode 100644 index 00000000..796bcc61 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_open/prog3.h @@ -0,0 +1,24 @@ +const unsigned char __attribute__((aligned(8))) testsuite_syscall_mpu_open_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, + 0x26, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xcc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x0a, 0xf8, 0x00, 0x20, 0x08, 0xb5, 0x40, 0xf2, 0x02, 0x41, + 0x02, 0x46, 0x00, 0xf0, 0x05, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x00, 0xbf, + 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, + 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; +unsigned int testsuite_syscall_mpu_open_elf_len = 244; diff --git a/miosix/testsuite/testsuite_syscall_mpu_open/test.txt b/miosix/testsuite/testsuite_syscall_mpu_open/test.txt new file mode 100644 index 00000000..1171c391 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_open/test.txt @@ -0,0 +1,91 @@ + +testsuite_syscall_mpu_open.elf: file format elf32-littlearm +testsuite_syscall_mpu_open.elf +architecture: arm, flags 0x00000050: +HAS_SYMS, DYNAMIC +start address 0x00000099 + +Program Header: + LOAD off 0x00000098 vaddr 0x00000098 paddr 0x00000098 align 2**3 + filesz 0x00000026 memsz 0x00000026 flags r-x + LOAD off 0x000000c0 vaddr 0x10000000 paddr 0x10000000 align 2**2 + filesz 0x00000034 memsz 0x00000034 flags rw- + DYNAMIC off 0x000000cc vaddr 0x1000000c paddr 0x1000000c align 2**2 + filesz 0x00000028 memsz 0x00000028 flags rw- + +Dynamic Section: + DEBUG 0x00000000 +private flags = 5000002: [Version5 EABI] [has entry point] + +Sections: +Idx Name Size VMA LMA File off Algn + 0 .text 00000026 00000098 00000098 00000098 2**3 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 1 .got 0000000c 10000000 10000000 000000c0 2**2 + CONTENTS, ALLOC, LOAD, DATA + 2 .dynamic 00000028 1000000c 1000000c 000000cc 2**2 + CONTENTS, ALLOC, LOAD, DATA +SYMBOL TABLE: +00000098 l d .text 00000000 .text +10000000 l d .got 00000000 .got +1000000c l d .dynamic 00000000 .dynamic +00000000 l df *ABS* 00000000 main.c +1000000c l O *ABS* 00000000 _DYNAMIC +10000000 l O *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ +00000098 g F .text 00000000 _start +000000a0 g F .text 00000012 main +000000b4 g F .text 00000000 _exit +000000b8 g F .text 00000000 open + + +Contents of section .text: + 0098 00f002f8 00f00af8 002008b5 40f20241 ......... ..@..A + 00a8 024600f0 05f80020 08bd00bf 022300df .F..... .....#.. + 00b8 062300df 7047 .#..pG +Contents of section .got: + 10000000 0c000010 00000000 00000000 ............ +Contents of section .dynamic: + 1000000c 15000000 00000000 00000000 00000000 ................ + 1000001c 00000000 00000000 00000000 00000000 ................ + 1000002c 00000000 00000000 ........ + +Disassembly of section .text: + +00000098 <_start>: +_start(): + 98: f000 f802 bl a0 <main> + 9c: f000 f80a bl b4 <_exit> + +000000a0 <main>: +main(): + a0: 2000 movs r0, #0 + a2: b508 push {r3, lr} + a4: f240 4102 movw r1, #1026 ; 0x402 + a8: 4602 mov r2, r0 + aa: f000 f805 bl b8 <open> + ae: 2000 movs r0, #0 + b0: bd08 pop {r3, pc} + b2: bf00 nop + +000000b4 <_exit>: +_exit(): + b4: 2302 movs r3, #2 + b6: df00 svc 0 + +000000b8 <open>: +open(): + b8: 2306 movs r3, #6 + ba: df00 svc 0 + bc: 4770 bx lr + +Disassembly of section .got: + +10000000 <.got>: +10000000: 1000000c andne r0, r0, ip + ... + +Disassembly of section .dynamic: + +1000000c <.dynamic>: +1000000c: 00000015 andeq r0, r0, r5, lsl r0 + ... diff --git a/miosix/testsuite/testsuite_syscall_mpu_read.h b/miosix/testsuite/testsuite_syscall_mpu_read.h new file mode 100644 index 00000000..ac0c2595 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_read.h @@ -0,0 +1,26 @@ +const unsigned char __attribute__((aligned(8))) testsuite_syscall_mpu_read_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xdc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x10, 0xf8, 0x06, 0x48, 0x08, 0xb5, 0x00, 0x22, 0x40, 0xf2, + 0x02, 0x41, 0x48, 0x44, 0x00, 0xf0, 0x0a, 0xf8, 0x00, 0x21, 0x0a, 0x22, + 0x00, 0xf0, 0x09, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x38, 0x00, 0x00, 0x00, + 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x04, 0x23, + 0x00, 0xdf, 0x70, 0x47, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2f, 0x72, 0x64, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, 0x74, 0x00 +}; +unsigned int testsuite_syscall_mpu_read_elf_len = 276; diff --git a/miosix/testsuite/testsuite_syscall_mpu_read/Makefile b/miosix/testsuite/testsuite_syscall_mpu_read/Makefile new file mode 100644 index 00000000..34f92e72 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_read/Makefile @@ -0,0 +1,45 @@ +## +## 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))) +ELF := $(addsuffix .elf, $(NAME)) + +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 + +LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group + +all: $(OBJ) crt0.o + $(CXX) $(LFLAGS) -o $(ELF) $(OBJ) crt0.o $(LINK_LIBS) + $(SZ) $(ELF) + @arm-miosix-eabi-objdump -Dslx $(ELF) > test.txt + @mx-postlinker $(ELF) --ramsize=16384 --stacksize=2048 --strip-sectheader + @xxd -i $(ELF) | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > prog3.h + +clean: + -rm $(OBJ) crt0.o *.elf test.map test.txt + +%.o: %.s + $(AS) $(AFLAGS) $< -o $@ + +%.o : %.c + $(CC) $(CFLAGS) $< -o $@ + +%.o : %.cpp + $(CXX) $(CXXFLAGS) $< -o $@ diff --git a/miosix/testsuite/testsuite_syscall_mpu_read/crt0.s b/miosix/testsuite/testsuite_syscall_mpu_read/crt0.s new file mode 100644 index 00000000..9959b317 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_read/crt0.s @@ -0,0 +1,131 @@ +/* + * 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 + +/** + * seek + * \param fd file descriptor + * \param pos moving offset + * \param start position, SEEK_SET, SEEK_CUR or SEEK_END +*/ +.section .text.seek +.global seek +.type seek, %function +seek: + 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/miosix/testsuite/testsuite_syscall_mpu_read/main.c b/miosix/testsuite/testsuite_syscall_mpu_read/main.c new file mode 100644 index 00000000..f442ac54 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_read/main.c @@ -0,0 +1,15 @@ +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> + +int main(){ + int fd = open("/rdtest.txt", O_RDWR|O_TRUNC, 0); + + read(fd, 0x00, 10); + return 0; +} + diff --git a/miosix/testsuite/testsuite_syscall_mpu_read/miosix.ld b/miosix/testsuite/testsuite_syscall_mpu_read/miosix.ld new file mode 100644 index 00000000..c91c803e --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_read/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/miosix/testsuite/testsuite_syscall_mpu_read/prog3.h b/miosix/testsuite/testsuite_syscall_mpu_read/prog3.h new file mode 100644 index 00000000..ac0c2595 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_read/prog3.h @@ -0,0 +1,26 @@ +const unsigned char __attribute__((aligned(8))) testsuite_syscall_mpu_read_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xdc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x10, 0xf8, 0x06, 0x48, 0x08, 0xb5, 0x00, 0x22, 0x40, 0xf2, + 0x02, 0x41, 0x48, 0x44, 0x00, 0xf0, 0x0a, 0xf8, 0x00, 0x21, 0x0a, 0x22, + 0x00, 0xf0, 0x09, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x38, 0x00, 0x00, 0x00, + 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x04, 0x23, + 0x00, 0xdf, 0x70, 0x47, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2f, 0x72, 0x64, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, 0x74, 0x00 +}; +unsigned int testsuite_syscall_mpu_read_elf_len = 276; diff --git a/miosix/testsuite/testsuite_syscall_mpu_read/test.txt b/miosix/testsuite/testsuite_syscall_mpu_read/test.txt new file mode 100644 index 00000000..29fe4582 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_read/test.txt @@ -0,0 +1,115 @@ + +testsuite_syscall_mpu_read.elf: file format elf32-littlearm +testsuite_syscall_mpu_read.elf +architecture: arm, flags 0x00000050: +HAS_SYMS, DYNAMIC +start address 0x00000099 + +Program Header: + LOAD off 0x00000098 vaddr 0x00000098 paddr 0x00000098 align 2**3 + filesz 0x00000038 memsz 0x00000038 flags r-x + LOAD off 0x000000d0 vaddr 0x10000000 paddr 0x10000000 align 2**3 + filesz 0x00000044 memsz 0x00000044 flags rw- + DYNAMIC off 0x000000dc vaddr 0x1000000c paddr 0x1000000c align 2**2 + filesz 0x00000028 memsz 0x00000028 flags rw- + +Dynamic Section: + DEBUG 0x00000000 +private flags = 5000002: [Version5 EABI] [has entry point] + +Sections: +Idx Name Size VMA LMA File off Algn + 0 .text 00000038 00000098 00000098 00000098 2**3 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 1 .got 0000000c 10000000 10000000 000000d0 2**2 + CONTENTS, ALLOC, LOAD, DATA + 2 .dynamic 00000028 1000000c 1000000c 000000dc 2**2 + CONTENTS, ALLOC, LOAD, DATA + 3 .rodata 0000000c 10000038 10000038 00000108 2**3 + CONTENTS, ALLOC, LOAD, READONLY, DATA +SYMBOL TABLE: +00000098 l d .text 00000000 .text +10000000 l d .got 00000000 .got +1000000c l d .dynamic 00000000 .dynamic +10000038 l d .rodata 00000000 .rodata +00000000 l df *ABS* 00000000 main.c +1000000c l O *ABS* 00000000 _DYNAMIC +10000000 l O *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ +00000098 g F .text 00000000 _start +000000ca g F .text 00000000 read +000000a0 g F .text 00000020 main +000000c0 g F .text 00000000 _exit +000000c4 g F .text 00000000 open + + +Contents of section .text: + 0098 00f002f8 00f010f8 064808b5 002240f2 .........H..."@. + 00a8 02414844 00f00af8 00210a22 00f009f8 .AHD.....!.".... + 00b8 002008bd 38000000 022300df 062300df . ..8....#...#.. + 00c8 70470423 00df7047 pG.#..pG +Contents of section .got: + 10000000 0c000010 00000000 00000000 ............ +Contents of section .dynamic: + 1000000c 15000000 00000000 00000000 00000000 ................ + 1000001c 00000000 00000000 00000000 00000000 ................ + 1000002c 00000000 00000000 ........ +Contents of section .rodata: + 10000038 2f726474 6573742e 74787400 /rdtest.txt. + +Disassembly of section .text: + +00000098 <_start>: +_start(): + 98: f000 f802 bl a0 <main> + 9c: f000 f810 bl c0 <_exit> + +000000a0 <main>: +main(): + a0: 4806 ldr r0, [pc, #24] ; (bc <main+0x1c>) + a2: b508 push {r3, lr} + a4: 2200 movs r2, #0 + a6: f240 4102 movw r1, #1026 ; 0x402 + aa: 4448 add r0, r9 + ac: f000 f80a bl c4 <open> + b0: 2100 movs r1, #0 + b2: 220a movs r2, #10 + b4: f000 f809 bl ca <read> + b8: 2000 movs r0, #0 + ba: bd08 pop {r3, pc} + bc: 00000038 andeq r0, r0, r8, lsr r0 + +000000c0 <_exit>: +_exit(): + c0: 2302 movs r3, #2 + c2: df00 svc 0 + +000000c4 <open>: +open(): + c4: 2306 movs r3, #6 + c6: df00 svc 0 + c8: 4770 bx lr + +000000ca <read>: +read(): + ca: 2304 movs r3, #4 + cc: df00 svc 0 + ce: 4770 bx lr + +Disassembly of section .got: + +10000000 <.got>: +10000000: 1000000c andne r0, r0, ip + ... + +Disassembly of section .dynamic: + +1000000c <.dynamic>: +1000000c: 00000015 andeq r0, r0, r5, lsl r0 + ... + +Disassembly of section .rodata: + +10000038 <.rodata>: +10000038: 7464722f strbtvc r7, [r4], #-559 ; 0x22f +1000003c: 2e747365 cdpcs 3, 7, cr7, cr4, cr5, {3} +10000040: 00747874 rsbseq r7, r4, r4, ror r8 diff --git a/miosix/testsuite/testsuite_syscall_mpu_write.h b/miosix/testsuite/testsuite_syscall_mpu_write.h new file mode 100644 index 00000000..61bf80e6 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_write.h @@ -0,0 +1,26 @@ +const unsigned char __attribute__((aligned(8))) testsuite_syscall_mpu_write_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xdc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x10, 0xf8, 0x06, 0x48, 0x08, 0xb5, 0x00, 0x22, 0x40, 0xf2, + 0x02, 0x41, 0x48, 0x44, 0x00, 0xf0, 0x0a, 0xf8, 0x00, 0x21, 0x0a, 0x22, + 0x00, 0xf0, 0x09, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x38, 0x00, 0x00, 0x00, + 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x03, 0x23, + 0x00, 0xdf, 0x70, 0x47, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2f, 0x72, 0x64, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, 0x74, 0x00 +}; +unsigned int testsuite_syscall_mpu_write_elf_len = 276; diff --git a/miosix/testsuite/testsuite_syscall_mpu_write/Makefile b/miosix/testsuite/testsuite_syscall_mpu_write/Makefile new file mode 100644 index 00000000..34f92e72 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_write/Makefile @@ -0,0 +1,45 @@ +## +## 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))) +ELF := $(addsuffix .elf, $(NAME)) + +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 + +LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group + +all: $(OBJ) crt0.o + $(CXX) $(LFLAGS) -o $(ELF) $(OBJ) crt0.o $(LINK_LIBS) + $(SZ) $(ELF) + @arm-miosix-eabi-objdump -Dslx $(ELF) > test.txt + @mx-postlinker $(ELF) --ramsize=16384 --stacksize=2048 --strip-sectheader + @xxd -i $(ELF) | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > prog3.h + +clean: + -rm $(OBJ) crt0.o *.elf test.map test.txt + +%.o: %.s + $(AS) $(AFLAGS) $< -o $@ + +%.o : %.c + $(CC) $(CFLAGS) $< -o $@ + +%.o : %.cpp + $(CXX) $(CXXFLAGS) $< -o $@ diff --git a/miosix/testsuite/testsuite_syscall_mpu_write/crt0.s b/miosix/testsuite/testsuite_syscall_mpu_write/crt0.s new file mode 100644 index 00000000..9959b317 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_write/crt0.s @@ -0,0 +1,131 @@ +/* + * 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 + +/** + * seek + * \param fd file descriptor + * \param pos moving offset + * \param start position, SEEK_SET, SEEK_CUR or SEEK_END +*/ +.section .text.seek +.global seek +.type seek, %function +seek: + 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/miosix/testsuite/testsuite_syscall_mpu_write/main.c b/miosix/testsuite/testsuite_syscall_mpu_write/main.c new file mode 100644 index 00000000..0fd7b2c1 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_write/main.c @@ -0,0 +1,15 @@ +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> + +int main(){ + int fd = open("/rdtest.txt", O_RDWR|O_TRUNC, 0); + + write(fd, 0x00, 10); + return 0; +} + diff --git a/miosix/testsuite/testsuite_syscall_mpu_write/miosix.ld b/miosix/testsuite/testsuite_syscall_mpu_write/miosix.ld new file mode 100644 index 00000000..c91c803e --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_write/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/miosix/testsuite/testsuite_syscall_mpu_write/prog3.h b/miosix/testsuite/testsuite_syscall_mpu_write/prog3.h new file mode 100644 index 00000000..61bf80e6 --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_write/prog3.h @@ -0,0 +1,26 @@ +const unsigned char __attribute__((aligned(8))) testsuite_syscall_mpu_write_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xdc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x10, 0xf8, 0x06, 0x48, 0x08, 0xb5, 0x00, 0x22, 0x40, 0xf2, + 0x02, 0x41, 0x48, 0x44, 0x00, 0xf0, 0x0a, 0xf8, 0x00, 0x21, 0x0a, 0x22, + 0x00, 0xf0, 0x09, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x38, 0x00, 0x00, 0x00, + 0x02, 0x23, 0x00, 0xdf, 0x06, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x03, 0x23, + 0x00, 0xdf, 0x70, 0x47, 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, + 0x00, 0x08, 0x00, 0x00, 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2f, 0x72, 0x64, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74, 0x78, 0x74, 0x00 +}; +unsigned int testsuite_syscall_mpu_write_elf_len = 276; diff --git a/miosix/testsuite/testsuite_syscall_mpu_write/test.txt b/miosix/testsuite/testsuite_syscall_mpu_write/test.txt new file mode 100644 index 00000000..21e148eb --- /dev/null +++ b/miosix/testsuite/testsuite_syscall_mpu_write/test.txt @@ -0,0 +1,115 @@ + +testsuite_syscall_mpu_write.elf: file format elf32-littlearm +testsuite_syscall_mpu_write.elf +architecture: arm, flags 0x00000050: +HAS_SYMS, DYNAMIC +start address 0x00000099 + +Program Header: + LOAD off 0x00000098 vaddr 0x00000098 paddr 0x00000098 align 2**3 + filesz 0x00000038 memsz 0x00000038 flags r-x + LOAD off 0x000000d0 vaddr 0x10000000 paddr 0x10000000 align 2**3 + filesz 0x00000044 memsz 0x00000044 flags rw- + DYNAMIC off 0x000000dc vaddr 0x1000000c paddr 0x1000000c align 2**2 + filesz 0x00000028 memsz 0x00000028 flags rw- + +Dynamic Section: + DEBUG 0x00000000 +private flags = 5000002: [Version5 EABI] [has entry point] + +Sections: +Idx Name Size VMA LMA File off Algn + 0 .text 00000038 00000098 00000098 00000098 2**3 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 1 .got 0000000c 10000000 10000000 000000d0 2**2 + CONTENTS, ALLOC, LOAD, DATA + 2 .dynamic 00000028 1000000c 1000000c 000000dc 2**2 + CONTENTS, ALLOC, LOAD, DATA + 3 .rodata 0000000c 10000038 10000038 00000108 2**3 + CONTENTS, ALLOC, LOAD, READONLY, DATA +SYMBOL TABLE: +00000098 l d .text 00000000 .text +10000000 l d .got 00000000 .got +1000000c l d .dynamic 00000000 .dynamic +10000038 l d .rodata 00000000 .rodata +00000000 l df *ABS* 00000000 main.c +1000000c l O *ABS* 00000000 _DYNAMIC +10000000 l O *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ +000000ca g F .text 00000000 write +00000098 g F .text 00000000 _start +000000a0 g F .text 00000020 main +000000c0 g F .text 00000000 _exit +000000c4 g F .text 00000000 open + + +Contents of section .text: + 0098 00f002f8 00f010f8 064808b5 002240f2 .........H..."@. + 00a8 02414844 00f00af8 00210a22 00f009f8 .AHD.....!.".... + 00b8 002008bd 38000000 022300df 062300df . ..8....#...#.. + 00c8 70470323 00df7047 pG.#..pG +Contents of section .got: + 10000000 0c000010 00000000 00000000 ............ +Contents of section .dynamic: + 1000000c 15000000 00000000 00000000 00000000 ................ + 1000001c 00000000 00000000 00000000 00000000 ................ + 1000002c 00000000 00000000 ........ +Contents of section .rodata: + 10000038 2f726474 6573742e 74787400 /rdtest.txt. + +Disassembly of section .text: + +00000098 <_start>: +_start(): + 98: f000 f802 bl a0 <main> + 9c: f000 f810 bl c0 <_exit> + +000000a0 <main>: +main(): + a0: 4806 ldr r0, [pc, #24] ; (bc <main+0x1c>) + a2: b508 push {r3, lr} + a4: 2200 movs r2, #0 + a6: f240 4102 movw r1, #1026 ; 0x402 + aa: 4448 add r0, r9 + ac: f000 f80a bl c4 <open> + b0: 2100 movs r1, #0 + b2: 220a movs r2, #10 + b4: f000 f809 bl ca <write> + b8: 2000 movs r0, #0 + ba: bd08 pop {r3, pc} + bc: 00000038 andeq r0, r0, r8, lsr r0 + +000000c0 <_exit>: +_exit(): + c0: 2302 movs r3, #2 + c2: df00 svc 0 + +000000c4 <open>: +open(): + c4: 2306 movs r3, #6 + c6: df00 svc 0 + c8: 4770 bx lr + +000000ca <write>: +write(): + ca: 2303 movs r3, #3 + cc: df00 svc 0 + ce: 4770 bx lr + +Disassembly of section .got: + +10000000 <.got>: +10000000: 1000000c andne r0, r0, ip + ... + +Disassembly of section .dynamic: + +1000000c <.dynamic>: +1000000c: 00000015 andeq r0, r0, r5, lsl r0 + ... + +Disassembly of section .rodata: + +10000038 <.rodata>: +10000038: 7464722f strbtvc r7, [r4], #-559 ; 0x22f +1000003c: 2e747365 cdpcs 3, 7, cr7, cr4, cr5, {3} +10000040: 00747874 rsbseq r7, r4, r4, ror r8 diff --git a/miosix/testsuite/testsuite_system.h b/miosix/testsuite/testsuite_system.h new file mode 100644 index 00000000..e263fad5 --- /dev/null +++ b/miosix/testsuite/testsuite_system.h @@ -0,0 +1,25 @@ +const unsigned char __attribute__((aligned(8))) testsuite_system_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x22, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xcc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x08, 0xf8, 0x02, 0x48, 0x08, 0xb5, 0x48, 0x44, 0x00, 0xf0, + 0x05, 0xf8, 0x08, 0xbd, 0x38, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, + 0x09, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, + 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, + 0x00, 0x00, 0x00, 0x00 +}; +unsigned int testsuite_system_elf_len = 256; diff --git a/miosix/testsuite/testsuite_system/Makefile b/miosix/testsuite/testsuite_system/Makefile new file mode 100644 index 00000000..34f92e72 --- /dev/null +++ b/miosix/testsuite/testsuite_system/Makefile @@ -0,0 +1,45 @@ +## +## 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))) +ELF := $(addsuffix .elf, $(NAME)) + +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 + +LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group + +all: $(OBJ) crt0.o + $(CXX) $(LFLAGS) -o $(ELF) $(OBJ) crt0.o $(LINK_LIBS) + $(SZ) $(ELF) + @arm-miosix-eabi-objdump -Dslx $(ELF) > test.txt + @mx-postlinker $(ELF) --ramsize=16384 --stacksize=2048 --strip-sectheader + @xxd -i $(ELF) | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > prog3.h + +clean: + -rm $(OBJ) crt0.o *.elf test.map test.txt + +%.o: %.s + $(AS) $(AFLAGS) $< -o $@ + +%.o : %.c + $(CC) $(CFLAGS) $< -o $@ + +%.o : %.cpp + $(CXX) $(CXXFLAGS) $< -o $@ diff --git a/miosix/testsuite/testsuite_system/crt0.s b/miosix/testsuite/testsuite_system/crt0.s new file mode 100644 index 00000000..8dbb153d --- /dev/null +++ b/miosix/testsuite/testsuite_system/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.seek +.global seek +.type seek, %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/miosix/testsuite/testsuite_system/main.c b/miosix/testsuite/testsuite_system/main.c new file mode 100644 index 00000000..3cc4e59f --- /dev/null +++ b/miosix/testsuite/testsuite_system/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> +#include <stdlib.h> + +int main(){ + return system("test"); +} diff --git a/miosix/testsuite/testsuite_system/miosix.ld b/miosix/testsuite/testsuite_system/miosix.ld new file mode 100644 index 00000000..c91c803e --- /dev/null +++ b/miosix/testsuite/testsuite_system/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/miosix/testsuite/testsuite_system/prog3.h b/miosix/testsuite/testsuite_system/prog3.h new file mode 100644 index 00000000..e263fad5 --- /dev/null +++ b/miosix/testsuite/testsuite_system/prog3.h @@ -0,0 +1,25 @@ +const unsigned char __attribute__((aligned(8))) testsuite_system_elf[] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x22, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xcc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10, + 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8, + 0x00, 0xf0, 0x08, 0xf8, 0x02, 0x48, 0x08, 0xb5, 0x48, 0x44, 0x00, 0xf0, + 0x05, 0xf8, 0x08, 0xbd, 0x38, 0x00, 0x00, 0x00, 0x02, 0x23, 0x00, 0xdf, + 0x09, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, + 0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, + 0x00, 0x00, 0x00, 0x00 +}; +unsigned int testsuite_system_elf_len = 256; diff --git a/miosix/testsuite/testsuite_system/test.txt b/miosix/testsuite/testsuite_system/test.txt new file mode 100644 index 00000000..532c7ab9 --- /dev/null +++ b/miosix/testsuite/testsuite_system/test.txt @@ -0,0 +1,101 @@ + +testsuite_system.elf: file format elf32-littlearm +testsuite_system.elf +architecture: arm, flags 0x00000050: +HAS_SYMS, DYNAMIC +start address 0x00000099 + +Program Header: + LOAD off 0x00000098 vaddr 0x00000098 paddr 0x00000098 align 2**3 + filesz 0x00000022 memsz 0x00000022 flags r-x + LOAD off 0x000000c0 vaddr 0x10000000 paddr 0x10000000 align 2**3 + filesz 0x00000040 memsz 0x00000040 flags rw- + DYNAMIC off 0x000000cc vaddr 0x1000000c paddr 0x1000000c align 2**2 + filesz 0x00000028 memsz 0x00000028 flags rw- + +Dynamic Section: + DEBUG 0x00000000 +private flags = 5000002: [Version5 EABI] [has entry point] + +Sections: +Idx Name Size VMA LMA File off Algn + 0 .text 00000022 00000098 00000098 00000098 2**3 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 1 .got 0000000c 10000000 10000000 000000c0 2**2 + CONTENTS, ALLOC, LOAD, DATA + 2 .dynamic 00000028 1000000c 1000000c 000000cc 2**2 + CONTENTS, ALLOC, LOAD, DATA + 3 .rodata 00000008 10000038 10000038 000000f8 2**3 + CONTENTS, ALLOC, LOAD, READONLY, DATA +SYMBOL TABLE: +00000098 l d .text 00000000 .text +10000000 l d .got 00000000 .got +1000000c l d .dynamic 00000000 .dynamic +10000038 l d .rodata 00000000 .rodata +00000000 l df *ABS* 00000000 main.c +1000000c l O *ABS* 00000000 _DYNAMIC +10000000 l O *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ +000000b4 g F .text 00000000 system +00000098 g F .text 00000000 _start +000000a0 g F .text 00000010 main +00000000 F *UND* 00000000 seek +000000b0 g F .text 00000000 _exit + + +Contents of section .text: + 0098 00f002f8 00f008f8 024808b5 484400f0 .........H..HD.. + 00a8 05f808bd 38000000 022300df 092300df ....8....#...#.. + 00b8 7047 pG +Contents of section .got: + 10000000 0c000010 00000000 00000000 ............ +Contents of section .dynamic: + 1000000c 15000000 00000000 00000000 00000000 ................ + 1000001c 00000000 00000000 00000000 00000000 ................ + 1000002c 00000000 00000000 ........ +Contents of section .rodata: + 10000038 74657374 00000000 test.... + +Disassembly of section .text: + +00000098 <_start>: +_start(): + 98: f000 f802 bl a0 <main> + 9c: f000 f808 bl b0 <_exit> + +000000a0 <main>: +main(): + a0: 4802 ldr r0, [pc, #8] ; (ac <main+0xc>) + a2: b508 push {r3, lr} + a4: 4448 add r0, r9 + a6: f000 f805 bl b4 <system> + aa: bd08 pop {r3, pc} + ac: 00000038 andeq r0, r0, r8, lsr r0 + +000000b0 <_exit>: +_exit(): + b0: 2302 movs r3, #2 + b2: df00 svc 0 + +000000b4 <system>: +system(): + b4: 2309 movs r3, #9 + b6: df00 svc 0 + b8: 4770 bx lr + +Disassembly of section .got: + +10000000 <.got>: +10000000: 1000000c andne r0, r0, ip + ... + +Disassembly of section .dynamic: + +1000000c <.dynamic>: +1000000c: 00000015 andeq r0, r0, r5, lsl r0 + ... + +Disassembly of section .rodata: + +10000038 <.rodata>: +10000038: 74736574 ldrbtvc r6, [r3], #-1396 ; 0x574 +1000003c: 00000000 andeq r0, r0, r0 diff --git a/miosix_np_processes/nbproject/configurations.xml b/miosix_np_processes/nbproject/configurations.xml index f7cc6131..87cad711 100644 --- a/miosix_np_processes/nbproject/configurations.xml +++ b/miosix_np_processes/nbproject/configurations.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <configurationDescriptor version="84"> <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT"> - <df name="miosix-kernel" root=".."> + <df name="embeddedmiosix" root=".."> <df name="app_template"> <in>crt0.s</in> <in>main.c</in> @@ -325,7 +325,77 @@ <in>unistd.cpp</in> </df> <df name="testsuite"> + <df name="testsuite_file1"> + <in>crt0.s</in> + <in>main.c</in> + <in>prog3.h</in> + </df> + <df name="testsuite_file2"> + <in>crt0.s</in> + <in>main.c</in> + <in>prog3.h</in> + </df> + <df name="testsuite_simple"> + <in>crt0.s</in> + <in>main.c</in> + <in>prog3.h</in> + </df> + <df name="testsuite_sleep"> + <in>crt0.s</in> + <in>main.c</in> + <in>prog3.h</in> + </df> + <df name="testsuite_syscall"> + <in>crt0.s</in> + <in>main.c</in> + <in>prog3.h</in> + </df> + <df name="testsuite_syscall_mpu_open"> + <in>Makefile</in> + <in>crt0.s</in> + <in>main.c</in> + <in>miosix.ld</in> + <in>prog3.h</in> + <in>test.map</in> + <in>test.txt</in> + <in>testsuite_syscall_mpu.elf</in> + </df> + <df name="testsuite_syscall_mpu_read"> + <in>Makefile</in> + <in>crt0.s</in> + <in>main.c</in> + <in>miosix.ld</in> + <in>prog3.h</in> + <in>test.map</in> + <in>test.txt</in> + <in>testsuite_syscall_mpu.elf</in> + </df> + <df name="testsuite_syscall_mpu_write"> + <in>Makefile</in> + <in>crt0.s</in> + <in>main.c</in> + <in>miosix.ld</in> + <in>prog3.h</in> + <in>test.map</in> + <in>test.txt</in> + <in>testsuite_syscall_mpu.elf</in> + </df> + <df name="testsuite_system"> + <in>crt0.s</in> + <in>main.c</in> + <in>prog3.h</in> + </df> <in>testsuite.cpp</in> + <in>testsuite_file1.h</in> + <in>testsuite_file2.h</in> + <in>testsuite_simple.h</in> + <in>testsuite_sleep.h</in> + <in>testsuite_syscall.h</in> + <in>testsuite_syscall_mpu.h</in> + <in>testsuite_syscall_mpu_open.h</in> + <in>testsuite_syscall_mpu_read.h</in> + <in>testsuite_syscall_mpu_write.h</in> + <in>testsuite_system.h</in> </df> <df name="util"> <in>crc16.cpp</in> @@ -343,10 +413,32 @@ </df> <df name="miosix_np_processes"> </df> - <df name="system_app_test"> - <in>crt0.s</in> - <in>main.c</in> - <in>prog3.h</in> + <df name="mpu_testsuite"> + <df name="altered_elfs"> + <in>aelf1.h</in> + <in>aelf2.h</in> + <in>aelf3.h</in> + <in>aelf4.h</in> + <in>aelf5.h</in> + <in>aelf6.h</in> + <in>aelf7.h</in> + <in>includes.h</in> + </df> + <df name="mpu_apps"> + <df name="test1"> + <in>crt0.s</in> + <in>main.c</in> + </df> + <df name="test2"> + <in>crt0.s</in> + <in>main.c</in> + </df> + <df name="test3"> + <in>crt0.s</in> + <in>main.c</in> + </df> + </df> + <in>mpu_testsuite.cpp</in> </df> <in>main.cpp</in> </df> -- GitLab