diff options
author | Nao Pross <naopross@thearcway.org> | 2017-07-04 09:16:59 +0200 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2017-07-04 09:16:59 +0200 |
commit | a86838ead76c76e62369d461d5f4ff6ea6b07433 (patch) | |
tree | a2a5131ce8a4fb06c6cefceaa5fb9857a42ce553 /sw/z80/kernel/progman.c | |
parent | new components list and cpld test unit (diff) | |
parent | Order and update of the struct (diff) | |
download | z80uPC-a86838ead76c76e62369d461d5f4ff6ea6b07433.tar.gz z80uPC-a86838ead76c76e62369d461d5f4ff6ea6b07433.zip |
merge branch 'atlas' into naopross
Diffstat (limited to 'sw/z80/kernel/progman.c')
-rw-r--r-- | sw/z80/kernel/progman.c | 90 |
1 files changed, 90 insertions, 0 deletions
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 |