summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2023-10-04 15:23:49 -0600
committerAlejandro Soto <alejandro@34project.org>2023-10-04 15:23:49 -0600
commit64dbe25a5023b87acaa648c7cfcb3f183032589a (patch)
tree16adff52540bae421b145903a8a657ed533fe384
parentf2b332fe0bf95beab5ef4ecbbdc506a1b7d0399c (diff)
Makefile: add rules for demo
-rw-r--r--Makefile26
-rw-r--r--demo/demo.h4
-rw-r--r--demo/main.c2
-rw-r--r--demo/start.S4
4 files changed, 29 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 61f0a0c..c1ff7a3 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,10 @@ COV_DIR := cov
RTL_DIR := rtl
TB_DIR := tb
SIM_DIR := sim
+DEMO_DIR := demo
TB_SIM_DIR := $(TB_DIR)/sim
SIM_OBJ_DIR := $(OBJ_DIR)/$(TOP)/sim
+DEMO_OBJ_DIR := $(OBJ_DIR)/$(TOP)/demo
VERILATOR ?= verilator
GENHTML ?= genhtml
CROSS_CC := $(CROSS_COMPILE)gcc
@@ -27,6 +29,8 @@ export CXXFLAGS LDFLAGS
X_MODE := $(if $(DISABLE_RAND),fast,unique)
+CC_CPU := -mcpu=arm810
+
VFLAGS ?= \
--x-assign $(X_MODE) --x-initial $(X_MODE) \
$(if $(DISABLE_THREADS),,--threads $(shell nproc)) \
@@ -62,6 +66,9 @@ sim/%: $(SIM_DIR)/sim.py $(TB_SIM_DIR)/%.py exe/$(TOP) $(SIM_OBJ_DIR)/%.bin
vmlaunch: $(SIM_DIR)/sim.py $(SIM_DIR)/gdbstub.py exe/$(TOP)
@$< $(SIM_DIR)/gdbstub.py $(OBJ_DIR)/$(TOP)/V$(TOP) build/u-boot.bin
+demo: $(SIM_DIR)/sim.py $(SIM_DIR)/gdbstub.py exe/$(TOP) $(DEMO_OBJ_DIR)/demo.bin
+ @$< $(SIM_DIR)/gdbstub.py $(OBJ_DIR)/$(TOP)/V$(TOP) $(DEMO_OBJ_DIR)/demo.bin
+
ifndef DISABLE_COV
$(COV_DIR): $(OBJ_DIR)/$(TOP)/cov.info
@rm -rf $@
@@ -75,15 +82,30 @@ $(OBJ_DIR)/$(TOP)/cov.info: $(patsubst %,$(SIM_OBJ_DIR)/%.cov,$(SIMS))
$(VERILATOR)_coverage -write-info $@ $(SIM_OBJ_DIR)/*.cov
endif
-$(SIM_OBJ_DIR)/%.bin: $(SIM_OBJ_DIR)/%
+%.bin: %
$(CROSS_OBJCOPY) -O binary --only-section=._img $< $@
$(SIM_OBJ_DIR)/%: $(SIM_OBJ_DIR)/%.o $(SIM_OBJ_DIR)/start.o
$(CROSS_CC) $(CROSS_LDFLAGS) -o $@ -g -T $(SIM_DIR)/link.ld -nostartfiles -nostdlib $^
+$(OBJ_DIR)/%.bin: $(SIM_OBJ_DIR)/%
+ $(CROSS_OBJCOPY) -O binary --only-section=._img $< $@
+
+$(DEMO_OBJ_DIR)/demo: $(DEMO_DIR)/link.ld $(patsubst $(DEMO_DIR)/%,$(DEMO_OBJ_DIR)/%.o,\
+ $(basename $(wildcard $(DEMO_DIR)/*.c) $(wildcard $(DEMO_DIR)/*.S)))
+ $(CROSS_CC) $(CROSS_LDFLAGS) -o $@ -g -nostartfiles -nostdlib -T $^
+
+$(DEMO_OBJ_DIR)/%.o: $(DEMO_DIR)/%.c $(wildcard $(DEMO_DIR)/*.h)
+ @mkdir -p $(DEMO_OBJ_DIR)
+ $(CROSS_CC) $(CROSS_CFLAGS) -o $@ -g -c $< $(CC_CPU)
+
+$(DEMO_OBJ_DIR)/%.o: $(DEMO_DIR)/%.S
+ @mkdir -p $(DEMO_OBJ_DIR)
+ $(CROSS_CC) $(CROSS_CFLAGS) -o $@ -g -c $<
+
$(SIM_OBJ_DIR)/%.o: $(TB_SIM_DIR)/%.c
@mkdir -p $(SIM_OBJ_DIR)
- $(CROSS_CC) $(CROSS_CFLAGS) -o $@ -g -c $< -mcpu=arm810
+ $(CROSS_CC) $(CROSS_CFLAGS) -o $@ -g -c $< $(CC_CPU)
$(SIM_OBJ_DIR)/%.o: $(TB_SIM_DIR)/%.S
@mkdir -p $(SIM_OBJ_DIR)
diff --git a/demo/demo.h b/demo/demo.h
index f01b36c..f98d599 100644
--- a/demo/demo.h
+++ b/demo/demo.h
@@ -13,10 +13,10 @@ struct cpu
unsigned num;
};
-/* R12 está reservado por la ABI
+/* Esto viola la ABI, pero no importa porque no dependemos de bibliotecas
* https://gcc.gnu.org/onlinedocs/gcc/Global-Register-Variables.html
*/
-register struct cpu *this_cpu asm("ip");
+register struct cpu *this_cpu asm("r9");
void spin_init(struct lock *lock);
void spin_lock(struct lock *lock, unsigned *irq_save);
diff --git a/demo/main.c b/demo/main.c
index 40e903c..988ef55 100644
--- a/demo/main.c
+++ b/demo/main.c
@@ -4,7 +4,7 @@ static struct cpu cpu0, cpu1, cpu2, cpu3;
struct cpu *__cpus[] = { &cpu0, &cpu1, &cpu2, &cpu3 };
-volatile static unsigned boot_done;
+static volatile unsigned boot_done;
static void cmd_run(char **tokens)
{
diff --git a/demo/start.S b/demo/start.S
index a0a9a4f..ecdeb3c 100644
--- a/demo/start.S
+++ b/demo/start.S
@@ -34,8 +34,8 @@ _start:
str r2, [r0]
ldr r2, =__cpus
lsl r3, r1, #2
- ldr ip, [r2, r3]
- str r1, [ip]
+ ldr r9, [r2, r3]
+ str r1, [r9]
ldr r2, =_stack_shift
lsl r1, r1, r2
ldr sp, =_stack_begin