diff --git a/.gitignore b/.gitignore index cd531cf..d477e49 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,8 @@ Module.symvers Mkfile.old dkms.conf +# Eclipse artefacts +.cproject +.project +.settings/ +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..688b419 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + +OBJS = grendel.o + +ifeq ($(BUILD_MODE),debug) + CFLAGS += -g -O0 +else ifeq ($(BUILD_MODE),run) + CFLAGS += -O2 +else ifeq ($(BUILD_MODE),profile) + CFLAGS += -g -pg -fprofile-arcs -ftest-coverage + LDFLAGS += -pg -fprofile-arcs -ftest-coverage + EXTRA_CLEAN += grendel.gcda grendel.gcno $(PROJECT_ROOT)gmon.out + EXTRA_CMDS = rm -rf grendel.gcda +else + $(error Build mode $(BUILD_MODE) not supported by this Makefile) +endif + +SRC_DIR=$(PROJECT_ROOT)/src + +all: grendel + +grendel: $(OBJS) + $(CXX) $(LDFLAGS) -o $@ $^ + $(EXTRA_CMDS) + +# %.o: $(SRC_DIR)/%.cpp +# $(CXX) -c $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -o $@ $< + +%.o: $(SRC_DIR)/%.c + $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< + +clean: + rm -fr grendel $(OBJS) $(EXTRA_CLEAN) diff --git a/src/grendel.c b/src/grendel.c new file mode 100644 index 0000000..bc36820 --- /dev/null +++ b/src/grendel.c @@ -0,0 +1,23 @@ +/** + * + * grendel.c + * + * Grendel: a compiling Beowulf reimplementation. + * + * The memory management subsystem. + * + * (c) 2026 Simon Brooke + * Licensed under GPL version 2.0, or, at your option, any later version. + */ + +#include +#include +#include + +#include "memory.h" + +int main(int argc, char **argv) { + + printf( "Grendel: size of pointer: %d, size of cell %d\n", sizeof( struct pointer), sizeof( struct cell)); + return 0; +} diff --git a/src/memory.h b/src/memory.h new file mode 100644 index 0000000..5303f8e --- /dev/null +++ b/src/memory.h @@ -0,0 +1,94 @@ +/** + * memory.h + * + * Grendel: a compiling Beowulf reimplementation. + * + * The memory management subsystem. + * + * (c) 2026 Simon Brooke + * Licensed under GPL version 2.0, or, at your option, any later version. + */ + +#ifndef __grendel_memory_h +#define __grendel_memory_h + +#include + +/* Tags for 32 bit objects, with 3 bits of tag an one mark bit */ + +/** + * This pointer object is an actual pointer -- an offset into consspace. + */ +#define OFFSETTV 0 +/** + * This pointer object is actually a 28 bit integer value. + */ +#define INTEGERTV 1 +/* + * Values 2..6 inclusive reserved further data types, including maybe + * implementing reals later. + */ + +/** + * This is not actually a pointer at all but the first word of a cell. + */ +#define CELLTV 7 + +/** + * Half of a cons cell. The mark bit is first, so that the ptag can be + * considered as part of the CTAG. + */ +struct pointer { + /* mark bit for mark and sweep garbage collector. Yes, this is normally + * thought of as part of the cell, but bear with me. */ + unsigned int mark : 1; + /* pointer tag, interpretations as above */ + unsigned int ptag : 3; + /* the actual payload of the pointer object */ + union { + unsigned int offset : 28; + int value : 28; + } payload; +}; + +struct cons_payload { + struct pointer pointers[2]; +}; + +struct symbol_payload { + /* this is the same mark bit as the one in the `address` pointer of the + * cons_payload. */ + unsigned int mark : 1; + unsigned int tag : 7; + char symbol[7]; +}; + +/* Tags for 64 bit objects. Note that, as the 64 bit object may be made up + * of two 32 bit objects (pointers*, the 64 bit tag is stored in bits 4..7 + * inclusive. The first three bits are the first three bits of a 32 bit object, + * and thus for 64bit objects will always b 111.*/ + +/* this 64 bit object is a cons cell */ +#define CONSTV 7 + +/* this 64 bit object is a seven character atom */ +#define ATOMTV 8 + +/* There are potentially another 119 types of object we could store in a 64 + * bit object, but I can't think of any we need just now. */ + +struct cell { + union { + struct cons_payload cons; + struct symbol_payload symbol; + } payload; +}; + +#define CONSSPACESIZE 65536 + +/** + * The entire array of cells available to the system. + */ +struct cell consspace[CONSSPACESIZE]; + +#endif