summaryrefslogtreecommitdiffstats
path: root/sw/z80/kernel/include
diff options
context:
space:
mode:
Diffstat (limited to 'sw/z80/kernel/include')
-rw-r--r--sw/z80/kernel/include/boot.h35
-rw-r--r--sw/z80/kernel/include/devices.h2
-rw-r--r--sw/z80/kernel/include/errno.h35
-rw-r--r--sw/z80/kernel/include/fs/dev.h29
-rw-r--r--sw/z80/kernel/include/fs/dirent.h17
-rw-r--r--sw/z80/kernel/include/fs/fd.h102
-rw-r--r--sw/z80/kernel/include/fs/fdop.h140
-rw-r--r--sw/z80/kernel/include/fs/fs.h63
-rw-r--r--sw/z80/kernel/include/fs/iter.h17
-rw-r--r--sw/z80/kernel/include/fs/users.h21
-rw-r--r--sw/z80/kernel/include/memory.h50
-rw-r--r--sw/z80/kernel/include/pio.h35
-rw-r--r--sw/z80/kernel/include/process.h43
-rw-r--r--sw/z80/kernel/include/progman.h85
-rw-r--r--sw/z80/kernel/include/sio.h43
-rw-r--r--sw/z80/kernel/include/stat.h24
-rw-r--r--sw/z80/kernel/include/types.h61
-rw-r--r--sw/z80/kernel/include/usart.h149
18 files changed, 641 insertions, 310 deletions
diff --git a/sw/z80/kernel/include/boot.h b/sw/z80/kernel/include/boot.h
deleted file mode 100644
index 5310e45..0000000
--- a/sw/z80/kernel/include/boot.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#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/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/errno.h b/sw/z80/kernel/include/errno.h
new file mode 100644
index 0000000..7632269
--- /dev/null
+++ b/sw/z80/kernel/include/errno.h
@@ -0,0 +1,35 @@
+#ifndef ERRNO_H
+#define ERRNO_H
+
+extern int errno;
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* Input/output error */
+#define ENXIO 6 /* Device not configured */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file descriptor */
+#define ECHILD 10 /* No child processes */
+#define EDEADLK 11 /* Resource deadlock avoided */
+
+#define ENOMEM 12 /* Cannot allocate memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+
+#define ENOTBLK 15 /* Block device required */
+#define EBUSY 16 /* Device busy */
+#define EEXIST 17 /* File exists */
+
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* Operation not supported by device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* Too many open files in system */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+
+#endif
diff --git a/sw/z80/kernel/include/fs/dev.h b/sw/z80/kernel/include/fs/dev.h
new file mode 100644
index 0000000..8e550f3
--- /dev/null
+++ b/sw/z80/kernel/include/fs/dev.h
@@ -0,0 +1,29 @@
+#ifndef DEV_H
+#define DEV_H
+
+#include "types.h"
+
+#define FS_MOUNT_LIMIT 16
+
+struct fs_superblock
+{
+ uint8_t magic; // identifier
+
+ size_t blk_size; // size of a single block
+ size_t imap_size; // quantity of inodes
+ size_t dmap_size; // quantity of blocks
+};
+
+struct fs_dev
+{
+ uint enabled :1; // in use
+ uint port_no :3; // serial port number
+ uint :4;
+ inode_t inode; // dir mounted
+ struct fs_superblock superblock; // block informations
+};
+
+/* list of devices */
+extern struct fs_dev devices[FS_MOUNT_LIMIT];
+
+#endif
diff --git a/sw/z80/kernel/include/fs/dirent.h b/sw/z80/kernel/include/fs/dirent.h
new file mode 100644
index 0000000..2fd224a
--- /dev/null
+++ b/sw/z80/kernel/include/fs/dirent.h
@@ -0,0 +1,17 @@
+#ifndef __DIRENT_H__
+#define __DIRENT_H__
+
+#include "types.h"
+
+struct dirent
+{
+ ino_t inode; // inode referred
+ uint8_t name_size; // size of the name
+ char name[]; // name of the referred inode
+};
+
+/* if inode is FS_INO_NULL, then the dirent is a memory leak */
+/* Warning: dirent leaks are generated by rm or rmdir operations */
+/* Filesystem must be periodically checked and cleaned */
+
+#endif // __DIRENT_H__
diff --git a/sw/z80/kernel/include/fs/fd.h b/sw/z80/kernel/include/fs/fd.h
new file mode 100644
index 0000000..d2fea2a
--- /dev/null
+++ b/sw/z80/kernel/include/fs/fd.h
@@ -0,0 +1,102 @@
+#ifndef __FD_H__
+#define __FD_H__
+
+#include "types.h"
+
+#define FD_MAX 32
+
+#define OPEN_READ 0x1
+#define OPEN_WRITE 0x2
+#define OPEN_BIN 0x4
+#define OPEN_APPEND 0x8
+#define OPEN_ERASE 0x10
+#define OPEN_DIR 0x20
+#define OPEN_LINK 0x40
+
+#define LS_ALL 0x1
+
+/* declare dirent, not include */
+#ifndef __DIRENT_H__
+struct dirent;
+#endif
+
+/* set of operations callback for fd */
+struct fd_operations
+{
+ size_t (*readline)(inode_t, fsize_t, char *, char term);
+ size_t (*print)(inode_t, fsize_t, const char *);
+ size_t (*append)(inode_t, fsize_t*, const char *);
+
+ size_t (*read)(inode_t, fsize_t, void *, size_t);
+ size_t (*write)(inode_t, fsize_t, const void *, size_t);
+ size_t (*bin_append)(inode_t, fsize_t*, const void *, size_t);
+
+ size_t (*ls)(inode_t, struct dirent *, uint8_t);
+ size_t (*find)(inode_t, struct dirent *, const char *);
+ int8_t (*mkdir)(inode_t, const char *);
+ int8_t (*rmdir)(inode_t, const char *);
+ int8_t (*touch)(inode_t, const char *);
+ int8_t (*rm)(inode_t, const char *);
+ int8_t (*ln)(inode_t, const char *, const char *);
+
+ int8_t (*special)(inode_t, void *, size_t);
+};
+
+/* file descriptor */
+struct file_desc
+{
+ inode_t inode; // inode pointed
+ fsize_t seek; // virtual seek
+ devsize_t begin; // beginning of blocks
+ struct fd_operations opers; // bound operations
+};
+
+/* bitmap of used file descriptors */
+extern struct uint8_t fd_bmap[FD_TABLE_SIZE / 8];
+
+/* table of file descriptors */
+extern struct file_desc fd_table[FD_TABLE_SIZE];
+
+/* returns a free file descriptor */
+int8_t __fd_new();
+
+/* opens a file streaming of the cwd */
+int8_t __open_c_inode(uint8_t flags);
+
+/* opens a file streaming by a path */
+int8_t open(const char *path, uint8_t flags);
+
+/* list content of directory */
+size_t ls(int8_t fd, struct dirent *buf, uint8_t all);
+
+/* find name through the directory entries */
+size_t find(int8_t fd, struct dirent *buf, const char *name);
+
+/* creates a new directory inside fd with the specified name */
+int8_t mkdir(int8_t fd, const char *name);
+
+/* creates a new file inside fd with the specified name */
+int8_t touch(int8_t fd, const char *name);
+
+/* creates a new symlink inside fd with the specified name */
+int8_t ln(int8_t fd, const char *name);
+
+/* change virtual seek position of the fd */
+int8_t seek(int8_t fd, fsize_t pos);
+
+/* reads a string from the fd until the terminator is reached */
+size_t readline(int8_t fd, char *buf, char term);
+
+/* writes a string into the fd */
+int8_t print(int8_t fd, const char *str);
+
+/* reads n bytes from the fd */
+size_t read(int8_t fd, void *buf, size_t n);
+
+/* writes n bytes into the fd */
+int8_t write(int8_t fd, const void *buf, size_t n);
+
+/* frees fd space */
+void close(int8_t fd);
+
+#endif // __FD_H__
diff --git a/sw/z80/kernel/include/fs/fdop.h b/sw/z80/kernel/include/fs/fdop.h
new file mode 100644
index 0000000..d4b1b77
--- /dev/null
+++ b/sw/z80/kernel/include/fs/fdop.h
@@ -0,0 +1,140 @@
+#ifndef __FDOP_H__
+#define __FDOP_H__
+
+#include "types.h"
+
+#ifndef __DIRENT_H__
+struct dirent;
+#endif
+
+/* macro for direct binding */
+
+#define FD_BIND_AS_DIR(oper) { \
+ oper.ls = &as_ls; \
+ oper.find = &as_find; \
+ oper.mkdir = &as_mkdir; \
+ oper.rmdir = &as_rmdir; \
+ oper.touch = &as_touch; \
+ oper.rm = &as_rm; \
+ oper.ln = &as_ln; \
+ }
+
+#define FD_BIND_SS_DIR(oper) { \
+ oper.ls = &ss_ls; \
+ oper.find = &ss_find; \
+ oper.mkdir = &ss_mkdir; \
+ oper.rmdir = &ss_rmdir; \
+ oper.touch = &ss_touch; \
+ oper.rm = &ss_rm; \
+ oper.ln = &ss_ln; \
+ }
+
+#define FD_BIND_AS_FILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.readline = as_readline; \
+ if (flags & OPEN_APPEND) \
+ opers.append = as_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.print = as_print; \
+ }
+
+#define FD_BIND_SS_FILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.readline = ss_readline; \
+ if (flags & OPEN_APPEND) \
+ opers.append = ss_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.print = ss_print; \
+ }
+
+#define FD_BIND_AS_BINFILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.read = as_read; \
+ if (flags & OPEN_APPEND) \
+ opers.bin_append = as_bin_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.write = as_write; \
+ }
+
+#define FD_BIND_SS_BINFILE(opers, flags) { \
+ if (flags & OPEN_READ) \
+ opers.read = ss_read; \
+ if (flags & OPEN_APPEND) \
+ opers.bin_append = ss_bin_append; \
+ else if (flags & OPEN_WRITE) \
+ opers.write = ss_write; \
+ }
+
+/* Set of file descriptors operations */
+/* Determines if to use the serial interface or the address space */
+
+/* Address space section */
+
+/* File functions */
+
+size_t as_readline(inode_t inode, fsize_t seek, char *buf, char term);
+
+size_t as_print(inode_t inode, fsize_t seek, const char *str);
+
+size_t as_append(inode_t inode, fsize_t *seek_ptr, const char *str);
+
+
+size_t as_read(inode_t inode, fsize_t seek, void *buf, size_t n);
+
+size_t as_write(inode_t inode, fsize_t seek, const void *buf, size_t n);
+
+size_t as_bin_append(inode_t inode, fsize_t *seek_ptr, const void *buf, size_t
+n);
+
+/* Directory functions */
+
+size_t as_ls(inode_t inode, struct dirent *buf, uint8_t all);
+
+size_t as_find(inode_t inode, struct dirent *buf, const char *name);
+
+int8_t as_mkdir(inode_t inode, const char *name);
+
+int8_t as_rmdir(inode_t inode, const char *name);
+
+int8_t as_touch(inode_t inode, const char *name);
+
+int8_t as_rm(inode_t inode, const char *name);
+
+int8_t as_ln(inode_t inode, const char *path, const char *name);
+
+/* Serial Space section */
+/* Warning, it doesn't switch to the right driver */
+
+/* File functions */
+
+size_t ss_readline(inode_t inode, fsize_t seek, char *buf, char term);
+
+size_t ss_print(inode_t inode, fsize_t seek, const char *str);
+
+size_t ss_append(inode_t inode, fsize_t *seek_ptr, const char *str);
+
+
+size_t ss_read(inode_t inode, fsize_t seek, void *buf, size_t n);
+
+size_t ss_write(inode_t inode, fsize_t seek, const void *buf, size_t n);
+
+size_t ss_bin_append(inode_t inode, fsize_t *seek_ptr, const void *buf, size_t
+n);
+
+/* Directory functions */
+
+size_t ss_ls(inode_t inode, struct dirent *buf, uint8_t all);
+
+size_t ss_find(inode_t inode, struct dirent *buf, const char *name);
+
+int8_t ss_mkdir(inode_t inode, const char *name);
+
+int8_t ss_rmdir(inode_t inode, const char *name);
+
+int8_t ss_touch(inode_t inode, const char *name);
+
+int8_t ss_rm(inode_t inode, const char *name);
+
+int8_t ss_ln(inode_t, const char *path, const char *name);
+
+#endif // __FDOP_H__
diff --git a/sw/z80/kernel/include/fs/fs.h b/sw/z80/kernel/include/fs/fs.h
new file mode 100644
index 0000000..ad20adb
--- /dev/null
+++ b/sw/z80/kernel/include/fs/fs.h
@@ -0,0 +1,63 @@
+#ifndef __FS_H__
+#define __FS_H__
+
+#include "types.h"
+
+#define FS_OFFSET 0x1000
+
+#define FS_BLOCKS_SIZE 512
+#define FS_BLOCKS_N 8
+#define FS_BLOCKS_IND 6
+
+#define INODE_TYPE_FILE 0x0
+#define INODE_TYPE_DIR 0x1
+#define INODE_TYPE_SLINK 0x2
+#define INODE_TYPE_SPECIAL 0x3
+
+#define INODE_META_SIZE 8
+
+/* inode basic structure */
+struct fs_inode
+{
+ /* inode meta data */
+
+ uint mode :3; // chmod
+ uint uid :3; // chown
+ uint type :2; // file, dir, sym-link, special
+
+ time_t ctime; // creation time
+
+ uint24_t size; // inode size
+
+ /* data storage informations */
+ /* it doesn't allocate memory, virtual size FS_BLOCKS_N */
+ blk_t blocks[];
+};
+
+#define FS_DEV_ROM 0x7f /* 01111111 */
+#define FS_DEV_NULL 0x80 /* 10000000 */
+
+#define FS_ROM_SPACE 0x2000 // second rom
+
+#define FS_INO_ROOT 0x0 // first 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}
+
+/* get block seek in current device */
+devsize_t fs_block(blk_t block);
+
+/* get common inode seek in current device */
+/* c_inode must be set first */
+/* returns seek at the beginning of blocks field */
+devsize_t fs_inode(struct fs_inode *buf);
+
+/* common inode for syscalls */
+extern inode_t c_inode;
+
+/* parse a path, absolute or relative to c_inode */
+inode_t fs_parse_path(const char *path);
+
+#endif // __FS_H__
diff --git a/sw/z80/kernel/include/fs/iter.h b/sw/z80/kernel/include/fs/iter.h
new file mode 100644
index 0000000..41f011d
--- /dev/null
+++ b/sw/z80/kernel/include/fs/iter.h
@@ -0,0 +1,17 @@
+#ifndef __ITER_H__
+#define __ITER_H__
+
+struct inode_iter
+{
+ devsize_t dev_seek; /* seek position in the volume */
+ devsize_t blk_end; /* end of the block */
+
+ int16_t blk_index; /* index of the block */
+
+ int8_t blk_level; /* recursion level, indirect blocks */
+
+ fsize_t fseek; /* virtual seek in the file */
+ fsize_t size; /* file size */
+};
+
+#endif // __ITER_H__
diff --git a/sw/z80/kernel/include/fs/users.h b/sw/z80/kernel/include/fs/users.h
new file mode 100644
index 0000000..83980e5
--- /dev/null
+++ b/sw/z80/kernel/include/fs/users.h
@@ -0,0 +1,21 @@
+#ifndef USERS_H
+#define USERS_H
+
+#include "types.h"
+
+#define USERS_MAX 8
+#define USER_ROOT 0
+
+/* current user in use */
+extern struct fs_user c_user;
+
+struct fs_user
+{
+ char name[32];
+ ino_t home;
+ uint8_t perm; // TODO, permissions
+};
+
+/* all users are in rom device */
+
+#endif
diff --git a/sw/z80/kernel/include/memory.h b/sw/z80/kernel/include/memory.h
new file mode 100644
index 0000000..67c4b88
--- /dev/null
+++ b/sw/z80/kernel/include/memory.h
@@ -0,0 +1,50 @@
+#ifndef __MEMORY_H__
+#define __MEMORY_H__
+
+#include "types.h"
+#include "devices.h"
+
+/* 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
+ * 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
+
+#define ADDR_PAGE_FIRST ADDR_PAGE_8
+#define ADDR_PAGE_LAST ADDR_PAGE_15
+
+struct page
+{
+ pid_t pid; // process owner of the page (0 if free)
+ uint16_t addr; // physical address
+};
+
+int mmu_write_table(void);
+
+int page_new(void);
+int page_map(int page, int pid, uint16_t addr);
+int page_unmap(int page);
+
+#endif // __MEMORY_H__
diff --git a/sw/z80/kernel/include/pio.h b/sw/z80/kernel/include/pio.h
deleted file mode 100644
index 5d289ca..0000000
--- a/sw/z80/kernel/include/pio.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef __PIO_H__
-#define __PIO_H__
-
-#include "devices.h"
-#include "types.h"
-
-#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_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);
-
-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);
-
-// uint8_t pio_read_data(int port);
-
-inline int pio_read_pin(int port, uint8_t pin);
-inline void pio_write_pin(int port, uint8_t pin);
-
-// TODO: implement mode (in/out/both) and interrupt vector
-
-#endif // __PIO_H__
diff --git a/sw/z80/kernel/include/process.h b/sw/z80/kernel/include/process.h
new file mode 100644
index 0000000..3b0c843
--- /dev/null
+++ b/sw/z80/kernel/include/process.h
@@ -0,0 +1,43 @@
+#ifndef __PROCESS_H__
+#define __PROCESS_H__
+
+#include "types.h"
+#include "memory.h"
+
+ /* maximum number of processes (i.e. pages in ram)
+ * since each program can use only one page in ram
+ */
+#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;
+ 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; // number of pages used by the process
+ struct page page[4]; // pages used by the process
+};
+
+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 5d01f1c..0000000
--- a/sw/z80/kernel/include/progman.h
+++ /dev/null
@@ -1,85 +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 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
-};
-
-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/include/sio.h b/sw/z80/kernel/include/sio.h
new file mode 100644
index 0000000..276b99c
--- /dev/null
+++ b/sw/z80/kernel/include/sio.h
@@ -0,0 +1,43 @@
+#ifndef __SIO_H__
+#define __SIO_H__
+
+#include "types.h"
+
+#define SIO_PORT_0 0x0
+#define SIO_PORT_1 0x1
+#define SIO_PORT_2 0x2
+#define SIO_PORT_3 0x3
+#define SIO_PORT_4 0x4
+#define SIO_PORT_5 0x5
+#define SIO_PORT_6 0x6
+#define SIO_PORT_7 0x7
+
+/* current port in use */
+extern uint8_t sio_port;
+
+/* current seek in the device */
+extern devsize_t sio_seek;
+
+struct dev_buffer
+{
+ // TODO, bytes needed to the device buffer interface
+};
+
+/* points to the buffers mapped in the I/O space */
+/* to be defined precisely in assembly */
+extern volatile struct dev_buffer sio_buffers[8];
+
+/* initialize serial interface */
+void sio_init();
+
+/* syscall: read one byte from the current device */
+uint8_t sio_recv();
+/* syscall: write one byte into the current device */
+void sio_send(uint8_t value);
+
+/* read n bytes from the current port */
+size_t sio_read(void *buffer, size_t n);
+/* write n bytes into the current port */
+int8_t sio_write(const void *buffer, size_t n);
+
+#endif // __SIO_H__
diff --git a/sw/z80/kernel/include/stat.h b/sw/z80/kernel/include/stat.h
new file mode 100644
index 0000000..44c0f63
--- /dev/null
+++ b/sw/z80/kernel/include/stat.h
@@ -0,0 +1,24 @@
+#ifndef __STAT_H__
+#define __STAT_H__
+
+#include "types.h"
+
+struct stat
+{
+ inode_t inode; /* inode reference */
+
+ uint mode :3; /* mode */
+ uint uid :3; /* owner id */
+ uint type :2; /* file, dir or link */
+
+ devsize_t size; /* file size */
+
+ size_t blk_size; /* single block size */
+ size_t blk_used; /* blocks used by the file */
+
+ time_t ctime; /* creation time */
+}
+
+struct stat * stat(const char *path, struct stat *buffer);
+
+#endif // __STAT_H__
diff --git a/sw/z80/kernel/include/types.h b/sw/z80/kernel/include/types.h
index 552b7e9..c6e620b 100644
--- a/sw/z80/kernel/include/types.h
+++ b/sw/z80/kernel/include/types.h
@@ -1,13 +1,62 @@
#ifndef __TYPES_H__
#define __TYPES_H__
-#define register_t volatile unsigned char
+/* only types from primitive types are defined in this file */
-#define int8_t char
-#define uint8_t unsigned char
-#define int16_t int
-#define uint16_t unsigned int
+typedef volatile unsigned char register_t;
-#define size_t uint16_t
+typedef unsigned int uint;
+
+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;
+
+typedef uint16_t size_t;
+typedef int16_t ssize_t;
+
+typedef uint8_t pid_t;
+typedef uint16_t ino_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;
+
+typedef struct {
+ uint8_t member[3];
+
+} uint24_t;
+
+typedef uint32_t fsize_t;
+
+typedef struct
+{
+ dev_t dev; // device id, global in the fs
+ ino_t inode; // inode id relative to the volume
+
+} inode_t;
+
+typedef struct time_s
+{
+ struct
+ {
+ uint minutes :6;
+ uint hour :5;
+
+ } time;
+
+ struct
+ {
+ uint day :5;
+ uint month :4;
+ uint year :12;
+
+ } date;
+
+} time_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__