aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--devkit/Makefile39
-rw-r--r--devkit/cacheracer.h73
-rw-r--r--devkit/cacheracer.x5
4 files changed, 120 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 7aef303..1fa83c8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
target
*~
+obj/
+bin/
+.cargo/
diff --git a/devkit/Makefile b/devkit/Makefile
new file mode 100644
index 0000000..3890bc0
--- /dev/null
+++ b/devkit/Makefile
@@ -0,0 +1,39 @@
+SOURCES = $(wildcard *.c)
+OBJECTS = $(patsubst %.c,obj/%.o,$(SOURCES))
+TARGETS = $(patsubst %.c,bin/%,$(SOURCES))
+
+CC = riscv64-unknown-elf-gcc
+
+COMMONFLAGS += -Wall
+# COMMONFLAGS += -Werror
+
+COMMONFLAGS += -O3
+
+COMMONFLAGS += -static
+# Use the 32-bit variant of RISC-V, with no floating-point support.
+COMMONFLAGS += -m32 -msoft-float -march=RV32I
+
+# Add debugging symbols
+COMMONFLAGS += -g3
+
+# Use C11.
+COMMONFLAGS += -std=c11
+
+# Link options: disable system libraries, and use the program
+# layout in test.x.
+LINKFLAGS = $(FLAGS) -nostartfiles -nodefaultlibs
+LINKFLAGS += -Wl,-T,cacheracer.x
+
+# Merge the common flags and the per-file FLAGS_xxx settings.
+FLAGS = $(COMMONFLAGS) $(FLAGS_$(basename $(notdir $@)))
+
+all: $(TARGETS)
+
+$(TARGETS): bin/%: obj/%.o
+ $(CC) $(LINKFLAGS) $< -o $@
+
+$(OBJECTS): obj/%.o: %.c
+ $(CC) $(FLAGS) -c $< -o $@
+
+clean:
+ rm -f obj/*.o bin/*
diff --git a/devkit/cacheracer.h b/devkit/cacheracer.h
new file mode 100644
index 0000000..5885395
--- /dev/null
+++ b/devkit/cacheracer.h
@@ -0,0 +1,73 @@
+#ifndef CACHERACER_H
+#define CACHERACER_H
+
+void __start(int core_id);
+
+/** Memory Layout
+ *
+ * Memory layout differs from CS 3410. Here, we have 64MB of memory,
+ * addressable in the range 0x00000000 to 0x04000000. Each player sees
+ * their half of memory as starting at 0x00000000. Player 2 is mapped
+ * in reverse, i.e. their 0x00000000 is Player 1's 0x03FFFFFC. Memory
+ * is byte-addressed.
+ *
+ * The linker script places code beginning at 0x400. Up to 0x00100000
+ * is read-only memory containing game data. Beginning at 0x00100000
+ * are the stacks, spaced 1 MB apart. Thus the layout is
+ *
+ * 0x00000000 - 0x00100000: Read-only memory
+ * 0x00100000 - 0x02000000: Your half of read-write memory
+ * TODO: are the below addresses correct?
+ * 0x02000000 - 0x03EFFFFC: Opponent's half of read-write memory
+ * 0x03EFFFFC - 0x04000000: Opponent's read-only memory
+ */
+
+#define PLAYER_RO_SEGMENT_SIZE 0x00100000
+#define PLAYER_STACK_SIZE 0x00100000
+
+#define HOME_START 0x00000000
+#define HOME_RW_START PLAYER_RO_SEGMENT_SIZE
+#define HOME_DATA_START (PLAYER_RO_SEGMENT_SIZE + 4 * PLAYER_STACK_SIZE)
+#define HOME_RW ((void *) HOME_RW_START)
+#define HOME_DATA ((void *) HOME_DATA_START)
+
+/** Definitions of global data */
+
+#define TAUNT_SIZE 228
+
+struct player_status {
+ signed char taunt[TAUNT_SIZE];
+};
+
+/** Pointers to global structures */
+
+#define HOME_STATUS ((struct player_status*) (HOME_RW_START - sizeof(struct player_status)))
+
+__attribute__ ((unused, noinline))
+static void prints(char *fmt) {
+ __asm__ __volatile__ (
+ "ADDI a1, %0, 0\n\t"
+ "ADDI a0, zero, 22\n\t"
+ "SCALL\n\t"
+ :
+ : "r" (fmt)
+ );
+}
+
+__attribute__ ((unused, noinline)) static void printi(int i) {
+ /* invoke system call number 22 */
+ __asm__ __volatile__ (
+ "ADDI a1, a0, 0\n\t"
+ "ADDI a0, zero, 23\n\t"
+ "SCALL\n\t"
+ );
+}
+
+__attribute__ ((unused, noinline)) static void sneak_attack() {
+ __asm__ __volatile__ (
+ "ADDI a0, zero, 24\n\t"
+ "SCALL"
+ );
+}
+
+#endif
diff --git a/devkit/cacheracer.x b/devkit/cacheracer.x
new file mode 100644
index 0000000..2928276
--- /dev/null
+++ b/devkit/cacheracer.x
@@ -0,0 +1,5 @@
+ENTRY(__start)
+SECTIONS
+{
+PROVIDE (__executable_start = 0x400); . = 0x400 + SIZEOF_HEADERS;
+}