-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (44 loc) · 1.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
PAYLOAD64 := helloworld-gas-64bit
C_PAYLOAD64 := helloworld-c-64bit
all: kvm_test
kvm_test: kvm_test.c
gcc kvm_test.c -o kvm_test
kvm_bare: kvm_bare.c
gcc kvm_bare.c -o kvm_bare
bare: bare.c
cc -c bare.c
objcopy bare.o bare -O binary
helloworld-gas-16bit.o: helloworld-gas-16bit.s
as -32 helloworld-gas-16bit.s -o helloworld-gas-16bit.o
helloworld-gas-16bit.bin: helloworld-gas-16bit.o
ld -m elf_i386 --oformat binary -N -e _start -Ttext 0x10000 -o helloworld-gas-16bit.bin helloworld-gas-16bit.o
.PHONY: disasm-16
disasm-16: helloworld-gas-16bit.bin
objdump -D helloworld-gas-16bit.o
hexdump -C helloworld-gas-16bit.bin
$(PAYLOAD64).o: $(PAYLOAD64).s
as -64 $(PAYLOAD64).s -o $(PAYLOAD64).o
$(PAYLOAD64).bin: $(PAYLOAD64).o
ld --oformat binary -N -e _start -Ttext 0x10000 -o $(PAYLOAD64).bin $(PAYLOAD64).o
.PHONY: disasm-64
disasm-64: $(PAYLOAD64).bin
objdump -D $(PAYLOAD64).o
hexdump -C $(PAYLOAD64).bin
.PHONY: run-kvm_bare
run-kvm_bare-16: kvm_bare disasm-16 helloworld-gas-16bit.bin
./kvm_bare helloworld-gas-16bit.bin
run-kvm_bare-64: kvm_bare disasm-64 $(PAYLOAD64).bin
./kvm_bare $(PAYLOAD64).bin
$(C_PAYLOAD64).o: $(C_PAYLOAD64).c
gcc -nostdlib -fomit-frame-pointer -m64 -c $(C_PAYLOAD64).c -o $(C_PAYLOAD64).o
$(C_PAYLOAD64).bin: $(C_PAYLOAD64).o
ld --oformat binary -N -e _start -Ttext 0x10000 -o $(C_PAYLOAD64).bin $(C_PAYLOAD64).o
.PHONY: run-kvm_bare-c-64
run-kvm_bare-c-64: kvm_bare $(C_PAYLOAD64).bin $(C_PAYLOAD64).o
objdump -d $(C_PAYLOAD64).o
hexdump -C $(C_PAYLOAD64).bin
# the objdump thing is to get the _start symbol address
./kvm_bare $(C_PAYLOAD64).bin $(shell objdump -t $(C_PAYLOAD64).o | grep '_start' | cut -f 1 -d ' ')
.PHONY: clean
clean:
rm *.o *.bin kvm_bare kvm_test