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

For how long it took see Actions tab
This commit is contained in:
Minecon724 2024-10-19 20:29:00 +02:00
parent d76cfe86a3
commit 7c03865b77
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
4 changed files with 48 additions and 32 deletions

View file

@ -0,0 +1,28 @@
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 artifacts
uses: https://github.com/actions/upload-artifact@v3
with:
path: build/criscv-*

View file

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

View file

@ -5,8 +5,13 @@
#include <stdint.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;
};

View file

@ -1,25 +1,14 @@
#include <stdint.h>
#include <stdio.h>
#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;