diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..51e4df4 --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,32 @@ +on: [push] +jobs: + deploy: + runs-on: docker + container: debian:bookworm + steps: + - name: Prepare for installation + run: dpkg --add-architecture amd64 && apt update + - name: Install prerequisites + run: apt install -y git ca-certificates + - name: Install toolchain + run: apt install -y gcc gcc-x86-64-linux-gnu:arm64 make:arm64 + - name: Install program dependencies + run: apt install -y libelf-dev:arm64 libelf-dev:amd64 + + - name: Clone repository + run: git clone https://git.m724.eu/Minecon724/criscv.git . + - name: Package for x86_64 + run: CC=x86_64-linux-gnu-gcc PROGRAM_NAME=criscv-x86_64 make && rm -rf build/obj + - name: Package for aarch64 + run: CC=aarch64-linux-gnu-gcc PROGRAM_NAME=criscv-aarch64 make + + - name: No escape from unnecessary nodejs + run: apt install -y --no-install-recommends nodejs + - name: Upload x86_64 artifact + uses: https://github.com/actions/upload-artifact@v3 + with: + path: build/criscv-x86_64 + - name: Upload aarch64 artifact + uses: https://github.com/actions/upload-artifact@v3 + with: + path: build/criscv-aarch64 \ No newline at end of file diff --git a/Makefile b/Makefile index 8bebe20..542de1e 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,14 @@ # Compiler to use -CC := gcc +CC ?= gcc -# Compiler flags: -# -Wall: Enable all warnings -# -Wextra: Enable extra warnings -# -std=gnu23: Use GNU C23 standard -# -I include: Add 'include' directory to the include path -# -O3: Optimize code (level 3) -# -Wno-unused-variable: Disable warnings for unused variables -ifeq ($(DEBUG),1) - CFLAGS := -Wall -Wextra -std=gnu23 -I include -O0 -g -lelf -else - CFLAGS := -Wall -Wextra -std=gnu23 -I include -O3 -lelf -endif +CFLAGS = -Wall -Wextra -std=gnu17 -I include +LDFLAGS = -lelf # Directory for build outputs BUILD_DIR := build # Name of the output program -PROGRAM_NAME := criscv +PROGRAM_NAME ?= criscv # Find all .c files in the source directory SRCS := $(wildcard src/*.c) @@ -30,16 +20,20 @@ OBJS := $(patsubst src/%.c,$(BUILD_DIR)/obj/%.o,$(SRCS)) TARGET := $(BUILD_DIR)/$(PROGRAM_NAME) +# Default target: build the executable +all: CFLAGS += -O3 +all: $(TARGET) + +# Debug target +debug: CFLAGS += -O0 -g +debug: $(TARGET) # Declare 'all' and 'clean' as phony targets (not files) -.PHONY: all clean - -# Default target: build the executable -all: $(TARGET) +.PHONY: all debug clean # Rule to link object files into the final executable $(TARGET): $(OBJS) | $(BUILD_DIR) - $(CC) $(CFLAGS) $^ -o $@ + $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) du -b $(TARGET) # Size of the executable in bytes # Rule to compile source files into object files diff --git a/include/cpu.h b/include/cpu.h index d1b09e6..6f56735 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -5,8 +5,13 @@ #include struct CPU_s { + // [32] of 32bit (uint32_t) registers uint32_t registers[32]; + + // Points to the byte of current instruction. Also known as pc uint32_t programCounter; + + // The address space AddressSpace *addressSpace; }; diff --git a/src/cpu.c b/src/cpu.c index a6fb4e9..6903aeb 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -1,25 +1,14 @@ #include #include + #include "address_space.h" #include "instruction_executor.h" -struct CPU_s { - // [32] of 32bit (uint32_t) registers - uint32_t registers[32]; - - // Points to the byte of current instruction. Also known as pc - uint32_t programCounter; - - // The address space - AddressSpace *addressSpace; -} cpu_default = { +const CPU cpu_default = { .registers = {0}, .programCounter = 0 }; -typedef struct CPU_s CPU; - - CPU create_cpu(AddressSpace *addressSpace) { CPU cpu = cpu_default; cpu.addressSpace = addressSpace;