Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
598 commits
Select commit Hold shift + click to select a range
b02df58
> run NEMU
Jun 20, 2025
22e3271
> run NEMU
Jun 20, 2025
85566eb
> run NEMU
Jun 20, 2025
c38b6ce
> run NEMU
Jun 20, 2025
52d82fd
> run NEMU
Jun 20, 2025
2a1c604
> run NEMU
Jun 20, 2025
f10ade9
> run NEMU
Jun 20, 2025
2d69d0c
> run NEMU
Jun 20, 2025
b6ff0a0
> run NEMU
Jun 20, 2025
1b80c99
> run NEMU
Jun 20, 2025
8ae0e6b
> run NEMU
Jun 20, 2025
c82d2f1
> run NEMU
Jun 20, 2025
f1162f4
> run NEMU
Jun 20, 2025
c4aba02
> run NEMU
Jun 20, 2025
576b7e1
> run NEMU
Jun 20, 2025
106ee87
> run NEMU
Jun 20, 2025
c4b7a12
> run NEMU
Jun 20, 2025
e244474
> run NEMU
Jun 20, 2025
621a8bc
> run NEMU
Jun 20, 2025
49d011f
> run NEMU
Jun 20, 2025
b40d6cf
> run NEMU
Jun 20, 2025
7dc7cdc
> run NEMU
Jun 20, 2025
1934639
> run NEMU
Jun 20, 2025
56da37e
> run NEMU
Jun 20, 2025
f018499
> run NEMU
Jun 20, 2025
cf188fb
> run NEMU
Jun 20, 2025
8b2f01e
> run NEMU
Jun 20, 2025
51ecd47
> run NEMU
Jun 20, 2025
a766c41
> gdb NEMU
Jun 20, 2025
991dd3c
> run NEMU
Jun 20, 2025
7864293
> run NEMU
Jun 20, 2025
ea06061
> run NEMU
Jun 20, 2025
db93503
> run NEMU
Jun 20, 2025
1308802
> run NEMU
Jun 20, 2025
0d1fff7
> run NEMU
Jun 20, 2025
f8d0f7d
> run NEMU
Jun 20, 2025
c8d13e8
> run NEMU
Jun 20, 2025
f19d3c9
> run NEMU
Jun 20, 2025
01da602
> run NEMU
Jun 20, 2025
78c45e2
> run NEMU
Jun 20, 2025
023a474
> run NEMU
Jun 20, 2025
f28fd7c
> run NEMU
Jun 20, 2025
3c95240
> run NEMU
Jun 20, 2025
8e91bdc
> run NEMU
Jun 20, 2025
b282f5c
> run NEMU
Jun 20, 2025
73f475d
> run NEMU
Jun 20, 2025
a8cd06f
> run NEMU
Jun 20, 2025
098a80e
> run NEMU
Jun 20, 2025
5867d24
> run NEMU
Jun 20, 2025
c9486c6
> run NEMU
Jun 20, 2025
36fe9d1
> run NEMU
Jun 20, 2025
9dbb0b3
> run NEMU
Jun 20, 2025
51a58c6
> run NEMU
Jun 22, 2025
f324577
> run NEMU
Jun 22, 2025
cc7160b
> run NEMU
Jun 22, 2025
b08ad23
> run NEMU
Jun 22, 2025
9dcbb63
> run NEMU
Aug 3, 2025
bf0401a
> run NEMU
Aug 3, 2025
51eec0f
> run NEMU
Aug 3, 2025
ba23fd0
> run NEMU
Aug 3, 2025
1ac1417
> run NEMU
Aug 3, 2025
27c2142
> run NEMU
Aug 3, 2025
505eedb
> run NEMU
Aug 3, 2025
15ac832
> run NEMU
Aug 3, 2025
2a30e7b
> run NEMU
Aug 3, 2025
3e5ebdc
> run NEMU
Aug 3, 2025
301901a
> run NEMU
Aug 3, 2025
fa56aba
> run NEMU
Aug 3, 2025
e44fc58
> run NEMU
Aug 3, 2025
440af87
> run NEMU
Aug 3, 2025
830f2e2
> run NEMU
Aug 3, 2025
00c5543
> run NEMU
Aug 3, 2025
1005c76
> run NEMU
Aug 3, 2025
ac7801f
> run NEMU
Aug 3, 2025
a695735
> run NEMU
Aug 3, 2025
dbda9f1
> run NEMU
Aug 3, 2025
63b90a0
> run NEMU
Aug 3, 2025
6139bf4
> run NEMU
Aug 3, 2025
30a0b75
> run NEMU
Aug 3, 2025
83d87ea
> run NEMU
Aug 3, 2025
b9b5dc2
> run NEMU
Aug 3, 2025
90458b9
> run NEMU
Aug 3, 2025
7684672
> run NEMU
Aug 3, 2025
ea5def6
> run NEMU
Aug 3, 2025
fcf3a7a
> run NEMU
Aug 3, 2025
f8fb5df
> run NEMU
Aug 3, 2025
a8c9f33
> run NEMU
Aug 3, 2025
82d9959
> run NEMU
Aug 3, 2025
0853a12
> run NEMU
Aug 3, 2025
8ac8021
> run NEMU
Aug 3, 2025
0a88374
> run NEMU
Aug 3, 2025
16f0b9d
> run NEMU
Aug 3, 2025
a02e2dd
> run NEMU
Aug 3, 2025
e4993ef
> run NEMU
Aug 3, 2025
16abef7
> run NEMU
Aug 3, 2025
3f82af2
> run NEMU
Aug 3, 2025
80b9259
> run NEMU
Aug 3, 2025
9ee9ed9
> run NEMU
Aug 3, 2025
b8dc54b
> run NEMU
Aug 3, 2025
d330781
> run NEMU
Aug 3, 2025
f6e2649
> run NEMU
Aug 3, 2025
f02f8ff
> run NEMU
Aug 3, 2025
1942325
> run NEMU
Aug 3, 2025
3a1a87a
> run NEMU
Aug 3, 2025
63f2bd0
> run NEMU
Aug 3, 2025
5ad529b
> run NEMU
Aug 3, 2025
868c96a
> run NEMU
Aug 3, 2025
533cee9
> run NEMU
Aug 3, 2025
bc7ac3e
> run NEMU
Aug 3, 2025
c889a97
> run NEMU
Aug 3, 2025
ae618e6
> run NEMU
Aug 3, 2025
837300a
> run NEMU
Aug 3, 2025
e5f94fb
> run NEMU
Aug 3, 2025
702ceac
> run NEMU
Aug 3, 2025
7b35b62
> run NEMU
Aug 3, 2025
09e3238
> run NEMU
Aug 3, 2025
602acbc
> run NEMU
Aug 3, 2025
25447ef
> run NEMU
Aug 3, 2025
4cec213
> run NEMU
Aug 3, 2025
41e8e9c
> run NEMU
Aug 3, 2025
ffe458a
> run NEMU
Aug 3, 2025
4b2d5e5
> run NEMU
Aug 3, 2025
3b3bf26
> run NEMU
Aug 3, 2025
4725c53
> run NEMU
Aug 3, 2025
fb1ab93
> run NEMU
Aug 3, 2025
1d55752
> run NEMU
Aug 3, 2025
7fb434b
> run NEMU
Aug 3, 2025
444470b
> run NEMU
Aug 3, 2025
e6bd086
> run NEMU
Aug 23, 2025
aea5560
> run NEMU
Aug 23, 2025
e992a4a
> run NEMU
Aug 23, 2025
780bfdf
> run NEMU
Aug 23, 2025
ecdc7d9
> run NEMU
Aug 23, 2025
0d00cc5
> run NEMU
Aug 23, 2025
e6a10c7
> run NEMU
Aug 23, 2025
b46dadf
> run NEMU
Aug 23, 2025
e3a9d64
> run NEMU
Aug 23, 2025
2890563
> run NEMU
Aug 23, 2025
7adf932
> run NEMU
Aug 23, 2025
f65d3d4
> run NEMU
Aug 23, 2025
d7b8f56
> run NEMU
Aug 23, 2025
a56a5b7
> run NEMU
Aug 23, 2025
f20628c
> run NEMU
Aug 23, 2025
9a1bce4
> run NEMU
Aug 23, 2025
166b603
> run NEMU
Aug 23, 2025
318517d
> run NEMU
Aug 23, 2025
1601680
> run NEMU
Aug 23, 2025
e6dfa0a
> run NEMU
Aug 23, 2025
18236be
> run NEMU
Aug 23, 2025
8d30d82
> run NEMU
Aug 23, 2025
bf17a2a
> run NEMU
Aug 23, 2025
11a3885
> run NEMU
Aug 23, 2025
c5c545c
> run NEMU
Aug 23, 2025
2d1447b
> run NEMU
Aug 23, 2025
82e5505
> run NEMU
Aug 23, 2025
7e40576
> run NEMU
Aug 23, 2025
60d29a1
> run NEMU
Aug 23, 2025
1b953b8
> run NEMU
Aug 23, 2025
e702566
> run NEMU
Aug 23, 2025
0b096d7
> run NEMU
Aug 23, 2025
ff256cb
> run NEMU
Aug 23, 2025
fa20e38
> run NEMU
Aug 23, 2025
59dc740
> run NEMU
Aug 26, 2025
541697a
> run NEMU
Aug 26, 2025
902b536
> run NEMU
Aug 26, 2025
2611fe9
> run NEMU
Aug 26, 2025
752819c
> run NEMU
Aug 26, 2025
53d77fd
> run NEMU
Aug 26, 2025
58db809
> run NEMU
Aug 26, 2025
26f6f64
> run NEMU
Aug 26, 2025
c21b593
> run NEMU
Aug 30, 2025
4abc553
> run NEMU
Aug 30, 2025
f06b85c
> run NEMU
Aug 30, 2025
635685d
> run NEMU
Aug 30, 2025
9d182ab
> run NEMU
Aug 30, 2025
c355c00
> run NEMU
Aug 30, 2025
16562da
> run NEMU
Aug 30, 2025
17520f9
> run NEMU
Aug 30, 2025
4fa5fdc
> run NEMU
Aug 30, 2025
535a3d3
> run NEMU
Aug 30, 2025
a92068a
> run NEMU
Aug 30, 2025
917fb45
> run NEMU
Aug 30, 2025
d68339c
> run NEMU
Aug 30, 2025
bfda4c0
> run NEMU
Aug 30, 2025
09f34ba
> run NEMU
Aug 30, 2025
17c4c23
> run NEMU
Aug 30, 2025
07f26fa
> run NEMU
Aug 30, 2025
2e3dd3e
> run NEMU
Aug 30, 2025
e2ea5c5
> run NEMU
Aug 30, 2025
b0592f3
> run NEMU
Aug 30, 2025
48aec75
> run NEMU
Aug 30, 2025
1c57111
> run NEMU
Aug 30, 2025
cf519eb
> run NEMU
Aug 30, 2025
2144a3e
> run NEMU
Aug 30, 2025
430aa55
> run NEMU
Aug 30, 2025
a05036a
> run NEMU
Aug 30, 2025
dfa9f53
> run NEMU
Aug 30, 2025
f6cb438
> run NEMU
Aug 30, 2025
950baf0
> run NEMU
Aug 30, 2025
58a10ad
> run NEMU
Aug 30, 2025
9379bbc
> run NEMU
Aug 30, 2025
5e1c46d
> run NEMU
Aug 30, 2025
f61d443
> run NEMU
Aug 30, 2025
572599f
> run NEMU
Aug 30, 2025
41fedf7
> run NEMU
Aug 30, 2025
2ab96e0
> run NEMU
Aug 30, 2025
9bddd4a
> run NEMU
Aug 30, 2025
4db0d7e
> run NEMU
Aug 30, 2025
08f2e02
> run NEMU
Aug 30, 2025
8f19a14
> run NEMU
Aug 30, 2025
3baf455
> run NEMU
Aug 30, 2025
f294a44
> run NEMU
Aug 30, 2025
e80845c
> run NEMU
Aug 30, 2025
64fbf05
> run NEMU
Aug 30, 2025
7d4038f
> run NEMU
Aug 30, 2025
3a4c112
> run NEMU
Aug 30, 2025
8a1d5bc
> run NEMU
Aug 30, 2025
e16a52e
> run NEMU
Aug 30, 2025
f0ae468
> run NEMU
Aug 30, 2025
335507f
> run NEMU
Aug 30, 2025
64230ce
> run NEMU
Aug 30, 2025
90e0d93
> run NEMU
Aug 30, 2025
983b1b9
> run NEMU
Aug 30, 2025
ab87b10
> run NEMU
Aug 30, 2025
c7e945d
> run NEMU
Aug 30, 2025
9696fc8
> run NEMU
Aug 30, 2025
25a1dc0
> run NEMU
Aug 30, 2025
180bf6a
> run NEMU
Aug 30, 2025
89f597e
> run NEMU
Aug 30, 2025
0b81e18
> run NEMU
Aug 30, 2025
d0d9487
> run NEMU
Aug 30, 2025
880e085
> run NEMU
Aug 30, 2025
9132024
> run NEMU
Aug 30, 2025
49e7fe2
> run NEMU
Aug 30, 2025
1c277ce
> run NEMU
Aug 30, 2025
00c23af
> run NEMU
Aug 30, 2025
db72969
> run NEMU
Aug 30, 2025
e8ffc23
> run NEMU
Aug 30, 2025
869ed61
> run NEMU
Aug 30, 2025
3b97437
> run NEMU
Aug 30, 2025
fc94d91
> run NEMU
Aug 30, 2025
eb12231
> run NEMU
Aug 30, 2025
c8d126c
> run NEMU
Aug 30, 2025
37681de
> run NEMU
Aug 30, 2025
8ae5f3c
> run NEMU
Sep 7, 2025
fdc14d3
ysyx
Meowth666 Sep 14, 2025
db6af3d
ysyx
Meowth666 Sep 25, 2025
313a3aa
ysyx
Meowth666 Sep 25, 2025
385059c
> run NEMU
Sep 28, 2025
8d06cdd
ysyx
Meowth666 Oct 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions abstract-machine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*
!*/
!*.h
!*.c
!*.cc
!*.S
!*.ld
!*.sh
!*.py
!*.mk
!Makefile
!README
!LICENSE
.*
_*
*~
build/
!.gitignore
.vscode
22 changes: 22 additions & 0 deletions abstract-machine/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The AbstractMachine software is:

