diff options
Diffstat (limited to 'sw/z80/kernel')
-rw-r--r-- | sw/z80/kernel/boot_loader.c | 43 | ||||
-rw-r--r-- | sw/z80/kernel/include/boot.h | 35 | ||||
-rw-r--r-- | sw/z80/kernel/include/progman.h | 86 | ||||
-rw-r--r-- | sw/z80/kernel/programs.c | 110 |
4 files changed, 274 insertions, 0 deletions
diff --git a/sw/z80/kernel/boot_loader.c b/sw/z80/kernel/boot_loader.c new file mode 100644 index 0000000..ddca4f9 --- /dev/null +++ b/sw/z80/kernel/boot_loader.c @@ -0,0 +1,43 @@ +#include "boot.h" +#include "progman.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) { + + 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; +} + +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++; + } +}
\ No newline at end of file diff --git a/sw/z80/kernel/include/boot.h b/sw/z80/kernel/include/boot.h new file mode 100644 index 0000000..5310e45 --- /dev/null +++ b/sw/z80/kernel/include/boot.h @@ -0,0 +1,35 @@ +#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/progman.h b/sw/z80/kernel/include/progman.h new file mode 100644 index 0000000..0f56bb3 --- /dev/null +++ b/sw/z80/kernel/include/progman.h @@ -0,0 +1,86 @@ +#ifndef PROGRAM_MAN +#define PROGRAM_MAN + +#include "types.h" + +#define PROG_0 0x0 +#define PROG_1 0x1 + +#define PROG_VSTART 0x1000 +#define PROG_0_PREFIX 0xA000 +#define PROG_1_PREFIX 0xC000 + +#define PROG_0_INFO // TODO +#define PROG_1_INFO // TODO find a space in the ram + +struct program_info { + + volatile int enabled:1; + volatile int running:1; + volatile int exiting:1; + volatile int heap_addr:13; + volatile void (*quit_cb)(void); // 16 +}; + +/* +* Initialize the program manager system +*/ + +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 +*/ + +#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); + +/* +* 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 +*/ + +struct program_base { + + void * inst_set; // pointer to the instructions set + 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); + +/* +* It jumps the program counter to the given one +*/ + +void prog_exec(int8_t id, struct program_info *info); + +/* +* It sets a quit callback +*/ + +void prog_0_qcb(void (*callback)(void)); +void prog_1_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(); + +#endif
\ No newline at end of file diff --git a/sw/z80/kernel/programs.c b/sw/z80/kernel/programs.c new file mode 100644 index 0000000..0f75887 --- /dev/null +++ b/sw/z80/kernel/programs.c @@ -0,0 +1,110 @@ +#include "progman.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) { + + // TODO, implements program allocation +} + +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 |