https://github.com/akkartik/mu/blob/master/020syscalls.cc
1 :(before "End Initialize Op Names")
2 put_new(Name, "cd", "software interrupt (int)");
3
4 :(before "End Single-Byte Opcodes")
5 case 0xcd: {
6 trace(Callstack_depth+1, "run") << "syscall" << end();
7 uint8_t code = next();
8 if (code != 0x80) {
9 raise << "Unimplemented interrupt code " << HEXBYTE << code << '\n' << end();
10 raise << " Only `int 80h` supported for now.\n" << end();
11 break;
12 }
13 process_int80();
14 break;
15 }
16
17 :(code)
18 void process_int80() {
19 switch (Reg[EAX].u) {
20 case 1:
21 exit(Reg[EBX].u);
22 break;
23 case 3:
24 trace(Callstack_depth+1, "run") << "read: " << Reg[EBX].u << ' ' << Reg[ECX].u << ' ' << Reg[EDX].u << end();
25 Reg[EAX].i = read(Reg[EBX].u, mem_addr_u8(Reg[ECX].u), Reg[EDX].u);
26 trace(Callstack_depth+1, "run") << "result: " << Reg[EAX].i << end();
27 if (Reg[EAX].i == -1) raise << "read: " << strerror(errno) << '\n' << end();
28 break;
29 case 4:
30 trace(Callstack_depth+1, "run") << "write: " << Reg[EBX].u << ' ' << Reg[ECX].u << ' ' << Reg[EDX].u << end();
31 trace(Callstack_depth+1, "run") << Reg[ECX].u << " => " << mem_addr_string(Reg[ECX].u, Reg[EDX].u) << end();
32 Reg[EAX].i = write(Reg[EBX].u, mem_addr_u8(Reg[ECX].u), Reg[EDX].u);
33 trace(Callstack_depth+| grep -m 1 -o '[0-9][0-9.]\+')
SNAPSHOT_NAME ?= $(NAME)-$(VERSION)-$(shell git rev-parse HEAD | cut -b 1-8).tar.gz
# Find suitable python version (need python >= 2.6 or 3.1):
PYTHON ?= $(shell python -c 'import sys; sys.exit(sys.version < "2.6")' && \
which python || which python3.1 || which python3 || which python2.6)
SETUPOPTS ?= '--record=install_log.txt'
DOCDIR ?= doc/pydoc
DESTDIR ?= /
PYOPTIMIZE ?= 1
BMCOUNT ?= 5 # how often to run the benchmarks?
CWD = $(shell pwd)
default: compile
@echo 'Run `make options` for a list of all options'
options: help
@echo
@echo 'Options:'
@echo 'PYTHON = $(PYTHON)'
@echo 'PYOPTIMIZE = $(PYOPTIMIZE)'
@echo 'DOCDIR = $(DOCDIR)'
help:
@echo 'make install: Install $(NAME)'
@echo 'make doc: Create the pydoc documentation'
@echo 'make clean: Remove the compiled files (*.pyc, *.pyo)'
@echo 'make cleandoc: Remove the pydoc documentation'
@echo 'make snapshot: Create a tar.gz of the current git revision'
@echo 'make test: Run all unittests.'
install:
$(PYTHON) setup.py install $(SETUPOPTS) \
'--root=$(DESTDIR)' --optimize=$(PYOPTIMIZE)
compile: clean
PYTHONOPTIMIZE=$(PYOPTIMIZE) $(PYTHON) -m compileall -q ranger
clean:
find . -regex .\*.py[co]\$$ -exec rm -f -- {} \;
doc: cleandoc
mkdir -p $(DOCDIR)
cd $(DOCDIR); \
$(PYTHON) -c 'import pydoc, sys; \
sys.path[0] = "$(CWD)"; \
pydoc.writedocs("$(CWD)")'
rm $(DOCDIR)/test*
find . -name \*.html -exec sed -i 's|'$(CWD)'|../..|g' -- {} \;
cleandoc:
test -d $(DOCDIR) && rm -f -- $(DOCDIR)/*.html || true
test:
@$(PYTHON) test/all_tests.py 1
bm:
@$(PYTHON) test/all_benchmarks.py $(BMCOUNT)
snapshot:
git archive --prefix='$(NAME)-$(VERSION)/' --format=tar HEAD | gzip > $(SNAPSHOT_NAME)
.PHONY: default options compile clean doc cleandoc test bm snapshot install