I'll get this out of the way first: I'm a lil bit of a newb here.
I've designed and built my own homebrew board and would like to (at some point) build my own target. I call it "CyBorg" (more info here: https://github.com/cyrusbuilt/CyBorg and the relevant firmware here: https://github.com/cyrusbuilt/CyBorg-Northbridge). The core of the system is nearly identical to the Z80-MBC2 (more info here: https://github.com/SuperFabius/Z80-MBC2 and here: https://hackaday.io/project/159973-z80- ... 0-computer). I didn't see a target for the Z80-MBC2, but if there is one, let know because I could just modify that to suit my needs.
But ultimately, I'm attempting to develop my own OS for it and I'm having trouble setting up my dev environment. I'm using VSCode and even though I've added z88dk to the include paths, intellisense isn't working and I'm getting weird compilation results. I'll just start with the relevant files.
First, my c_cpp_properties.json file:
Code: Select all
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${default}",
"${workspaceFolder}/**",
"~/z88dk/include/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/opt/homebrew/bin/sdcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-arm64"
}
],
"version": 4
}
Makefile
Code: Select all
CC=zcc
AS=zcc
TARGET=+embedded
VERBOSITY=-vn
CRT=1
PRAGMA_FILE=zpragma.inc
C_OPT_FLAGS=-clib=new
CFLAGS=$(TARGET) $(VERBOSITY) $(C_OPT_FLAGS) -pragma-include:$(PRAGMA_FILE)
LDFLAGS=$(CFLAGS)
ASFLAGS=$(TARGET) $(VERBOSITY) -c
EXEC=kernel.bin
EXEC_OUTPUT=cyos
OBJECTS=Common/io.o Kernel/kernel.o
%.o: %.c $(PRAGMA_FILE)
$(CC) $(CFLAGS) -o build/$@ $<
%.o: %.asm
$(AS) $(ASFLAGS) -o build/$@ $<
all : $(EXEC)
$(EXEC) : $(OBJECTS)
$(CC) $(LDFLAGS) -startup=$(CRT) $(OBJECTS) -o build/$(EXEC_OUTPUT) -create-app
.PHONY: clean
clean:
rm -rf build
And now for the relevant sources:
Common/io.h
Code: Select all
#ifndef _IO_H
#define _IO_H
#include <sys/compiler.h>
void k_outp(unsigned int port, unsigned int val);
unsigned int k_inp(unsigned int port);
__sfr __at 0x00 EXEC_PORT;
__sfr __at 0x01 STORE_OPC_PORT;
__sfr __at 0x01 SER_RX_PORT;
#endif
Common/io.c
Code: Select all
#include "io.h"
void k_outp(unsigned int port, unsigned int val) {
STORE_OPC_PORT = port;
EXEC_PORT = (char)(val);
}
unsigned int k_inp(unsigned int port) {
return SER_RX_PORT;
}
Code: Select all
Kernel/kernel.h
#ifndef _KERNEL_H
#define _KERNEL_H
#include <stdlib.h>
#include <z80.h>
#define VERSION "0.1"
#define PANIC(fmt, ...) \
do { \
printf("PANIC: %s:%d: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
while (1) {} \
} while (0)
#endif
Kernel/kernel.c
Code: Select all
#include "kernel.h"
#include "opcodes.h"
#include "Common/io.h"
#define LF 0x0a
#define CR 0x0d
#define SER_BUF_EMPTY_BIT 0x04
int putchar(int c) {
if (c == LF) {
k_outp(OP_IO_WR_SER_TX, CR);
}
k_outp(OP_IO_WR_SER_TX, c);
return c;
}
int getchar(void) {
static char sysFlags;
do {
STORE_OPC_PORT = OP_IO_RD_SYSFLG;
sysFlags = EXEC_PORT;
} while (!(sysFlags & SER_BUF_EMPTY_BIT));
return SER_RX_PORT;
}
/**
* Kernel bootstrap routine.
*/
void kernel_main(void) {
printf("\n\n");
// Just something to verify we can boot and run.
PANIC("%s: hello world!", VERSION);
}
/**
* Kernel entry point.
*/
int main() {
// TODO initialize subsystems
// Should never return.
kernel_main();
return 0;
}
So with everything above (beyond the intellisense issues), it fails to compile with the following error:
Code: Select all
zcc +embedded -vn -clib=new -pragma-include:zpragma.inc -o build/Kernel/kernel.o Kernel/kernel.c
Kernel/kernel.c:38: warning: operator '##' produced the invalid token ',VERSION'
Kernel/kernel.c:32:11: warning: Implicit definition of function 'printf' it will return an int. Prototype it explicitly if this is not what you want. [-Wimplicit-function-definition]
Kernel/kernel.c::putchar::0::0:11: error: undefined symbol: _k_outp
^---- _k_outp
Kernel/kernel.c::putchar::0::0:11: error: undefined symbol: _k_outp
^---- _k_outp
Kernel/kernel.c::kernel_main::0::4:31: error: undefined symbol: _printf
^---- _printf
Kernel/kernel.c::kernel_main::0::4:31: error: undefined symbol: _printf
^---- _printf
make: *** [Kernel/kernel.o] Error 1
Code: Select all
zcc +embedded -vn -clib=new -pragma-include:zpragma.inc -o build/Common/io.o Common/io.c
/Users/cyrus/z88dk/lib/config/../..//libsrc/_DEVELOPMENT/target/z80/z80_crt.asm.m4:1237: error: undefined symbol: _main
^---- _main
make: *** [Common/io.o] Error 1
zpragma.inc
Code: Select all
#pragma output CRT_MODEL = 1 // ROM model
#pragma output CRT_ORG_CODE = 0x0000 // move code origin
#pragma output CRT_ORG_DATA = 0x8000 // DATA appends to CODE
#pragma output CRT_ORG_BSS = 0 // BSS appends to DATA