diff options
Diffstat (limited to '')
-rw-r--r-- | sw/z80/kernel/drivers/ctc.c | 1 | ||||
-rw-r--r-- | sw/z80/kernel/drivers/pio.c | 29 | ||||
-rw-r--r-- | sw/z80/kernel/include/drivers/ctc.h | 6 | ||||
-rw-r--r-- | sw/z80/kernel/include/drivers/pio.h | 20 | ||||
-rw-r--r-- | sw/z80/kernel/include/fs/fs.h | 2 | ||||
-rw-r--r-- | sw/z80/kernel/include/memory.h | 10 | ||||
-rw-r--r-- | sw/z80/kernel/include/process.h | 21 | ||||
-rw-r--r-- | sw/z80/kernel/include/syscall.h | 20 | ||||
-rw-r--r-- | sw/z80/kernel/include/types.h | 42 | ||||
-rw-r--r-- | sw/z80/kernel/memory.c | 32 | ||||
-rw-r--r-- | sw/z80/kernel/process.c | 38 |
11 files changed, 140 insertions, 81 deletions
diff --git a/sw/z80/kernel/drivers/ctc.c b/sw/z80/kernel/drivers/ctc.c new file mode 100644 index 0000000..e23ed8e --- /dev/null +++ b/sw/z80/kernel/drivers/ctc.c @@ -0,0 +1 @@ +#include "drivers/ctc.h"
\ No newline at end of file diff --git a/sw/z80/kernel/drivers/pio.c b/sw/z80/kernel/drivers/pio.c index 289ebe0..4321fb8 100644 --- a/sw/z80/kernel/drivers/pio.c +++ b/sw/z80/kernel/drivers/pio.c @@ -3,17 +3,38 @@ static uint8_t *pio_port = (uint8_t *) ADDR_DEV_PIO; static uint8_t *pio_ctrl = (uint8_t *) (ADDR_DEV_PIO + 2); -void _pio_data(int port, uint8_t data) +inline void _pio_data(int port, uint8_t data) { *(pio_port + port) = data; } -void _pio_command(int port, uint8_t cmd) +inline void _pio_control(int port, uint8_t cmd) { *(pio_ctrl + port) = cmd; } -/* void pio_set_mode(int port, int mode) +void pio_set_mode(int port, int mode, uint8_t io) { + // 0x0F is a control sequence to set mode + _pio_control(port, ((mode << 6) | 0x0F)); -} */ + // this mode requires an additional argument that sets + // a mode for each pin + if (mode == PIO_MODE_BIT_IO) { + _pio_control(port, io); + } +} + +void pio_set_interrupts(int port, int control) +{ + // 0x07 is a control sequence to set interrupts + _pio_control(port, (control | 0x07)); +} + +void pio_set_interrupts_mask(int port, int control, uint8_t mask) +{ + // 0x17 is a control sequence to set interrupts + // and to interpret the next byte as a mask + _pio_control(port, (control | 0x17)); + _pio_control(port, mask); +} diff --git a/sw/z80/kernel/include/drivers/ctc.h b/sw/z80/kernel/include/drivers/ctc.h new file mode 100644 index 0000000..488e02b --- /dev/null +++ b/sw/z80/kernel/include/drivers/ctc.h @@ -0,0 +1,6 @@ +#ifndef __CTC_H__ +#define __CTC_H__ + +void ctc_control() + +#endif /* __CTC_H__ */
\ No newline at end of file diff --git a/sw/z80/kernel/include/drivers/pio.h b/sw/z80/kernel/include/drivers/pio.h index 5d289ca..0df2ed0 100644 --- a/sw/z80/kernel/include/drivers/pio.h +++ b/sw/z80/kernel/include/drivers/pio.h @@ -7,25 +7,27 @@ #define PIO_A 0 #define PIO_B 1 -#define PIO_MODE_0 0 -#define PIO_MODE_1 1 -#define PIO_MODE_2 2 -#define PIO_MODE_3 3 +#define PIO_MODE_BYTE_IN 0 +#define PIO_MODE_BYTE_OUT 1 +#define PIO_MODE_BYTE_BI 2 +#define PIO_MODE_BIT_IO 3 #define PIO_INT_ACTIVE_HIGH (1<<5) #define PIO_INT_AND_MODE (1<<6) #define PIO_INT_ENABLE (1<<7) -void _pio_data(int port, uint8_t data); -void _pio_command(int port, uint8_t cmd); +inline void _pio_data(int port, uint8_t data); +inline void _pio_control(int port, uint8_t cmd); + +void pio_set_mode(int port, int mode, uint8_t io); -void pio_set_mode(int port, int mode); void pio_set_interrupts(int port, int control); -void pio_set_interrupts_mask(int port, uint8_t mask); -void pio_set_io(int port, uint8_t io); +void pio_set_interrupts_mask(int port, int control, uint8_t mask); // uint8_t pio_read_data(int port); +uint8_t pio_read(int port); +void pio_write(int port, uint8_t data); inline int pio_read_pin(int port, uint8_t pin); inline void pio_write_pin(int port, uint8_t pin); diff --git a/sw/z80/kernel/include/fs/fs.h b/sw/z80/kernel/include/fs/fs.h index b92303d..ad20adb 100644 --- a/sw/z80/kernel/include/fs/fs.h +++ b/sw/z80/kernel/include/fs/fs.h @@ -44,7 +44,7 @@ struct fs_inode #define FS_INODE_ROOT(inode) {inode.dev = 0xff; inode.inode = 0x0} #define FS_INODE_NULL(inode) {inode.dev = 0x80; inode.inode = 0x0} -#define FS_USE_ROM(inode) inode.dev == 0x7f +#define FS_USE_ROM(inode) {inode.dev == 0x7f} /* get block seek in current device */ devsize_t fs_block(blk_t block); diff --git a/sw/z80/kernel/include/memory.h b/sw/z80/kernel/include/memory.h index 45fc325..67c4b88 100644 --- a/sw/z80/kernel/include/memory.h +++ b/sw/z80/kernel/include/memory.h @@ -6,6 +6,7 @@ /* maximum number of pages on the system */ #define PAGES_MAX_COUNT 32 +#define PAGE_SIZE 1000 /* 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 @@ -31,17 +32,18 @@ #define ADDR_PAGE_14 0xE000 #define ADDR_PAGE_15 0xF000 +#define ADDR_PAGE_FIRST ADDR_PAGE_8 +#define ADDR_PAGE_LAST ADDR_PAGE_15 + struct page { - uint used :1; - pid_t pid; // process owner of the page + pid_t pid; // process owner of the page (0 if free) uint16_t addr; // physical address }; -extern struct page pages_table[PAGES_MAX_COUNT]; - int mmu_write_table(void); +int page_new(void); int page_map(int page, int pid, uint16_t addr); int page_unmap(int page); diff --git a/sw/z80/kernel/include/process.h b/sw/z80/kernel/include/process.h index d7aa7fd..3b0c843 100644 --- a/sw/z80/kernel/include/process.h +++ b/sw/z80/kernel/include/process.h @@ -9,6 +9,12 @@ */ #define PROC_COUNT 2 +/* 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 + */ +#define PID_COUNT_MAX 255 + struct executable { void *text; @@ -19,19 +25,12 @@ struct executable struct process { - uint blocked :1; // process is waiting for hardware or locked - uint running :1; // pid is used - struct page pages[4]; // pages used by the process - // TODO: implement quick callback? + uint blocked :1; // process is waiting for hardware or locked + uint running :1; // pid is used + uint pages; // number of pages used by the process + struct page page[4]; // pages used by the process }; -/* 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]; -extern struct process *current_proc; - pid_t newpid(void); int fork(void); diff --git a/sw/z80/kernel/include/syscall.h b/sw/z80/kernel/include/syscall.h deleted file mode 100644 index 29941c9..0000000 --- a/sw/z80/kernel/include/syscall.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __SYS_CALL_H__ -#define __SYS_CALL_H__ - -/* -* Enable / disable virtual address traslation -*/ - -extern void v_addr(uint8_t flag); - -/* -* Programs execution -*/ - -extern void prog_exec_0(void); -extern void prog_exec_1(void); - -extern void prog_stop_0(void); -extern void prog_stop_1(void); - -#endif
\ No newline at end of file diff --git a/sw/z80/kernel/include/types.h b/sw/z80/kernel/include/types.h index c01afb2..c6e620b 100644 --- a/sw/z80/kernel/include/types.h +++ b/sw/z80/kernel/include/types.h @@ -3,39 +3,35 @@ /* only types from primitive types are defined in this file */ -#define register_t volatile unsigned char +typedef volatile unsigned char register_t; -#define uint unsigned int +typedef unsigned int uint; -#define int8_t char -#define uint8_t unsigned char -#define int16_t int -#define uint16_t unsigned short int +typedef char int8_t; +typedef unsigned char uint8_t; +typedef int int16_t; +typedef unsigned int uint16_t; +typedef long int int32_t; +typedef unsigned long int uint32_t; -#define uint32_t unsigned long int +typedef uint16_t size_t; +typedef int16_t ssize_t; -#define size_t uint16_t -#define ssize_t int16_t -#define pid_t uint8_t +typedef uint8_t pid_t; +typedef uint16_t ino_t; -#define ino_t uint16_t +typedef uint8_t dev_t; +typedef uint32_t devsize_t; +typedef uint8_t fd_t; +typedef uint16_t blk_t; +typedef uint8_t user_t; -#define dev_t uint8_t -#define devsize_t uint32_t - -#define fd_t uint8_t - -#define blk_t uint16_t - -#define user_t int8_t - -typedef struct -{ +typedef struct { uint8_t member[3]; } uint24_t; -#define fsize_t uint32_t +typedef uint32_t fsize_t; typedef struct { diff --git a/sw/z80/kernel/memory.c b/sw/z80/kernel/memory.c index bcda3c3..cda62ca 100644 --- a/sw/z80/kernel/memory.c +++ b/sw/z80/kernel/memory.c @@ -1,13 +1,13 @@ #include "memory.h" -struct page pages_table[PAGES_MAX_COUNT]; +static struct page pages_table[PAGES_MAX_COUNT]; int mmu_write_table(void) { int i; for (i = 0; i < PAGES_MAX_COUNT; i++) { - if (pages_table[i].used) { + if (pages_table[i].pid != 0) { // write to mmu table } } @@ -15,18 +15,37 @@ int mmu_write_table(void) return 0; } +int page_new(void) +{ + int i, addr, used; + for (addr = ADDR_PAGE_FIRST; addr < ADDR_PAGE_LAST; addr += PAGE_SIZE) { + used = 0; + + for (i = 0; i < PAGES_MAX_COUNT; i++) { + if (page_map[i].addr == addr) { + used = 1; + break; + } + } + + if (!used) + return i; + } + + return -1; +} + int page_map(int page, int pid, uint16_t addr) { if (page >= PAGES_MAX_COUNT) return -1; - if (pages_table[page].used) + if (pages_table[page].pid != 0) return -2; pages_table[page].addr = addr; pages_table[page].pid = pid; - pages_table[page].used = 1; return 0; } @@ -35,10 +54,11 @@ int page_unmap(int page) if (page >= PAGES_MAX_COUNT) return -1; - if (pages_table[page].used == 0) + if (pages_table[page].pid == 0) return -2; - pages_table[page].used = 0; + pages_table[page].pid = 0; + pages_table[page].addr = 0; return 0; } diff --git a/sw/z80/kernel/process.c b/sw/z80/kernel/process.c index 49b86b8..049c88c 100644 --- a/sw/z80/kernel/process.c +++ b/sw/z80/kernel/process.c @@ -1,16 +1,48 @@ #include "process.h" -struct process proc_table[255]; +static struct process proc_table[PID_COUNT_MAX]; +static struct process *current_proc; pid_t newpid(void) { + int i; static pid_t last_pid = 0; - return ++last_pid; + + for (i = 0; i < PID_COUNT_MAX; i++, last_pid++) { + if (last_pid == PID_COUNT_MAX) { + last_pid = 0; + continue; + } + + if (!proc_table[last_pid].running) + break; + } + + if (i >= PID_COUNT_MAX) + return 0; + + return last_pid; } int fork(void) { - + int i, p; + pid_t child_pid = newpid(); + + if (child_pid == 0) + return -1; + + + for (i = 0; i < current_proc.pages; i++) { + p = page_new(); + + if (p == -1) { + + return -2; + } + + proc_table[child_pid].page[i] = p; + } } int exec(char *path, char *args) |