summaryrefslogtreecommitdiffstats
path: root/sw/z80
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sw/z80/build/helvetiOS.lk11
-rw-r--r--sw/z80/build/helvetiOS.map182
-rw-r--r--sw/z80/build/helvetiOS.noi50
-rw-r--r--sw/z80/build/kernel/kernel.asm65
-rw-r--r--sw/z80/build/kernel/kernel.lst65
-rw-r--r--sw/z80/build/kernel/kernel.rel23
-rw-r--r--sw/z80/build/kernel/kernel.sym27
-rw-r--r--sw/z80/crt0.rel86
-rw-r--r--sw/z80/kernel/boot_loader.c43
-rw-r--r--sw/z80/kernel/include/boot.h35
-rw-r--r--sw/z80/kernel/include/progman.h86
-rw-r--r--sw/z80/kernel/programs.c110
12 files changed, 783 insertions, 0 deletions
diff --git a/sw/z80/build/helvetiOS.lk b/sw/z80/build/helvetiOS.lk
new file mode 100644
index 0000000..c16247f
--- /dev/null
+++ b/sw/z80/build/helvetiOS.lk
@@ -0,0 +1,11 @@
+-mjwx
+-i build/helvetiOS.hex
+-b _CODE = 0x0800
+-b _DATA = 0x8000
+-k /usr/bin/../share/sdcc/lib/z80
+-k /usr/share/sdcc/lib/z80
+-l z80
+crt0.rel
+build/kernel/kernel.rel
+
+-e
diff --git a/sw/z80/build/helvetiOS.map b/sw/z80/build/helvetiOS.map
new file mode 100644
index 0000000..98210c7
--- /dev/null
+++ b/sw/z80/build/helvetiOS.map
@@ -0,0 +1,182 @@
+ ASxxxx Linker V03.00 + NoICE + sdld, page 1.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+. .ABS. 00000000 00000000 = 0. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ 00000000 .__.ABS. kernel
+ 00000000 l__BSEG
+ 00000000 l__BSS
+ 00000000 l__CABS
+ 00000000 l__DABS
+ 00000000 l__DATA
+ 00000000 l__HEADER
+ 00000000 l__HEAP
+ 00000000 l__HOME
+ 00000000 l__INITIALIZED
+ 00000000 l__INITIALIZER
+ 00000000 s__CABS
+ 00000000 s__DABS
+ 00000000 s__HEADER
+ 00000000 s__HEADER0
+ 00000000 s__HEADER1
+ 00000000 s__HEADER2
+ 00000000 s__HEADER3
+ 00000000 s__HEADER4
+ 00000000 s__HEADER5
+ 00000000 s__HEADER6
+ 00000000 s__HEADER7
+ 00000000 s__HEADER8
+ 00000001 l__GSFINAL
+ 00000002 l__HEADER1
+ 00000002 l__HEADER2
+ 00000002 l__HEADER3
+ 00000002 l__HEADER4
+ 00000002 l__HEADER5
+ 00000002 l__HEADER6
+ 00000002 l__HEADER7
+ 00000003 l__HEADER0
+ 00000006 l__GSINIT
+ 0000000C l__HEADER8
+ 00000017 l__CODE
+ 00000800 s__CODE
+ 00000817 s__GSINIT
+ 00000817 s__HOME
+ 00000817 s__INITIALIZER
+ 0000081D s__GSFINAL
+ 00008000 s__BSEG
+ 00008000 s__BSS
+ 00008000 s__DATA
+ 00008000 s__HEAP
+ 00008000 s__INITIALIZED
+ ASxxxx Linker V03.00 + NoICE + sdld, page 2.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_CODE 00000800 00000017 = 23. bytes (REL,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ 00000800 __clock crt0
+ 00000804 _exit crt0
+ 0000080A _main kernel
+ ASxxxx Linker V03.00 + NoICE + sdld, page 3.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER0 00000000 00000003 = 3. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 4.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER1 00000000 00000002 = 2. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 5.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER2 00000000 00000002 = 2. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 6.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER3 00000000 00000002 = 2. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 7.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER4 00000000 00000002 = 2. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 8.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER5 00000000 00000002 = 2. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 9.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER6 00000000 00000002 = 2. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 10.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER7 00000000 00000002 = 2. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 11.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_HEADER8 00000000 0000000C = 12. bytes (ABS,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 12.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_GSINIT 00000817 00000006 = 6. bytes (REL,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ 00000817 gsinit crt0
+
+ ASxxxx Linker V03.00 + NoICE + sdld, page 13.
+Hexadecimal [32-Bits]
+
+Area Addr Size Decimal Bytes (Attributes)
+-------------------------------- ---- ---- ------- ----- ------------
+_GSFINAL 0000081D 00000001 = 1. bytes (REL,CON)
+
+ Value Global Global Defined In Module
+ ----- -------------------------------- ------------------------
+ ASxxxx Linker V03.00 + NoICE + sdld, page 14.
+
+Files Linked [ module(s) ]
+
+crt0.rel [ crt0 ]
+build/kernel/kernel.rel [ kernel ]
+
+ ASxxxx Linker V03.00 + NoICE + sdld, page 15.
+
+User Base Address Definitions
+
+_CODE = 0x0800
+_DATA = 0x8000
+
+ \ No newline at end of file
diff --git a/sw/z80/build/helvetiOS.noi b/sw/z80/build/helvetiOS.noi
new file mode 100644
index 0000000..1b9c284
--- /dev/null
+++ b/sw/z80/build/helvetiOS.noi
@@ -0,0 +1,50 @@
+DEF .__.ABS. 0x0
+DEF l__BSEG 0x0
+DEF l__BSS 0x0
+DEF l__CABS 0x0
+DEF l__DABS 0x0
+DEF l__DATA 0x0
+DEF l__HEADER 0x0
+DEF l__HEAP 0x0
+DEF l__HOME 0x0
+DEF l__INITIALIZED 0x0
+DEF l__INITIALIZER 0x0
+DEF s__CABS 0x0
+DEF s__DABS 0x0
+DEF s__HEADER 0x0
+DEF s__HEADER0 0x0
+DEF s__HEADER1 0x0
+DEF s__HEADER2 0x0
+DEF s__HEADER3 0x0
+DEF s__HEADER4 0x0
+DEF s__HEADER5 0x0
+DEF s__HEADER6 0x0
+DEF s__HEADER7 0x0
+DEF s__HEADER8 0x0
+DEF l__GSFINAL 0x1
+DEF l__HEADER1 0x2
+DEF l__HEADER2 0x2
+DEF l__HEADER3 0x2
+DEF l__HEADER4 0x2
+DEF l__HEADER5 0x2
+DEF l__HEADER6 0x2
+DEF l__HEADER7 0x2
+DEF l__HEADER0 0x3
+DEF l__GSINIT 0x6
+DEF l__HEADER8 0xC
+DEF l__CODE 0x17
+DEF s__CODE 0x800
+DEF s__GSINIT 0x817
+DEF s__HOME 0x817
+DEF s__INITIALIZER 0x817
+DEF s__GSFINAL 0x81D
+DEF s__BSEG 0x8000
+DEF s__BSS 0x8000
+DEF s__DATA 0x8000
+DEF s__HEAP 0x8000
+DEF s__INITIALIZED 0x8000
+DEF __clock 0x800
+DEF _exit 0x804
+DEF _main 0x80A
+DEF gsinit 0x817
+LOAD build/helvetiOS.ihx
diff --git a/sw/z80/build/kernel/kernel.asm b/sw/z80/build/kernel/kernel.asm
new file mode 100644
index 0000000..a29db4d
--- /dev/null
+++ b/sw/z80/build/kernel/kernel.asm
@@ -0,0 +1,65 @@
+;--------------------------------------------------------
+; File Created by SDCC : free open source ANSI-C Compiler
+; Version 3.5.0 #9253 (Mar 24 2016) (Linux)
+; This file was generated Tue May 2 18:13:35 2017
+;--------------------------------------------------------
+ .module kernel
+ .optsdcc -mz80
+
+;--------------------------------------------------------
+; Public variables in this module
+;--------------------------------------------------------
+ .globl _main
+;--------------------------------------------------------
+; special function registers
+;--------------------------------------------------------
+;--------------------------------------------------------
+; ram data
+;--------------------------------------------------------
+ .area _DATA
+;--------------------------------------------------------
+; ram data
+;--------------------------------------------------------
+ .area _INITIALIZED
+;--------------------------------------------------------
+; absolute external ram data
+;--------------------------------------------------------
+ .area _DABS (ABS)
+;--------------------------------------------------------
+; global & static initialisations
+;--------------------------------------------------------
+ .area _HOME
+ .area _GSINIT
+ .area _GSFINAL
+ .area _GSINIT
+;--------------------------------------------------------
+; Home
+;--------------------------------------------------------
+ .area _HOME
+ .area _HOME
+;--------------------------------------------------------
+; code
+;--------------------------------------------------------
+ .area _CODE
+;kernel/kernel.c:4: void main(void)
+; ---------------------------------
+; Function main
+; ---------------------------------
+_main::
+;kernel/kernel.c:7: for (i = 0; i < 10; i++) {
+ ld de,#0x000A
+00104$:
+;kernel/kernel.c:8: j--;
+ ld c,e
+ ld b,d
+ dec bc
+ ld e, c
+;kernel/kernel.c:7: for (i = 0; i < 10; i++) {
+ ld a,b
+ ld d,a
+ or a,c
+ jr NZ,00104$
+ ret
+ .area _CODE
+ .area _INITIALIZER
+ .area _CABS (ABS)
diff --git a/sw/z80/build/kernel/kernel.lst b/sw/z80/build/kernel/kernel.lst
new file mode 100644
index 0000000..8ec7438
--- /dev/null
+++ b/sw/z80/build/kernel/kernel.lst
@@ -0,0 +1,65 @@
+ 1 ;--------------------------------------------------------
+ 2 ; File Created by SDCC : free open source ANSI-C Compiler
+ 3 ; Version 3.5.0 #9253 (Mar 24 2016) (Linux)
+ 4 ; This file was generated Tue May 2 18:13:35 2017
+ 5 ;--------------------------------------------------------
+ 6 .module kernel
+ 7 .optsdcc -mz80
+ 8
+ 9 ;--------------------------------------------------------
+ 10 ; Public variables in this module
+ 11 ;--------------------------------------------------------
+ 12 .globl _main
+ 13 ;--------------------------------------------------------
+ 14 ; special function registers
+ 15 ;--------------------------------------------------------
+ 16 ;--------------------------------------------------------
+ 17 ; ram data
+ 18 ;--------------------------------------------------------
+ 19 .area _DATA
+ 20 ;--------------------------------------------------------
+ 21 ; ram data
+ 22 ;--------------------------------------------------------
+ 23 .area _INITIALIZED
+ 24 ;--------------------------------------------------------
+ 25 ; absolute external ram data
+ 26 ;--------------------------------------------------------
+ 27 .area _DABS (ABS)
+ 28 ;--------------------------------------------------------
+ 29 ; global & static initialisations
+ 30 ;--------------------------------------------------------
+ 31 .area _HOME
+ 32 .area _GSINIT
+ 33 .area _GSFINAL
+ 34 .area _GSINIT
+ 35 ;--------------------------------------------------------
+ 36 ; Home
+ 37 ;--------------------------------------------------------
+ 38 .area _HOME
+ 39 .area _HOME
+ 40 ;--------------------------------------------------------
+ 41 ; code
+ 42 ;--------------------------------------------------------
+ 43 .area _CODE
+ 44 ;kernel/kernel.c:4: void main(void)
+ 45 ; ---------------------------------
+ 46 ; Function main
+ 47 ; ---------------------------------
+ 0000 48 _main::
+ 49 ;kernel/kernel.c:7: for (i = 0; i < 10; i++) {
+ 0000 11 0A 00 [10] 50 ld de,#0x000A
+ 0003 51 00104$:
+ 52 ;kernel/kernel.c:8: j--;
+ 0003 4B [ 4] 53 ld c,e
+ 0004 42 [ 4] 54 ld b,d
+ 0005 0B [ 6] 55 dec bc
+ 0006 59 [ 4] 56 ld e, c
+ 57 ;kernel/kernel.c:7: for (i = 0; i < 10; i++) {
+ 0007 78 [ 4] 58 ld a,b
+ 0008 57 [ 4] 59 ld d,a
+ 0009 B1 [ 4] 60 or a,c
+ 000A 20 F7 [12] 61 jr NZ,00104$
+ 000C C9 [10] 62 ret
+ 63 .area _CODE
+ 64 .area _INITIALIZER
+ 65 .area _CABS (ABS)
diff --git a/sw/z80/build/kernel/kernel.rel b/sw/z80/build/kernel/kernel.rel
new file mode 100644
index 0000000..1079edc
--- /dev/null
+++ b/sw/z80/build/kernel/kernel.rel
@@ -0,0 +1,23 @@
+XL2
+H 9 areas 2 global symbols
+M kernel
+O -mz80
+S .__.ABS. Def0000
+A _CODE size D flags 0 addr 0
+S _main Def0000
+A _DATA size 0 flags 0 addr 0
+A _INITIALIZED size 0 flags 0 addr 0
+A _DABS size 0 flags 8 addr 0
+A _HOME size 0 flags 0 addr 0
+A _GSINIT size 0 flags 0 addr 0
+A _GSFINAL size 0 flags 0 addr 0
+A _INITIALIZER size 0 flags 0 addr 0
+A _CABS size 0 flags 8 addr 0
+T 00 00
+R 00 00 00 00
+T 00 00 11 0A 00
+R 00 00 00 00
+T 03 00
+R 00 00 00 00
+T 03 00 4B 42 0B 59 78 57 B1 20 F7 C9
+R 00 00 00 00
diff --git a/sw/z80/build/kernel/kernel.sym b/sw/z80/build/kernel/kernel.sym
new file mode 100644
index 0000000..d01735c
--- /dev/null
+++ b/sw/z80/build/kernel/kernel.sym
@@ -0,0 +1,27 @@
+ ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180), page 1.
+Hexadecimal [16-Bits]
+
+Symbol Table
+
+ .__.$$$. = 2710 L
+ .__.ABS. = 0000 G
+ .__.CPU. = 0000 L
+ .__.H$L. = 0000 L
+ 0 _main 0000 GR
+
+
+ ASxxxx Assembler V02.00 + NoICE + SDCC mods (Zilog Z80 / Hitachi HD64180), page 2.
+Hexadecimal [16-Bits]
+
+Area Table
+
+ 0 _CODE size D flags 0
+ 1 _DATA size 0 flags 0
+ 2 _INITIALIZED size 0 flags 0
+ 3 _DABS size 0 flags 8
+ 4 _HOME size 0 flags 0
+ 5 _GSINIT size 0 flags 0
+ 6 _GSFINAL size 0 flags 0
+ 7 _INITIALIZER size 0 flags 0
+ 8 _CABS size 0 flags 8
+
diff --git a/sw/z80/crt0.rel b/sw/z80/crt0.rel
new file mode 100644
index 0000000..809c0e6
--- /dev/null
+++ b/sw/z80/crt0.rel
@@ -0,0 +1,86 @@
+XL2
+H 14 areas 5 global symbols
+M crt0
+S _main Ref0000
+S .__.ABS. Def0000
+A _CODE size A flags 0 addr 0
+S __clock Def0000
+S _exit Def0004
+A _HEADER size 0 flags 8 addr 0
+A _HEADER0 size 3 flags 8 addr 0
+A _HEADER1 size 2 flags 8 addr 8
+A _HEADER2 size 2 flags 8 addr 10
+A _HEADER3 size 2 flags 8 addr 18
+A _HEADER4 size 2 flags 8 addr 20
+A _HEADER5 size 2 flags 8 addr 28
+A _HEADER6 size 2 flags 8 addr 30
+A _HEADER7 size 2 flags 8 addr 38
+A _HEADER8 size C flags 8 addr 100
+A _HOME size 0 flags 0 addr 0
+A _INITIALIZER size 0 flags 0 addr 0
+A _GSINIT size 6 flags 0 addr 0
+S gsinit Def0000
+A _GSFINAL size 1 flags 0 addr 0
+A _DATA size 0 flags 0 addr 0
+A _INITIALIZED size 0 flags 0 addr 0
+A _BSEG size 0 flags 0 addr 0
+A _BSS size 0 flags 0 addr 0
+A _HEAP size 0 flags 0 addr 0
+T 00 00
+R 00 00 02 00
+T 00 00 C3 00 01
+R 00 00 02 00 00 03 0A 00
+T 08 00
+R 00 00 03 00
+T 08 00 ED 4D
+R 00 00 03 00
+T 10 00
+R 00 00 04 00
+T 10 00 ED 4D
+R 00 00 04 00
+T 18 00
+R 00 00 05 00
+T 18 00 ED 4D
+R 00 00 05 00
+T 20 00
+R 00 00 06 00
+T 20 00 ED 4D
+R 00 00 06 00
+T 28 00
+R 00 00 07 00
+T 28 00 ED 4D
+R 00 00 07 00
+T 30 00
+R 00 00 08 00
+T 30 00 ED 4D
+R 00 00 08 00
+T 38 00
+R 00 00 09 00
+T 38 00 ED 4D
+R 00 00 09 00
+T 00 01
+R 00 00 0A 00
+T 00 01
+R 00 00 0A 00
+T 00 01 31 FF FF CD 00 00 CD 00 00 C3 04 00
+R 00 00 0A 00 00 06 0D 00 02 09 00 00 00 0C 00 00
+T 00 00
+R 00 00 00 00
+T 00 00 3E 02 CF C9
+R 00 00 00 00
+T 04 00
+R 00 00 00 00
+T 04 00 3E 00 CF
+R 00 00 00 00
+T 07 00
+R 00 00 00 00
+T 07 00 76 18 FD
+R 00 00 00 00
+T 00 00
+R 00 00 0D 00
+T 00 00 78 B1 28 02 ED B0
+R 00 00 0D 00
+T 06 00
+R 00 00 0D 00
+T 00 00 C9
+R 00 00 0E 00
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