Copyright (c) 2018-2021 Yanyan Jiang and Zihao Yu

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
170 changes: 170 additions & 0 deletions abstract-machine/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Makefile for AbstractMachine Kernels and Libraries

### *Get a more readable version of this Makefile* by `make html` (requires python-markdown)
html:
cat Makefile | sed 's/^\([^#]\)/ \1/g' | markdown_py > Makefile.html
.PHONY: html

## 1. Basic Setup and Checks

### Default to create a bare-metal kernel image
ifeq ($(MAKECMDGOALS),)
MAKECMDGOALS = image
.DEFAULT_GOAL = image
endif

### Override checks when `make clean/clean-all/html`
ifeq ($(findstring $(MAKECMDGOALS),clean|clean-all|html),)

### Print build info message
$(info # Building $(NAME)-$(MAKECMDGOALS) [$(ARCH)])

### Check: environment variable `$AM_HOME` looks sane
ifeq ($(wildcard $(AM_HOME)/am/include/am.h),)
$(error $$AM_HOME must be an AbstractMachine repo)
endif

### Check: environment variable `$ARCH` must be in the supported list
ARCHS = $(basename $(notdir $(shell ls $(AM_HOME)/scripts/*.mk)))
ifeq ($(filter $(ARCHS), $(ARCH)), )
$(error Expected $$ARCH in {$(ARCHS)}, Got "$(ARCH)")
endif

### Extract instruction set architecture (`ISA`) and platform from `$ARCH`. Example: `ARCH=x86_64-qemu -> ISA=x86_64; PLATFORM=qemu`
ARCH_SPLIT = $(subst -, ,$(ARCH))
ISA = $(word 1,$(ARCH_SPLIT))
PLATFORM = $(word 2,$(ARCH_SPLIT))

### Check if there is something to build
ifeq ($(flavor SRCS), undefined)
$(error Nothing to build)
endif

### Checks end here
endif

## 2. General Compilation Targets

### Create the destination directory (`build/$ARCH`)
WORK_DIR = $(shell pwd)
DST_DIR = $(WORK_DIR)/build/$(ARCH)
$(shell mkdir -p $(DST_DIR))

### Compilation targets (a binary image or archive)
IMAGE_REL = build/$(NAME)-$(ARCH)
IMAGE = $(abspath $(IMAGE_REL))
ARCHIVE = $(WORK_DIR)/build/$(NAME)-$(ARCH).a

### Collect the files to be linked: object files (`.o`) and libraries (`.a`)
OBJS = $(addprefix $(DST_DIR)/, $(addsuffix .o, $(basename $(SRCS))))
LIBS := $(sort $(LIBS) am klib) # lazy evaluation ("=") causes infinite recursions
LINKAGE = $(OBJS) # library archives are added by LIB_TEMPLATE below

## 3. General Compilation Flags

### (Cross) compilers, e.g., mips-linux-gnu-g++
AS = $(CROSS_COMPILE)gcc
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld
AR = $(CROSS_COMPILE)ar
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
READELF = $(CROSS_COMPILE)readelf

### Compilation flags
INC_PATH += $(WORK_DIR)/include $(addsuffix /include/, $(addprefix $(AM_HOME)/, $(LIBS)))
INCFLAGS += $(addprefix -I, $(INC_PATH))

ARCH_H := arch/$(ARCH).h
CFLAGS += -O2 -MMD -Wall -Werror $(INCFLAGS) \
-D__ISA__=\"$(ISA)\" -D__ISA_$(shell echo $(ISA) | tr a-z A-Z)__ \
-D__ARCH__=$(ARCH) -D__ARCH_$(shell echo $(ARCH) | tr a-z A-Z | tr - _) \
-D__PLATFORM__=$(PLATFORM) -D__PLATFORM_$(shell echo $(PLATFORM) | tr a-z A-Z | tr - _) \
-DARCH_H=\"$(ARCH_H)\" \
-fno-asynchronous-unwind-tables -fno-builtin -fno-stack-protector \
-Wno-main -U_FORTIFY_SOURCE -fvisibility=hidden
CXXFLAGS += $(CFLAGS) -ffreestanding -fno-rtti -fno-exceptions
ASFLAGS += -MMD $(INCFLAGS)
LDFLAGS += -z noexecstack $(addprefix -T, $(LDSCRIPTS))

## 4. Arch-Specific Configurations

### Paste in arch-specific configurations (e.g., from `scripts/x86_64-qemu.mk`)
-include $(AM_HOME)/scripts/$(ARCH).mk

## 5. Compilation Rules

### Rule (compile): a single `.c` -> `.o` (gcc)
$(DST_DIR)/%.o: %.c
@mkdir -p $(dir $@) && echo + CC $<
@$(CC) -std=gnu11 $(CFLAGS) -c -o $@ $(realpath $<)

### Rule (compile): a single `.cc` -> `.o` (g++)
$(DST_DIR)/%.o: %.cc
@mkdir -p $(dir $@) && echo + CXX $<
@$(CXX) -std=c++17 $(CXXFLAGS) -c -o $@ $(realpath $<)

### Rule (compile): a single `.cpp` -> `.o` (g++)
$(DST_DIR)/%.o: %.cpp
@mkdir -p $(dir $@) && echo + CXX $<
@$(CXX) -std=c++17 $(CXXFLAGS) -c -o $@ $(realpath $<)

### Rule (compile): a single `.S` -> `.o` (gcc, which preprocesses and calls as)
$(DST_DIR)/%.o: %.S
@mkdir -p $(dir $@) && echo + AS $<
@$(AS) $(ASFLAGS) -c -o $@ $(realpath $<)

ifeq ($(MAKECMDGOALS),archive)
### Rule (archive): objects (`*.o`) -> `ARCHIVE.a` (ar)
$(ARCHIVE): $(OBJS)
@echo + AR "->" $(shell realpath $@ --relative-to .)
@$(AR) rcs $@ $^
else
# $(1): library name
define LIB_TEMPLATE =
$$(AM_HOME)/$(1)/build/$(1)-$$(ARCH).a: force
@$$(MAKE) -s -C $$(AM_HOME)/$(1) archive
LINKAGE += $$(AM_HOME)/$(1)/build/$(1)-$$(ARCH).a
endef

### Rule (recursive make): build a dependent library (am, klib, ...)
$(foreach lib, $(LIBS), $(eval $(call LIB_TEMPLATE,$(lib))))
endif

### Rule (link): objects (`*.o`) and libraries (`*.a`) -> `IMAGE.elf`, the final ELF binary to be packed into image (ld)
$(IMAGE).elf: $(LINKAGE) $(LDSCRIPTS)
@echo \# Creating image [$(ARCH)]
@echo + LD "->" $(IMAGE_REL).elf
ifneq ($(filter $(ARCH),native),)
@$(CXX) -o $@ -Wl,--whole-archive $(LINKAGE) -Wl,-no-whole-archive $(LDFLAGS_CXX)
else
@$(LD) $(LDFLAGS) -o $@ --start-group $(LINKAGE) --end-group
endif

### Rule (`#include` dependencies): paste in `.d` files generated by gcc on `-MMD`
-include $(addprefix $(DST_DIR)/, $(addsuffix .d, $(basename $(SRCS))))

## 6. Miscellaneous

### Build order control
image: image-dep
archive: $(ARCHIVE)
image-dep: $(IMAGE).elf
.PHONY: image image-dep archive run

### Force to rebuild a rule
force:
.PHONY: force

### Clean a single project (remove `build/`)
clean:
rm -rf Makefile.html $(WORK_DIR)/build/
.PHONY: clean

### Clean all sub-projects within depth 2 (and ignore errors)
CLEAN_ALL = $(dir $(shell find . -mindepth 2 -name Makefile))
clean-all: $(CLEAN_ALL) clean
$(CLEAN_ALL):
-@$(MAKE) -s -C $@ clean
.PHONY: clean-all $(CLEAN_ALL)
13 changes: 13 additions & 0 deletions abstract-machine/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
AbstractMachine is a minimal, modularized, and machine-independent
abstraction layer of the computer hardware:

* physical memory and direct execution (The "Turing Machine");
* basic model for input and output devices (I/O Extension);
* interrupt/exception and processor context management (Context Extension);
* virtual memory and protection (Virtual Memory Extension);
* multiprocessing (Multiprocessing Extension).

CONTACTS

Bug reports and suggestions go to Yanyan Jiang ([email protected]) and Zihao
Yu ([email protected]).
5 changes: 5 additions & 0 deletions abstract-machine/am/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NAME := am
SRCS = $(addprefix src/, $(AM_SRCS))
INC_PATH += $(AM_HOME)/am/src

include $(AM_HOME)/Makefile
81 changes: 81 additions & 0 deletions abstract-machine/am/include/am.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#ifndef AM_H__
#define AM_H__

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include ARCH_H // this macro is defined in $CFLAGS
// examples: "arch/x86-qemu.h", "arch/native.h", ...

// Memory protection flags
#define MMAP_NONE 0x00000000 // no access
#define MMAP_READ 0x00000001 // can read
#define MMAP_WRITE 0x00000002 // can write

// Memory area for [@start, @end)
typedef struct {
void *start, *end;
} Area;

// Arch-dependent processor context
typedef struct Context Context;

// An event of type @event, caused by @cause of pointer @ref
typedef struct {
enum {
EVENT_NULL = 0,
EVENT_YIELD, EVENT_SYSCALL, EVENT_PAGEFAULT, EVENT_ERROR,
EVENT_IRQ_TIMER, EVENT_IRQ_IODEV,
} event;
uintptr_t cause, ref;
const char *msg;
} Event;

// A protected address space with user memory @area
// and arch-dependent @ptr
typedef struct {
int pgsize;
Area area;
void *ptr;
} AddrSpace;

#ifdef __cplusplus
extern "C" {
#endif

// ----------------------- TRM: Turing Machine -----------------------
extern Area heap;
void putch (char ch);
void halt (int code) __attribute__((__noreturn__));

// -------------------- IOE: Input/Output Devices --------------------
bool ioe_init (void);
void ioe_read (int reg, void *buf);
void ioe_write (int reg, void *buf);
#include "amdev.h"

// ---------- CTE: Interrupt Handling and Context Switching ----------
bool cte_init (Context *(*handler)(Event ev, Context *ctx));
void yield (void);
bool ienabled (void);
void iset (bool enable);
Context *kcontext (Area kstack, void (*entry)(void *), void *arg);

// ----------------------- VME: Virtual Memory -----------------------
bool vme_init (void *(*pgalloc)(int), void (*pgfree)(void *));
void protect (AddrSpace *as);
void unprotect (AddrSpace *as);
void map (AddrSpace *as, void *vaddr, void *paddr, int prot);
Context *ucontext (AddrSpace *as, Area kstack, void *entry);

// ---------------------- MPE: Multi-Processing ----------------------
bool mpe_init (void (*entry)());
int cpu_count (void);
int cpu_current (void);
int atomic_xchg (int *addr, int newval);

#ifdef __cplusplus
}
#endif

#endif
74 changes: 74 additions & 0 deletions abstract-machine/am/include/amdev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef __AMDEV_H__
#define __AMDEV_H__

// **MAY SUBJECT TO CHANGE IN THE FUTURE**

#define AM_DEVREG(id, reg, perm, ...) \
enum { AM_##reg = (id) }; \
typedef struct { __VA_ARGS__; } AM_##reg##_T;

AM_DEVREG( 1, UART_CONFIG, RD, bool present);
AM_DEVREG( 2, UART_TX, WR, char data);
AM_DEVREG( 3, UART_RX, RD, char data);
AM_DEVREG( 4, TIMER_CONFIG, RD, bool present, has_rtc);
AM_DEVREG( 5, TIMER_RTC, RD, int year, month, day, hour, minute, second);
AM_DEVREG( 6, TIMER_UPTIME, RD, uint64_t us);
AM_DEVREG( 7, INPUT_CONFIG, RD, bool present);
AM_DEVREG( 8, INPUT_KEYBRD, RD, bool keydown; int keycode);
AM_DEVREG( 9, GPU_CONFIG, RD, bool present, has_accel; int width, height, vmemsz);
AM_DEVREG(10, GPU_STATUS, RD, bool ready);
AM_DEVREG(11, GPU_FBDRAW, WR, int x, y; void *pixels; int w, h; bool sync);
AM_DEVREG(12, GPU_MEMCPY, WR, uint32_t dest; void *src; int size);
AM_DEVREG(13, GPU_RENDER, WR, uint32_t root);
AM_DEVREG(14, AUDIO_CONFIG, RD, bool present; int bufsize);
AM_DEVREG(15, AUDIO_CTRL, WR, int freq, channels, samples);
AM_DEVREG(16, AUDIO_STATUS, RD, int count);
AM_DEVREG(17, AUDIO_PLAY, WR, Area buf);
AM_DEVREG(18, DISK_CONFIG, RD, bool present; int blksz, blkcnt);
AM_DEVREG(19, DISK_STATUS, RD, bool ready);
AM_DEVREG(20, DISK_BLKIO, WR, bool write; void *buf; int blkno, blkcnt);
AM_DEVREG(21, NET_CONFIG, RD, bool present);
AM_DEVREG(22, NET_STATUS, RD, int rx_len, tx_len);
AM_DEVREG(23, NET_TX, WR, Area buf);
AM_DEVREG(24, NET_RX, WR, Area buf);

// Input

#define AM_KEYS(_) \
_(ESCAPE) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) _(F8) _(F9) _(F10) _(F11) _(F12) \
_(GRAVE) _(1) _(2) _(3) _(4) _(5) _(6) _(7) _(8) _(9) _(0) _(MINUS) _(EQUALS) _(BACKSPACE) \
_(TAB) _(Q) _(W) _(E) _(R) _(T) _(Y) _(U) _(I) _(O) _(P) _(LEFTBRACKET) _(RIGHTBRACKET) _(BACKSLASH) \
_(CAPSLOCK) _(A) _(S) _(D) _(F) _(G) _(H) _(J) _(K) _(L) _(SEMICOLON) _(APOSTROPHE) _(RETURN) \
_(LSHIFT) _(Z) _(X) _(C) _(V) _(B) _(N) _(M) _(COMMA) _(PERIOD) _(SLASH) _(RSHIFT) \
_(LCTRL) _(APPLICATION) _(LALT) _(SPACE) _(RALT) _(RCTRL) \
_(UP) _(DOWN) _(LEFT) _(RIGHT) _(INSERT) _(DELETE) _(HOME) _(END) _(PAGEUP) _(PAGEDOWN)

#define AM_KEY_NAMES(key) AM_KEY_##key,
enum {
AM_KEY_NONE = 0,
AM_KEYS(AM_KEY_NAMES)
};

// GPU

#define AM_GPU_TEXTURE 1
#define AM_GPU_SUBTREE 2
#define AM_GPU_NULL 0xffffffff

typedef uint32_t gpuptr_t;

struct gpu_texturedesc {
uint16_t w, h;
gpuptr_t pixels;
} __attribute__((packed));

struct gpu_canvas {
uint16_t type, w, h, x1, y1, w1, h1;
gpuptr_t sibling;
union {
gpuptr_t child;
struct gpu_texturedesc texture;
};
} __attribute__((packed));

#endif
Loading