diff options
author | leleraffa97@hotmail.it <leleraffa97@hotmail.it> | 2017-06-23 12:18:24 +0200 |
---|---|---|
committer | leleraffa97@hotmail.it <leleraffa97@hotmail.it> | 2017-06-23 12:18:24 +0200 |
commit | ac89960fbe89141aea31da9a329bfa39d67eede7 (patch) | |
tree | 5fd8f8baefd80d235ebe43167f89c580d137ce22 | |
parent | libc memset, memcmp (diff) | |
download | z80uPC-ac89960fbe89141aea31da9a329bfa39d67eede7.tar.gz z80uPC-ac89960fbe89141aea31da9a329bfa39d67eede7.zip |
Order and update of the struct
Separation of boot and login sections
Improuved program manager system
Diffstat (limited to '')
-rw-r--r-- | sw/z80/kernel/boot_loader.c | 24 | ||||
-rw-r--r-- | sw/z80/kernel/include/boot.h | 35 | ||||
-rw-r--r-- | sw/z80/kernel/include/login.h | 23 | ||||
-rw-r--r-- | sw/z80/kernel/include/progman.h | 68 | ||||
-rw-r--r-- | sw/z80/kernel/include/syscall.h | 20 | ||||
-rw-r--r-- | sw/z80/kernel/include/sysexe.h | 55 | ||||
-rw-r--r-- | sw/z80/kernel/login.c | 12 | ||||
-rw-r--r-- | sw/z80/kernel/progman.c | 90 | ||||
-rw-r--r-- | sw/z80/kernel/programs.c | 137 | ||||
-rw-r--r-- | sw/z80/kernel/sysexe.c | 14 |
10 files changed, 260 insertions, 218 deletions
diff --git a/sw/z80/kernel/boot_loader.c b/sw/z80/kernel/boot_loader.c deleted file mode 100644 index 03a52b5..0000000 --- a/sw/z80/kernel/boot_loader.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "boot.h" -#include "progman.h" -#include "string.h" - -#define DEFAULT_EXEC_STATUS 0x4000 - -struct exec_status *status = EXEC_STATUS; - -void boot_init() { - - *status = DEFAULT_EXEC_STATUS; - - // TODO other stuff -} - -int8_t authenticate(const char *pwd) { - - return !memcmp(PWD_ADDR, pwd, PWD_SIZE); -} - -void set_pwd(const char *pwd) { - - memcpy(PWD_ADDR, pwd, PWD_SIZE); -}
\ No newline at end of file diff --git a/sw/z80/kernel/include/boot.h b/sw/z80/kernel/include/boot.h deleted file mode 100644 index 5310e45..0000000 --- a/sw/z80/kernel/include/boot.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef BOOT_H -#define BOOT_H - -#include "types.h" - -#define LOGIN_PC // TODO find an address in ROM, to perform jumps - -#define EXEC_STATUS // TODO find an address in Kernel space - -#define PWD_ADDR // TODO find an address in ROM, password -#define PWD_SIZE 8 - -struct exec_status { - - volatile int logged_in:1; // authenticated - volatile int k_control:1; // no running programs - volatile int program_id:1; // current running program id, see "progman.h" - volatile int hidden_pc:13; // program counter of the paused program -}; - -void boot_init(); - -/* -* It returns 1 if succeded, otherwise 0 -*/ - -int8_t authenticate(const char *pwd); - -/* -* It sets the password in the ROM space, maximum 8 characters -*/ - -void set_pwd(const char *pwd); - -#endif
\ No newline at end of file diff --git a/sw/z80/kernel/include/login.h b/sw/z80/kernel/include/login.h new file mode 100644 index 0000000..5fa4b5e --- /dev/null +++ b/sw/z80/kernel/include/login.h @@ -0,0 +1,23 @@ +#ifndef LOGIN_H +#define LOGIN_H + +#include "types.h" + +#define LOGIN_PC // TODO find an address in ROM, to perform jumps + +#define PWD_ADDR // TODO find an address in ROM, password +#define PWD_SIZE 8 + +/* +* It returns 1 if succeded, otherwise 0 +*/ + +int8_t authenticate(const char *pwd); + +/* +* It sets the password in the ROM space, maximum 8 characters +*/ + +void set_pwd(const char *pwd); + +#endif
\ No newline at end of file diff --git a/sw/z80/kernel/include/progman.h b/sw/z80/kernel/include/progman.h index 5d01f1c..b59e14a 100644 --- a/sw/z80/kernel/include/progman.h +++ b/sw/z80/kernel/include/progman.h @@ -13,13 +13,41 @@ #define PROG_0_INFO // TODO #define PROG_1_INFO // TODO find a space in the ram -struct program_info { +struct prog_status { - volatile int enabled:1; - volatile int running:1; - volatile int exiting:1; - volatile int heap_addr:13; - volatile void (*quit_cb)(void); // 16 + // The program is in execution + + uint8_t running:1; + + // The program is executing its quit callback + + uint8_t exiting:1; + + uint8_t unused:6; // TODO, find a usage for these bits +}: + +struct prog_data { + + struct prog_status status; + + /* + * The following addresses are needed to map + * map the usable memory for dynamic allocations + */ + + // Virtual address of the heap + + uint8_t heap_addr:12; + + // Virtual address of the stack limit + + uint8_t stack_limit:12; + + /* + * Function called when the program exits normally + */ + + void (*quit_cb)(void); // 16 }; /* @@ -32,20 +60,23 @@ void progman_init(); * Check if it can start a new program * If it succedes, the program id is returned, * otherwise it is returned an error number +* +* ! Disable virtual addresses when this function is called */ #define PROG_REQ_FULL -1 -#define PROG_REQ_ERR -2 // Maybe we don't need this, but just in case -int8_t prog_req(struct program_info *info); +int8_t prog_req(); /* * It allocates a program in the RAM * To obtain the right id call prog_req() first * Basic informations must be allocated and referenced by a program_base struct +* +* ! Disable virtual addresses when this function is called */ -struct program_base { +struct prog_space { void * inst_set; // pointer to the instructions set size_t inst_size; // size of the instructions set @@ -53,33 +84,26 @@ struct program_base { size_t data_size; // size of the bss/data space }; -void prog_alloc(int8_t id, struct program_info *info, const struct program_base *base); +void prog_alloc(int8_t id, struct prog_data *data, const struct prog_space *space); /* * It jumps the program counter to the given one */ -void prog_exec(int8_t id, struct program_info *info); +void prog_exec(int8_t id, struct prog_data *data); /* * It sets a quit callback */ -void prog_0_qcb(void (*callback)(void)); -void prog_1_qcb(void (*callback)(void)); +void prog_0_set_qcb(void (*callback)(void)); +void prog_1_set_qcb(void (*callback)(void)); /* * It quits a program, if a callback is set, it will be called */ -void prog_0_quit(); -void prog_1_quit(); - -/* -* It forces a program to quit -*/ - -void prog_0_fquit(); -void prog_1_fquit(); +void prog_0_quit(uint8_t force); +void prog_1_quit(uint8_t force); #endif
\ No newline at end of file diff --git a/sw/z80/kernel/include/syscall.h b/sw/z80/kernel/include/syscall.h new file mode 100644 index 0000000..9641f25 --- /dev/null +++ b/sw/z80/kernel/include/syscall.h @@ -0,0 +1,20 @@ +#ifndef SYS_CALL +#define SYS_CALL + +/* +* Enable / disable virtual address traslation +*/ + +extern void v_addr(uint8_t flag); + +/* +* Programs execution +*/ + +extern void prog_exec_0(void); +extern void prog_exec_1(void); + +extern void prog_stop_0(void); +extern void prog_stop_1(void); + +#endif
\ No newline at end of file diff --git a/sw/z80/kernel/include/sysexe.h b/sw/z80/kernel/include/sysexe.h new file mode 100644 index 0000000..9c13c09 --- /dev/null +++ b/sw/z80/kernel/include/sysexe.h @@ -0,0 +1,55 @@ +#ifndef SYS_EXE +#define SYS_EXE + +#define SYS_EXEC_ADDR // TODO find an address in Kernel space + +struct sys_progman { + + // program 0 enabled + + uint8_t prog_0_enabled:1; + + // program 1 enabled + + /* + * Obs: A program is enabled when its space is allocated + * and its virtual program counter is stored in + * the hardware or in the silent_pc. + * An enabled program is not necessarly running, it + * could be paused too. + */ + + uint8_t prog_1_enabled:1; + + // running's program id + + uint8_t prog_running:1; +}; + +struct sys_exec { + + /* + * Virtual addresses are activated + */ + + uint8_t virtual_addr:1; + + struct sys_progman progman; + + /* + * The silent_pc is the place designed to store the + * program counter of the program that's not running + */ + + uint8_t silent_pc:12; +}; + +/* +* Function to access informations +*/ + +uint8_t vaddr_enabled(); + +struct sys_progman * sys_prog_data(struct sys_progman *data); + +#endif
\ No newline at end of file diff --git a/sw/z80/kernel/login.c b/sw/z80/kernel/login.c new file mode 100644 index 0000000..5e100bf --- /dev/null +++ b/sw/z80/kernel/login.c @@ -0,0 +1,12 @@ +#include "login.h" +#include "string.h" + +int8_t authenticate(const char *pwd) { + + return !memcmp(PWD_ADDR, pwd, PWD_SIZE); +} + +void set_pwd(const char *pwd) { + + memcpy(PWD_ADDR, pwd, PWD_SIZE); +}
\ No newline at end of file diff --git a/sw/z80/kernel/progman.c b/sw/z80/kernel/progman.c new file mode 100644 index 0000000..44888f8 --- /dev/null +++ b/sw/z80/kernel/progman.c @@ -0,0 +1,90 @@ +#include "progman.h" +#include "string.h" +#include "syscall.h" +#include "sysexe.h" + +#define EMPTY_PROG_INFO 0x0 + +volatile struct prog_data *prog_0 = PROG_0_INFO, + *prog_1 = PROG_1_INFO; + +void progman_init() { + + *prog_0 = EMPTY_PROG_INFO; + *prog_1 = EMPTY_PROG_INFO; + + // TODO other stuff +} + +int8_t prog_req() { + + struct sys_progman data; + + sys_prog_data(&data); + + if (data.prog_0_enabled) + return PROG_0; + else if (data.prog_1_enabled) + return PROG_1; + + return PROG_REQ_FULL; +} + +void prog_alloc(int8_t id, struct prog_data *data, const struct prog_space *space) { + + void *addr = (id ? PROG_1_PREFIX : PROG_0_PREFIX) + PROG_VSTART; + + 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 +} + +void prog_exec(int8_t id, struct prog_data *data) { + + if (id) + prog_exec_1(); // system call + else + prog_exec_0(); // system call +} + +void prog_0_set_qcb(void (*callback)(void)) { + + prog_0->quit_cb = callback; +} + +void prog_1_set_qcb(void (*callback)(void)) { + + prog_1->quit_cb = callback; +} + +void prog_0_quit(uint8_t force) { + + if (!prog_0->enabled || prog_0->exiting) + return; + + if (!force && prog_0->quit_cb) + prog_0->quit_cb(); + + *prog_0 = EMPTY_PROG_INFO; + + prog_stop_0(); // system call +} + +void prog_1_quit(uint8_t force) { + + if (!prog_1->enabled || prog_1->exiting) + return; + + if (!force && prog_1->quit_cb) + prog_1->quit_cb(); + + *prog_1 = EMPTY_PROG_INFO; + + prog_stop_1(); // system call +}
\ No newline at end of file diff --git a/sw/z80/kernel/programs.c b/sw/z80/kernel/programs.c deleted file mode 100644 index 705ea96..0000000 --- a/sw/z80/kernel/programs.c +++ /dev/null @@ -1,137 +0,0 @@ -#include "progman.h" -#include "string.h" - -#define EMPTY_PROG_INFO 0x0 - -struct program_info *prog_0 = PROG_0_INFO, - *prog_1 = PROG_1_INFO; - -void progman_init() { - - *prog_0 = EMPTY_PROG_INFO; - *prog_1 = EMPTY_PROG_INFO; - - // TODO other stuff -} - -int8_t prog_req(struct program_info *info) { - - uint8_t prog; - - if (!prog_0->enabled) { - - prog = PROG_0; - *info = *prog_0; - - } else if (!prog_1->enabled) { - - prog = PROG_1; - *info = *prog_1; - - } else { - - return PROG_REQ_FULL; - } - - return prog; -} - -void prog_alloc(int8_t id, struct program_info *info, const struct program_base *base) { - - 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 -} - -void prog_0_qcb(void (*callback)(void)) { - - prog_0->quit_cb = callback; -} - -void prog_1_qcb(void (*callback)(void)) { - - prog_1->quit_cb = callback; -} - -void prog_0_quit() { - - if (!prog_0->enabled || prog_0->exiting) - return; - - if (prog_0->quit_cb) - prog_0->quit_cb(); - - // TODO free space in RAM - - *prog_0 = EMPTY_PROG_INFO; - - // TODO jump program counter -} - -void prog_1_quit() { - - if (!prog_1->enabled || prog_1->exiting) - return; - - if (prog_1->quit_cb) - prog_1->quit_cb(); - - // TODO free space in RAM - - *prog_1 = EMPTY_PROG_INFO; - - // TODO jump program counter -} - -void prog_0_fquit() { - - if (!prog_0->enabled) - return; - - // TODO free space in RAM - - *prog_0 = EMPTY_PROG_INFO; - - // TODO jump program counter -} - -void prog_1_fquit() { - - if (!prog_1->enabled) - return; - - // TODO free space in RAM - - *prog_1 = EMPTY_PROG_INFO; - - // TODO jump program counter -}
\ No newline at end of file diff --git a/sw/z80/kernel/sysexe.c b/sw/z80/kernel/sysexe.c new file mode 100644 index 0000000..f020b88 --- /dev/null +++ b/sw/z80/kernel/sysexe.c @@ -0,0 +1,14 @@ +#include "sysexe.h" + +volatile struct sys_exec *exec_data = SYS_EXEC_ADDR; + +uint8_t vaddr_enabled() { + + return exec_data->virtual_addr; +} + +struct sys_progman * sys_prog_data(struct sys_progman *data) { + + *data = exec_data->sys_progman; + return data; +}
\ No newline at end of file |