Skip to content

Commit

Permalink
z8: initial sketch of Z8 CPU enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
EtchedPixels committed Feb 12, 2024
1 parent c767056 commit 46ea723
Show file tree
Hide file tree
Showing 10 changed files with 1,079 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Kernel/cpu-z8/cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

#define uputp uputw /* Copy user pointer type */
#define ugetp ugetw /* between user and kernel */
#define uputi uputw /* Copy user int type */
#define ugeti ugetw /* between user and kernel */

typedef uint16_t irqflags_t;

/* Allow a minimum of 512 bytes gap between stack and top of allocations */
#define brk_limit() (udata.u_syscall_sp - 512)

typedef uint16_t size_t;
typedef int16_t ssize_t;
extern void *memcpy(void *dest, const void *src, size_t n);
extern char *strcpy(char *dest, const char *src);
extern char *strncpy(char *dest, const char *src, size_t n);
extern char *strchr(const char *s, int c);
extern void *memset(void *dest, int c, size_t n);

/* There is no compiler optimized inline memmove */
extern void *memmove(void *dest, const void *src, size_t n);

extern int16_t strlen(const char *p);

#define staticfast

/* User's structure for times() system call */
typedef unsigned long clock_t;

typedef union { /* this structure is endian dependent */
clock_t full; /* 32-bit count of ticks since boot */
struct {
uint16_t low; /* 16-bit count of ticks since boot */
uint16_t high;
} h;
} ticks_t;

#define used(x) x

#define cpu_to_le16(x) swab(x)
#define le16_to_cpu(x) swab(x)
#define cpu_to_le32(x) ((((uint32_t)cpu_to_le16((x) & 0xFFFF)) << 16) | \
(uint32_t)cpu_to_le16((x) >> 16))
#define le32_to_cpu(x) cpu_to_le32(x)

#define ntohs(x) (x)
#define ntohl(x) (x)

#define BIG_ENDIAN

#define __packed
#define barrier()
#define inline

#define __fastcall

extern void out(uint_fast8_t port, uint_fast8_t val);
extern uint_fast8_t in(uint_fast8_t port);
7 changes: 7 additions & 0 deletions Kernel/cpu-z8/image.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tools/visualize6800: tools/visualize6800.c

tools/pack85: tools/pack85.c

fuzix.bin: target $(OBJS) tools/pack85 tools/visualize6800
+$(MAKE) -C platform/platform-$(TARGET) image
tools/visualize6800 <fuzix.map
48 changes: 48 additions & 0 deletions Kernel/cpu-z8/kernel-z8.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
; Keep these in sync with struct u_data;;

#include "../build/kernel.def"

#define U_DATA__U_PTAB _udata+0 /* struct p_tab* */
#define U_DATA__U_PAGE _udata+2 /* uint16_t */
#define U_DATA__U_PAGE2 _udata+4 /* uint16_t */
#define U_DATA__U_INSYS _udata+6 /* bool */
#define U_DATA__U_CALLNO _udata+7 /* uint8_t */
#define U_DATA__U_SYSCALL_SP _udata+8 /* void * */
#define U_DATA__U_RETVAL _udata+10 /* int16_t */
#define U_DATA__U_ERROR _udata+12 /* int16_t */
#define U_DATA__U_SP _udata+14 /* void * */
#define U_DATA__U_ININTERRUPT _udata+16 /* bool */
#define U_DATA__U_CURSIG _udata+17 /* int8_t */
#define U_DATA__U_ARGN _udata+18 /* uint16_t */
#define U_DATA__U_ARGN1 _udata+20 /* uint16_t */
#define U_DATA__U_ARGN2 _udata+22 /* uint16_t */
#define U_DATA__U_ARGN3 _udata+24 /* uint16_t */
#define U_DATA__U_ISP _udata+26 /* void * initial stack pointer when _execing */
#define U_DATA__U_TOP _udata+28 /* uint16_t */
#define U_DATA__U_BREAK _udata+30 /* uint16_t */
#define U_DATA__U_CODEBASE _udata+32 /* uint16_t */
#define U_DATA__U_SIGVEC _udata+34 /* table of function pointers void * */
#define U_DATA__U_BASE _udata+98 /* uint8_t * */
#define U_DATA__U_COUNT _udata+100 /* uint16_t */
#define U_DATA__U_OFFSET _udata+102 /* uint32_t */

; Keep these in sync with struct p_tab;;
#define P_TAB__P_STATUS_OFFSET 0
#define P_TAB__P_FLAGS_OFFSET 1
#define P_TAB__P_TTY_OFFSET 2
#define P_TAB__P_PID_OFFSET 3
#define P_TAB__P_PAGE_OFFSET 15
#define P_TAB__P_PAGE2_OFFSET 17

#define P_RUNNING 1 /* value from include/kernel.h */
#define P_READY 2 /* value from include/kernel.h */

#define PFL_BATCH 4 /* value from include/kernel.h */

#define OS_BANK 0 /* value from include/kernel.h */

#define EAGAIN 11 /* value from include/kernel.h */

; Keep in sync with struct blkbuf
#define BUFSIZE 520

Loading

0 comments on commit 46ea723

Please sign in to comment.