Add actions, support older gcc
All checks were successful
/ deploy (push) Successful in 1m21s

This commit is contained in:
Minecon724 2024-10-19 20:16:31 +02:00
parent d76cfe86a3
commit 51c5804ef6
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
4 changed files with 52 additions and 32 deletions

View file

@ -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

View file

@ -1,24 +1,14 @@
# Compiler to use # Compiler to use
CC := gcc CC ?= gcc
# Compiler flags: CFLAGS = -Wall -Wextra -std=gnu17 -I include
# -Wall: Enable all warnings LDFLAGS = -lelf
# -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
# Directory for build outputs # Directory for build outputs
BUILD_DIR := build BUILD_DIR := build
# Name of the output program # Name of the output program
PROGRAM_NAME := criscv PROGRAM_NAME ?= criscv
# Find all .c files in the source directory # Find all .c files in the source directory
SRCS := $(wildcard src/*.c) SRCS := $(wildcard src/*.c)
@ -30,16 +20,20 @@ OBJS := $(patsubst src/%.c,$(BUILD_DIR)/obj/%.o,$(SRCS))
TARGET := $(BUILD_DIR)/$(PROGRAM_NAME) 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) # Declare 'all' and 'clean' as phony targets (not files)
.PHONY: all clean .PHONY: all debug clean
# Default target: build the executable
all: $(TARGET)
# Rule to link object files into the final executable # Rule to link object files into the final executable
$(TARGET): $(OBJS) | $(BUILD_DIR) $(TARGET): $(OBJS) | $(BUILD_DIR)
$(CC) $(CFLAGS) $^ -o $@ $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
du -b $(TARGET) # Size of the executable in bytes du -b $(TARGET) # Size of the executable in bytes
# Rule to compile source files into object files # Rule to compile source files into object files

View file

@ -5,8 +5,13 @@
#include <stdint.h> #include <stdint.h>
struct CPU_s { struct CPU_s {
// [32] of 32bit (uint32_t) registers
uint32_t registers[32]; uint32_t registers[32];
// Points to the byte of current instruction. Also known as pc
uint32_t programCounter; uint32_t programCounter;
// The address space
AddressSpace *addressSpace; AddressSpace *addressSpace;
}; };

View file

@ -1,25 +1,14 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "address_space.h" #include "address_space.h"
#include "instruction_executor.h" #include "instruction_executor.h"
struct CPU_s { const CPU cpu_default = {
// [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 = {
.registers = {0}, .registers = {0},
.programCounter = 0 .programCounter = 0
}; };
typedef struct CPU_s CPU;
CPU create_cpu(AddressSpace *addressSpace) { CPU create_cpu(AddressSpace *addressSpace) {
CPU cpu = cpu_default; CPU cpu = cpu_default;
cpu.addressSpace = addressSpace; cpu.addressSpace = addressSpace;