summaryrefslogtreecommitdiffstats
path: root/sw/z80/kernel/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sw/z80/kernel/include/devices.h2
-rw-r--r--sw/z80/kernel/include/drivers/pio.h (renamed from sw/z80/kernel/include/pio.h)0
-rw-r--r--sw/z80/kernel/include/drivers/usart.h155
-rw-r--r--sw/z80/kernel/include/login.h23
-rw-r--r--sw/z80/kernel/include/memory.h48
-rw-r--r--sw/z80/kernel/include/process.h42
-rw-r--r--sw/z80/kernel/include/progman.h109
-rw-r--r--sw/z80/kernel/include/sysexe.h55
-rw-r--r--sw/z80/kernel/include/types.h5
-rw-r--r--sw/z80/kernel/include/usart.h149
10 files changed, 251 insertions, 337 deletions
diff --git a/sw/z80/kernel/include/devices.h b/sw/z80/kernel/include/devices.h
index e8c183f..a846f9b 100644
--- a/sw/z80/kernel/include/devices.h
+++ b/sw/z80/kernel/include/devices.h
@@ -8,6 +8,8 @@
#define ADDR_DEV_CTC 0x4100
#define ADDR_DEV_PIO 0x4200
+#define ADDR_DEV_MMU
+
#define ADDR_DEV_RAM 0x8000
#endif
diff --git a/sw/z80/kernel/include/pio.h b/sw/z80/kernel/include/drivers/pio.h
index 5d289ca..5d289ca 100644
--- a/sw/z80/kernel/include/pio.h
+++ b/sw/z80/kernel/include/drivers/pio.h
diff --git a/sw/z80/kernel/include/drivers/usart.h b/sw/z80/kernel/include/drivers/usart.h
new file mode 100644
index 0000000..b85ee3e
--- /dev/null
+++ b/sw/z80/kernel/include/drivers/usart.h
@@ -0,0 +1,155 @@
+#ifndef __USART_H__
+#define __USART_H__
+
+#include "types.h"
+#include "devices.h"
+
+#include "string.h"
+
+// baudrate clock divisors
+// values from TL16C550C datasheet (table 9 for 1.8432 MHz crystal)
+#define USART_BAUDRATE_50 2304
+#define USART_BAUDRATE_75 1536
+#define USART_BAUDRATE_110 1047
+#define USART_BAUDRATE_134_5 857
+#define USART_BAUDRATE_150 768
+#define USART_BAUDRATE_300 384
+#define USART_BAUDRATE_600 192
+#define USART_BAUDRATE_1200 96
+#define USART_BAUDRATE_1800 64
+#define USART_BAUDRATE_2000 58
+#define USART_BAUDRATE_2400 48
+#define USART_BAUDRATE_3600 32
+#define USART_BAUDRATE_4800 24
+#define USART_BAUDRATE_7200 16
+#define USART_BAUDRATE_9600 12
+#define USART_BAUDRATE_19200 6
+#define USART_BAUDRATE_38400 3
+#define USART_BAUDRATE_56000 3
+
+// parity
+#define USART_PARITY_NONE 0
+#define USART_PARITY_EVEN 1
+#define USART_PARITY_ODD 2
+
+// stop bits
+#define USART_STOP_BITS_1 10
+#define USART_STOP_BITS_15 15
+#define USART_STOP_BITS_2 20
+
+// word lenght
+#define USART_WORD_LENGTH_5 0
+#define USART_WORD_LENGTH_6 1
+#define USART_WORD_LENGTH_7 2
+#define USART_WORD_LENGTH_8 3
+
+// autoflow
+#define USART_AUTOFLOW_ALL 3
+#define USART_AUTOFLOW_CTS 2
+#define USART_AUTOFLOW_OFF 0
+
+/* stuctures for usart registers */
+struct IER
+{
+ volatile uint received_data_interrupt :1;
+ volatile uint transmitter_empty_interrupt :1;
+ volatile uint receiver_line_status_interrupt :1;
+ volatile uint modem_status_interrupt :1;
+ volatile uint reserved :4;
+};
+
+struct IIR
+{
+ volatile uint interrupt_pending :1;
+ volatile uint interrupt_id :3;
+ volatile uint reserved :2;
+ volatile uint fifos :2;
+};
+
+struct FCR
+{
+ volatile uint fifo_enable :1;
+ volatile uint receiver_fifo_rst :1;
+ volatile uint trasmitter_fifo_rst :1;
+ volatile uint dma_mode_select :1;
+ volatile uint reserved :1;
+ volatile uint receiver_trigger :2;
+};
+
+struct LCR
+{
+ volatile uint word_length :2;
+ volatile uint stop_bits :1;
+ volatile uint parity :1;
+ volatile uint even_parity :1;
+ volatile uint stick_parity :1;
+ volatile uint break_control :1;
+ volatile uint divisor_latch_access :1;
+};
+
+struct MCR
+{
+ volatile uint data_terminal_ready :1;
+ volatile uint request_to_send :1;
+ volatile uint out1;
+ volatile uint out2;
+ volatile uint loop;
+ volatile uint autoflow :1;
+ volatile uint reserved :2;
+};
+
+struct LSR
+{
+ volatile uint data_ready :1;
+ volatile uint overrun_error :1;
+ volatile uint parity_error :1;
+ volatile uint framing_error :1;
+ volatile uint break_interrupt :1;
+ volatile uint transmitter_holder_empty :1;
+ volatile uint transmitter_empty :1;
+ volatile uint fifo_recv_error :1;
+};
+
+struct MSR
+{
+ volatile uint delta_cts :1;
+ volatile uint delta_data_set_ready :1;
+ volatile uint trailing_edge_ring_indicator :1;
+ volatile uint delta_data_carrier_detect :1;
+ volatile uint clear_to_send :1;
+ volatile uint data_set_ready :1;
+ volatile uint ring_indicator :1;
+ volatile uint data_carrier_detect :1;
+};
+
+/* this structure is only for internal usage */
+struct _usart_device
+{
+ register_t buffer; // also used as LSB for divisor latch
+ struct IER IER;
+ struct IIR IIR;
+ struct FCR FCR;
+ struct LCR LCR;
+ struct MCR MCR;
+ struct LSR LSR;
+ struct MSR MSR;
+ register_t scratch;
+};
+
+
+// setup functions (wrappers)
+void usart_set_baudrate(uint16_t baudrate);
+void usart_set_parity(int mode);
+void usart_set_stop_bits(int count);
+void usart_set_word_length(int length);
+void usart_set_autoflow(int mode);
+
+inline void usart_init(uint16_t baudrate, int parity, int stop_bits);
+
+void usart_transmit(uint8_t data);
+uint8_t usart_receive();
+
+int usart_write(uint8_t *data, size_t size);
+int usart_read(uint8_t *buffer, size_t count);
+
+#endif // __USART__H__
diff --git a/sw/z80/kernel/include/login.h b/sw/z80/kernel/include/login.h
deleted file mode 100644
index 5fa4b5e..0000000
--- a/sw/z80/kernel/include/login.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#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/memory.h b/sw/z80/kernel/include/memory.h
new file mode 100644
index 0000000..5bca5a5
--- /dev/null
+++ b/sw/z80/kernel/include/memory.h
@@ -0,0 +1,48 @@
+#ifndef __MEMORY_H__
+#define __MEMORY_H__
+
+#include "types.h"
+#include "devices.h"
+
+/* maximum number of pages on the system */
+#define PAGES_MAX_COUNT 32
+
+/* in our system there are only 16 pages since only 64KB can be addressed
+ * to optimize the memory management in ROM and RAM only pages from this set
+ * shall be used
+ */
+// ROM
+#define ADDR_PAGE_0 0x0000
+#define ADDR_PAGE_1 0x1000
+#define ADDR_PAGE_2 0x2000
+#define ADDR_PAGE_3 0x3000
+// IOSPACE
+#define ADDR_PAGE_4 0x4000
+#define ADDR_PAGE_5 0x5000
+#define ADDR_PAGE_6 0x6000
+#define ADDR_PAGE_7 0x7000
+// RAM
+#define ADDR_PAGE_8 0x8000
+#define ADDR_PAGE_9 0x9000
+#define ADDR_PAGE_10 0xA000
+#define ADDR_PAGE_11 0xB000
+#define ADDR_PAGE_12 0xC000
+#define ADDR_PAGE_13 0xD000
+#define ADDR_PAGE_14 0xE000
+#define ADDR_PAGE_15 0xF000
+
+struct page
+{
+ uint used :1;
+ uint8_t pid; // process owner of the page
+ uint16_t addr; // physical address
+};
+
+extern struct page pages_table[PAGES_MAX_COUNT];
+
+int mmu_write_table(void);
+
+int page_map(int page, int pid, uint16_t addr);
+int page_unmap(int page);
+
+#endif // __MEMORY_H__ \ No newline at end of file
diff --git a/sw/z80/kernel/include/process.h b/sw/z80/kernel/include/process.h
new file mode 100644
index 0000000..ffd39e7
--- /dev/null
+++ b/sw/z80/kernel/include/process.h
@@ -0,0 +1,42 @@
+#ifndef __PROCESS_H__
+#define __PROCESS_H__
+
+#include "types.h"
+
+ /* maximum number of processes (i.e. pages in ram)
+ * since each program can use only one page in ram
+ */
+#define PROC_COUNT 2
+
+struct executable
+{
+ void *text;
+ size_t text_size;
+ void *bss;
+ size_t bss_size;
+}
+
+struct process
+{
+ uint blocked :1; // process is waiting for hardware or locked
+ uint running :1; // pid is used
+ uint pages[4]; // pages used by the process
+ // TODO: implement quick callback?
+};
+
+/* the pid is defined with a single byte (pid_t is uint8_t), because of that
+ * there cannot be more than 255 processes open at the same time. this is a
+ * limitation but for our purposes is more than enough
+ */
+extern struct process proc_table[255];
+
+static pid_t newpid(void);
+
+int fork(void);
+int exec(char *path, char *args);
+int spawn(char *path, char *args);
+
+pid_t getpid(void);
+int kill(pid_t pid);
+
+#endif // __PROCESS_H__
diff --git a/sw/z80/kernel/include/progman.h b/sw/z80/kernel/include/progman.h
deleted file mode 100644
index b59e14a..0000000
--- a/sw/z80/kernel/include/progman.h
+++ /dev/null
@@ -1,109 +0,0 @@
-#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 prog_status {
-
- // 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
-};
-
-/*
-* 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
-*
-* ! Disable virtual addresses when this function is called
-*/
-
-#define PROG_REQ_FULL -1
-
-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 prog_space {
-
- 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
-};
-
-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 prog_data *data);
-
-/*
-* It sets a quit callback
-*/
-
-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(uint8_t force);
-void prog_1_quit(uint8_t force);
-
-#endif \ No newline at end of file
diff --git a/sw/z80/kernel/include/sysexe.h b/sw/z80/kernel/include/sysexe.h
deleted file mode 100644
index 9c13c09..0000000
--- a/sw/z80/kernel/include/sysexe.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#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/include/types.h b/sw/z80/kernel/include/types.h
index 552b7e9..44df3eb 100644
--- a/sw/z80/kernel/include/types.h
+++ b/sw/z80/kernel/include/types.h
@@ -3,11 +3,14 @@
#define register_t volatile unsigned char
+#define uint unsigned int
+
#define int8_t char
#define uint8_t unsigned char
#define int16_t int
-#define uint16_t unsigned int
+#define uint16_t unsigned long int
#define size_t uint16_t
+#define pid_t uint8_t
#endif
diff --git a/sw/z80/kernel/include/usart.h b/sw/z80/kernel/include/usart.h
deleted file mode 100644
index 3e5c070..0000000
--- a/sw/z80/kernel/include/usart.h
+++ /dev/null
@@ -1,149 +0,0 @@
-#ifndef __USART_H__
-#define __USART_H__
-
-#include "types.h"
-#include "devices.h"
-
-#include "string.h"
-
-// baudrate clock divisors
-// values from TL16C550C datasheet (table 9 for 1.8432 MHz crystal)
-#define USART_BAUDRATE_50 2304
-#define USART_BAUDRATE_75 1536
-#define USART_BAUDRATE_110 1047
-#define USART_BAUDRATE_134_5 857
-#define USART_BAUDRATE_150 768
-#define USART_BAUDRATE_300 384
-#define USART_BAUDRATE_600 192
-#define USART_BAUDRATE_1200 96
-#define USART_BAUDRATE_1800 64
-#define USART_BAUDRATE_2000 58
-#define USART_BAUDRATE_2400 48
-#define USART_BAUDRATE_3600 32
-#define USART_BAUDRATE_4800 24
-#define USART_BAUDRATE_7200 16
-#define USART_BAUDRATE_9600 12
-#define USART_BAUDRATE_19200 6
-#define USART_BAUDRATE_38400 3
-#define USART_BAUDRATE_56000 3
-
-// parity
-#define USART_PARITY_NONE 0
-#define USART_PARITY_EVEN 1
-#define USART_PARITY_ODD 2
-
-// stop bits
-#define USART_STOP_BITS_1 10
-#define USART_STOP_BITS_15 15
-#define USART_STOP_BITS_2 20
-
-// word lenght
-#define USART_WORD_LENGTH_5 0
-#define USART_WORD_LENGTH_6 1
-#define USART_WORD_LENGTH_7 2
-#define USART_WORD_LENGTH_8 3
-
-// autoflow
-#define USART_AUTOFLOW_ALL 3
-#define USART_AUTOFLOW_CTS 2
-#define USART_AUTOFLOW_OFF 0
-
-
-/* this structure is only for internal usage */
-struct _usart_device
-{
- register_t buffer; // also used as LSB for divisor latch
-
- struct IER
- {
- volatile int received_data_interrupt :1;
- volatile int transmitter_empty_interrupt :1;
- volatile int receiver_line_status_interrupt :1;
- volatile int modem_status_interrupt :1;
- volatile int reserved :4;
- } IER;
-
- struct IIR
- {
- volatile int interrupt_pending :1;
- volatile int interrupt_id :3;
- volatile int reserved :2;
- volatile int fifos :2;
- } IIR;
-
- struct FCR
- {
- volatile int fifo_enable :1;
- volatile int receiver_fifo_rst :1;
- volatile int trasmitter_fifo_rst :1;
- volatile int dma_mode_select :1;
- volatile int reserved :1;
- volatile int receiver_trigger :2;
- } FCR;
-
- struct LCR
- {
- volatile int word_length :2;
- volatile int stop_bits :1;
- volatile int parity :1;
- volatile int even_parity :1;
- volatile int stick_parity :1;
- volatile int break_control :1;
- volatile int divisor_latch_access :1;
- } LCR;
-
- struct MCR
- {
- volatile int data_terminal_ready :1;
- volatile int request_to_send :1;
- volatile int out1;
- volatile int out2;
- volatile int loop;
- volatile int autoflow :1;
- volatile int reserved :2;
- } MCR;
-
- struct LSR
- {
- volatile int data_ready :1;
- volatile int overrun_error :1;
- volatile int parity_error :1;
- volatile int framing_error :1;
- volatile int break_interrupt :1;
- volatile int transmitter_holder_empty :1;
- volatile int transmitter_empty :1;
- volatile int fifo_recv_error :1;
- } LSR;
-
- struct MSR
- {
- volatile int delta_cts :1;
- volatile int delta_data_set_ready :1;
- volatile int trailing_edge_ring_indicator :1;
- volatile int delta_data_carrier_detect :1;
- volatile int clear_to_send :1;
- volatile int data_set_ready :1;
- volatile int ring_indicator :1;
- volatile int data_carrier_detect :1;
- } MSR;
-
- register_t scratch;
-};
-
-
-// setup functions (wrappers)
-void usart_set_baudrate(uint16_t baudrate);
-void usart_set_parity(int mode);
-void usart_set_stop_bits(int count);
-void usart_set_word_length(int length);
-void usart_set_autoflow(int mode);
-
-inline void usart_init(uint16_t baudrate, int parity, int stop_bits);
-
-void usart_transmit(uint8_t data);
-uint8_t usart_receive();
-
-int usart_write(uint8_t *data, size_t size);
-int usart_read(uint8_t *buffer, size_t count);
-
-#endif // __USART__H__