diff options
author | Nao Pross <naopross@thearcway.org> | 2017-08-25 10:26:21 +0200 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2017-08-25 10:26:21 +0200 |
commit | f209dc3a24987419c3f7ad9fbe3fe2b4dfb16427 (patch) | |
tree | b2a9a38bd081756c70917a64e1c830489939f4ca /sw | |
parent | new programmer interface for linux (diff) | |
download | z80uPC-f209dc3a24987419c3f7ad9fbe3fe2b4dfb16427.tar.gz z80uPC-f209dc3a24987419c3f7ad9fbe3fe2b4dfb16427.zip |
implements pio.h functions and makefile update to optimize size
- remove syscall.h, unused and not implemented
- bug fix for memcmp() in string.c
other changes are still partially unfinished and might not work
Diffstat (limited to '')
-rwxr-xr-x | sw/programmer/linux/src/z80prog | bin | 48160 -> 0 bytes | |||
-rw-r--r-- | sw/z80/kernel/drivers/pio.c | 29 | ||||
-rw-r--r-- | sw/z80/kernel/include/drivers/pio.h | 20 | ||||
-rw-r--r-- | sw/z80/kernel/include/memory.h | 3 | ||||
-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/memory.c | 9 | ||||
-rw-r--r-- | sw/z80/kernel/process.c | 22 | ||||
-rw-r--r-- | sw/z80/libc/string.c | 20 | ||||
-rw-r--r-- | sw/z80/makefile | 3 | ||||
-rw-r--r-- | sw/z80_test/crt0.s | 103 | ||||
-rw-r--r-- | sw/z80_test/makefile | 54 |
12 files changed, 238 insertions, 66 deletions
diff --git a/sw/programmer/linux/src/z80prog b/sw/programmer/linux/src/z80prog Binary files differdeleted file mode 100755 index 2f0d230..0000000 --- a/sw/programmer/linux/src/z80prog +++ /dev/null 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/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/memory.h b/sw/z80/kernel/include/memory.h index e4352b5..60fc98a 100644 --- a/sw/z80/kernel/include/memory.h +++ b/sw/z80/kernel/include/memory.h @@ -33,8 +33,7 @@ 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 }; 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/memory.c b/sw/z80/kernel/memory.c index f174906..ca9f447 100644 --- a/sw/z80/kernel/memory.c +++ b/sw/z80/kernel/memory.c @@ -7,7 +7,7 @@ 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 } } @@ -20,13 +20,12 @@ 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,9 +34,9 @@ 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; return 0; } diff --git a/sw/z80/kernel/process.c b/sw/z80/kernel/process.c index 49b86b8..b43fa11 100644 --- a/sw/z80/kernel/process.c +++ b/sw/z80/kernel/process.c @@ -1,16 +1,32 @@ #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 exec(char *path, char *args) diff --git a/sw/z80/libc/string.c b/sw/z80/libc/string.c index 9dd56cc..57b3a7f 100644 --- a/sw/z80/libc/string.c +++ b/sw/z80/libc/string.c @@ -1,11 +1,11 @@ #include "string.h" -void * memset(void *dest, const int8_t src, size_t n) { +void *memset(void *dest, const int8_t src, size_t n) { - void *dp = dest; + char *dp = (char *) dest; while (n--) - *dp++ = src; + *(dp++) = src; return dest; } @@ -22,16 +22,14 @@ void *memcpy(void *dest, void *src, size_t n) return dest; } -int8_t memcmp(const void *s1, const void *s2, size_t n) { - - uint8_t u1, u2; - - for ( ; n--; s1++, s2++) { +int8_t memcmp(void *s1, void *s2, size_t n) +{ + char *u1 = (char *) s1; + char *u2 = (char *) s2; - u1 = *s1; - u2 = *s2; + for ( ; n--; u1++, u2++) { - if (u1 != u2) + if (*u1 != *u2) return u1 - u2; } diff --git a/sw/z80/makefile b/sw/z80/makefile index 5047824..5ab7e93 100644 --- a/sw/z80/makefile +++ b/sw/z80/makefile @@ -20,6 +20,7 @@ CFLAGS := -mz80 \ -I kernel/include \ -I kernel/include/drivers \ -I libc/include \ + --opt-code-size \ -DDEBUG LDFLAGS := -mz80 --no-std-crt0 crt0.rel \ @@ -43,7 +44,7 @@ crt0.rel: crt0.s sdasz80 -o $< dirs: - mkdir -p build build/kernel build/libc + mkdir -p build build/kernel build/libc build/kernel/drivers dis: $(BINARY) @# z80dasm -a -l -g 0h $< -o build/$(OSNAME).s diff --git a/sw/z80_test/crt0.s b/sw/z80_test/crt0.s new file mode 100644 index 0000000..00c7da1 --- /dev/null +++ b/sw/z80_test/crt0.s @@ -0,0 +1,103 @@ +;-------------------------------------------------------------------------- +; crt0.s - Generic crt0.s for a Z80 +; +; Copyright (C) 2000, Michael Hope +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this library; see the file COPYING. If not, write to the +; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, +; MA 02110-1301, USA. +; +; As a special exception, if you link this library with other files, +; some of which are compiled with SDCC, to produce an executable, +; this library does not by itself cause the resulting executable to +; be covered by the GNU General Public License. This exception does +; not however invalidate any other reasons why the executable file +; might be covered by the GNU General Public License. +;-------------------------------------------------------------------------- + + .module crt0 + .globl _kmain + + .area _HEADER (ABS) + ;; Reset vector + .org 0 + jp init + + .org 0x08 + reti + .org 0x10 + reti + .org 0x18 + reti + .org 0x20 + reti + .org 0x28 + reti + .org 0x30 + reti + .org 0x38 + reti + + .org 0x100 +init: + ;; Set stack pointer directly above top of memory. + ld sp,#0xFFFF + + ;; Initialise global variables + call gsinit + call _kmain + jp _exit + + ;; Ordering of segments for the linker. + .area _HOME + .area _CODE + .area _INITIALIZER + .area _GSINIT + .area _GSFINAL + + .area _DATA + .area _INITIALIZED + .area _BSEG + .area _BSS + .area _HEAP + + .area _CODE + +__clock:: + ld a,#2 + rst 0x08 + ret + +_exit:: + ;; Exit - special code to the emulator + ld a,#0 + rst 0x08 +1$: + halt + jr 1$ + + .area _GSINIT +gsinit:: + ; ld bc, #l__INITIALIZER + ld a, b + or a, c + jr Z, gsinit_next + ; ld de, #s__INITIALIZED + ; ld hl, #s__INITIALIZER + ldir +gsinit_next: + + .area _GSFINAL + ret + diff --git a/sw/z80_test/makefile b/sw/z80_test/makefile new file mode 100644 index 0000000..c709d61 --- /dev/null +++ b/sw/z80_test/makefile @@ -0,0 +1,54 @@ +#### +# source code settings +# +OSNAME := helvetiOS_test + +CSOURCES := $(wildcard kernel/*.c) \ + $(wildcard kernel/drivers/*.c) \ + $(wildcard libc/*.c) + +OBJECTS := $(patsubst %.c,build/%.rel,$(CSOURCES)) +HEXFILE := build/$(OSNAME).hex +BINARY := build/$(OSNAME).bin + +### +# compiler settings + +CC := sdcc + +CFLAGS := -mz80 \ + -I kernel/include \ + -I kernel/include/drivers \ + -I libc/include \ + -DDEBUG + +LDFLAGS := -mz80 --no-std-crt0 crt0.rel \ + --std-c89 -pedantic \ + --code-loc 0x0800 --data-loc 0x8000 + +.PHONY: dirs dis clean +all: $(BINARY) + +# build binary +$(BINARY): $(OBJECTS) dirs + $(CC) $(LDFLAGS) $(OBJECTS) -o $(HEXFILE) + @# xxd -r -p $(HEXFILE) $(BINARY) + makebin -s 16384 $(HEXFILE) $(BINARY) + +$(OBJECTS): build/%.rel : %.c $(CSOURCES) dirs crt0.rel + @printf "\n" + $(CC) $(CFLAGS) -c $< -o $@ + +crt0.rel: crt0.s + sdasz80 -o $< + +dirs: + mkdir -p build build/kernel build/libc + +dis: $(BINARY) + @# z80dasm -a -l -g 0h $< -o build/$(OSNAME).s + dz80 -b -n $< + +clean: + - rm -rd build/* + - rm crt0.rel |