diff options
author | leleraffa97@hotmail.it <leleraffa97@hotmail.it> | 2017-06-19 15:06:25 +0200 |
---|---|---|
committer | leleraffa97@hotmail.it <leleraffa97@hotmail.it> | 2017-06-19 15:06:25 +0200 |
commit | acee9e74f6bd183b284af028b1f08aab666df9be (patch) | |
tree | 02d8df6267dd75dd92760ab9b8e924f4f4b8b400 /sw | |
parent | Merge branch 'master' of github.com:NaoPross/z80uPC into atlas (diff) | |
download | z80uPC-master.tar.gz z80uPC-master.zip |
boot improved
program allocation
Diffstat (limited to 'sw')
-rw-r--r-- | sw/z80/kernel/boot_loader.c | 25 | ||||
-rw-r--r-- | sw/z80/kernel/include/progman.h | 1 | ||||
-rw-r--r-- | sw/z80/kernel/programs.c | 29 | ||||
-rw-r--r-- | sw/z80/libc/include/string.h | 4 | ||||
-rw-r--r-- | sw/z80/libc/string.c | 26 |
5 files changed, 61 insertions, 24 deletions
diff --git a/sw/z80/kernel/boot_loader.c b/sw/z80/kernel/boot_loader.c index ddca4f9..03a52b5 100644 --- a/sw/z80/kernel/boot_loader.c +++ b/sw/z80/kernel/boot_loader.c @@ -1,5 +1,6 @@ #include "boot.h" #include "progman.h" +#include "string.h" #define DEFAULT_EXEC_STATUS 0x4000 @@ -14,30 +15,10 @@ void boot_init() { int8_t authenticate(const char *pwd) { - const char *c_pwd = PWD_ADDR, *c_req = pwd; - - for (uint8_t i = 0; i < PWD_SIZE; i++) { - - if (*c_pwd != *c_req) - return 0; - - c_pwd++; - c_req++; - } - - return 1; + return !memcmp(PWD_ADDR, pwd, PWD_SIZE); } void set_pwd(const char *pwd) { - char *c_pwd = PWD_ADDR; - const char *c_req = pwd; - - for (uint8_t i = 0; i < PWD_SIZE; i++) { - - *c_pwd = *c_req; - - c_pwd++; - c_req++; - } + memcpy(PWD_ADDR, pwd, PWD_SIZE); }
\ No newline at end of file diff --git a/sw/z80/kernel/include/progman.h b/sw/z80/kernel/include/progman.h index 0f56bb3..5d01f1c 100644 --- a/sw/z80/kernel/include/progman.h +++ b/sw/z80/kernel/include/progman.h @@ -51,7 +51,6 @@ struct program_base { size_t inst_size; // size of the instructions set void * bss_data; // pointer to the bss/data space size_t data_size; // size of the bss/data space - size_t stack_size; // size of the stack to determine the stack limit }; void prog_alloc(int8_t id, struct program_info *info, const struct program_base *base); diff --git a/sw/z80/kernel/programs.c b/sw/z80/kernel/programs.c index 0f75887..705ea96 100644 --- a/sw/z80/kernel/programs.c +++ b/sw/z80/kernel/programs.c @@ -1,4 +1,5 @@ #include "progman.h" +#include "string.h" #define EMPTY_PROG_INFO 0x0 @@ -37,9 +38,35 @@ int8_t prog_req(struct program_info *info) { void prog_alloc(int8_t id, struct program_info *info, const struct program_base *base) { - // TODO, implements program allocation + void *addr = (id ? PROG_1_PREFIX : PROG_0_PREFIX) + PROG_VSTART; + + if (info->enabled) { + + if (id) + prog_1_fquit(); // force quit operation + else + prog_0_fquit(); + } + + + memcpy(addr, base->inst_set, base->inst_size); + + addr += base->inst_size; + + memcpy(addr, base->bss_data, base->data_size); + + addr += base->data_size; + + // TODO, empty heap and stack } +/* +* TODO Called from the assembly, system calls +*/ + +extern void exec_0(void); +extern void exec_1(void); + void prog_exec(int8_t id, struct program_info *info) { // TODO, perform a program counter jump diff --git a/sw/z80/libc/include/string.h b/sw/z80/libc/include/string.h index f224c87..9c002e3 100644 --- a/sw/z80/libc/include/string.h +++ b/sw/z80/libc/include/string.h @@ -3,6 +3,10 @@ #include "types.h" +void * memset(void *dest, const int8_t src, size_t n); + void *memcpy(void *dest, const void *src, size_t n); +int8_t memcmp(const void *s1, const void *s2, size_t n); + #endif diff --git a/sw/z80/libc/string.c b/sw/z80/libc/string.c index fd6a7ff..9dd56cc 100644 --- a/sw/z80/libc/string.c +++ b/sw/z80/libc/string.c @@ -1,5 +1,15 @@ #include "string.h" +void * memset(void *dest, const int8_t src, size_t n) { + + void *dp = dest; + + while (n--) + *dp++ = src; + + return dest; +} + void *memcpy(void *dest, void *src, size_t n) { char *dp = dest; @@ -11,3 +21,19 @@ void *memcpy(void *dest, void *src, size_t n) return dest; } + +int8_t memcmp(const void *s1, const void *s2, size_t n) { + + uint8_t u1, u2; + + for ( ; n--; s1++, s2++) { + + u1 = *s1; + u2 = *s2; + + if (u1 != u2) + return u1 - u2; + } + + return 0; +}
\ No newline at end of file |