From f85e54f7982d5fefecddccbb11f5aabd478b91d6 Mon Sep 17 00:00:00 2001
From: "leleraffa97@hotmail.it" <leleraffa97@hotmail.it>
Date: Mon, 19 Jun 2017 13:46:16 +0200
Subject: Authentication section Programs management

---
 sw/z80/kernel/boot_loader.c     | 30 ++++++++++++++++++++++++++++++
 sw/z80/kernel/include/boot.h    | 17 +++++++++++++++++
 sw/z80/kernel/include/progman.h | 23 +++++++++++++++++++++++
 sw/z80/kernel/programs.c        | 10 ++++++++++
 4 files changed, 80 insertions(+)

diff --git a/sw/z80/kernel/boot_loader.c b/sw/z80/kernel/boot_loader.c
index b7873ec..ddca4f9 100644
--- a/sw/z80/kernel/boot_loader.c
+++ b/sw/z80/kernel/boot_loader.c
@@ -10,4 +10,34 @@ 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
index d581687..5310e45 100644
--- a/sw/z80/kernel/include/boot.h
+++ b/sw/z80/kernel/include/boot.h
@@ -1,10 +1,15 @@
 #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
@@ -15,4 +20,16 @@ struct exec_status {
 
 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
index b37e9e9..0f56bb3 100644
--- a/sw/z80/kernel/include/progman.h
+++ b/sw/z80/kernel/include/progman.h
@@ -39,6 +39,29 @@ void progman_init();
 
 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
 */
diff --git a/sw/z80/kernel/programs.c b/sw/z80/kernel/programs.c
index 31593d1..0f75887 100644
--- a/sw/z80/kernel/programs.c
+++ b/sw/z80/kernel/programs.c
@@ -35,6 +35,16 @@ int8_t prog_req(struct program_info *info) {
     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;
-- 
cgit v1.2.1