|
| 1 | +CFLAGS=-std=gnu2x -Og -ggdb3 $(shell pkg-config --cflags $(PKGDEPS)) -mavx -march=znver2 |
| 2 | +CPPFLAGS=-Wall -W -D_GNU_SOURCE -DZENTOOL_VERSION=\"$(VERSION)\" -mavx -march=znver2 |
| 3 | +LDLIBS=$(shell pkg-config --libs $(PKGDEPS)) |
| 4 | +LDFLAGS=-Wl,-z,noexecstack |
| 5 | +VERSION=0.01 |
| 6 | + |
| 7 | +# List of all required dependencies in pkg-config format. |
| 8 | +PKGDEPS=openssl,gmp,json-c |
| 9 | + |
| 10 | +.PHONY: clean distclean sync check template.bin |
| 11 | + |
| 12 | +all: check zentool mcop mcas opcodes mtalk dumper |
| 13 | + |
| 14 | +# build debug versions of all binaries |
| 15 | +debug: CFLAGS+=-fsanitize=address -O0 |
| 16 | +debug: clean all |
| 17 | + |
| 18 | +# This is just to check all required packages are installed |
| 19 | +.ONESHELL: |
| 20 | +check: |
| 21 | + @pkg-config $(PKGDEPS) || { |
| 22 | + echo missing dependencies, try: |
| 23 | + echo Debian: apt install pkg-config libssl-dev libgmp-dev libjson-c-dev nasm pahole |
| 24 | + echo Fedora: dnf install pkg-config gmp-devel json-c-devel openssl-devel libasan nasm dwarves |
| 25 | + exit 1 |
| 26 | + } |
| 27 | + @pahole --version > /dev/null || { |
| 28 | + echo missing dependency, try: |
| 29 | + echo Debian: apt install pahole nasm |
| 30 | + echo Fedora: dnf install dwarves nasm |
| 31 | + exit 1 |
| 32 | + } |
| 33 | + @nasm --version > /dev/null || { |
| 34 | + echo missing dependency, try: |
| 35 | + echo Debian: apt install nasm |
| 36 | + echo Fedora: dnf install nasm |
| 37 | + exit 1 |
| 38 | + } |
| 39 | + |
| 40 | +sync: HOST=amdbench.cpu |
| 41 | +sync: |
| 42 | + rsync --delete -azF . $(HOST):zentool/ |
| 43 | + |
| 44 | +%.o: %.asm |
| 45 | + nasm $(NFLAGS) -felf64 -o $@ $^ |
| 46 | + |
| 47 | +.ONESHELL: |
| 48 | +%_fields.h: CLASS=$(patsubst %_fields.h,%,$@) |
| 49 | +%_fields.h: structs.o ucode.h risc86.h |
| 50 | + pahole -C $(CLASS) $< | awk 'BEGIN { |
| 51 | + print "/* This file was automatically generated */" |
| 52 | + } /unsigned int/ && $$3 !~ /^_/ { |
| 53 | + printf("REGISTER_BITFIELD($(CLASS), %s);\n",gensub(/:.*/, "", 1, $$3)) |
| 54 | + }' > $@ |
| 55 | + |
| 56 | +opcodes: CFLAGS=-fno-sanitize=address |
| 57 | +opcodes: corechk.o |
| 58 | + |
| 59 | +# This file is only used for generating bitfield headers. |
| 60 | +structs.o: CFLAGS+=-O0 |
| 61 | + |
| 62 | +# This binary does some weird asm stuff for testing. |
| 63 | +mtalk: LDFLAGS+=-O0 |
| 64 | + |
| 65 | +fields.o disas.o: RegOp_fields.h LdStOp_fields.h SpecOp_fields.h BrOp_fields.h SRegOp_fields.h |
| 66 | + |
| 67 | +zentool: ucode.o risc86.o preimage.o fixup.o loader.o \ |
| 68 | + dump.o options.o edit.o verify.o disas.o xxtea.o encrypt.o \ |
| 69 | + util.o parse.o cpuid.o data.o symbols.o fields.o factor.o |
| 70 | + |
| 71 | +mcas: disas.o options.o ucode.o parse.o ucode.o \ |
| 72 | + risc86.o preimage.o options.o util.o cpuid.o factor.o dump.o data.o |
| 73 | +mcop: ucode.o risc86.o disas.o util.o fields.o options.o \ |
| 74 | + cpuid.o preimage.o factor.o dump.o data.o |
| 75 | +mtalk: util.o options.o |
| 76 | +dumper: dumper.o |
| 77 | + |
| 78 | +# The automated tests use this file |
| 79 | +template.bin: REVISION=$(shell printf "%08X" $$(grep -m1 -oP '^microcode\s+:\s+\K\S+' /proc/cpuinfo)) |
| 80 | +template.bin: zentool |
| 81 | + ./zentool --output=$@ decrypt $(wildcard data/cpu????????_ver$(REVISION)_*.bin) |
| 82 | + ./zentool edit --hdr-autorun false --nop all --match all=0 $@ |
| 83 | + ./zentool resign $@ |
| 84 | + |
| 85 | +clean: |
| 86 | + rm -f *.o zentool mcas mcop mtalk opcodes dumper template.bin |
| 87 | + rm -f zentool-$(VERSION).tar.gz |
| 88 | + |
| 89 | +distclean: clean |
| 90 | + rm -f *_fields.h |
| 91 | + |
| 92 | +dist: distclean |
| 93 | + @tmpfile=$$(mktemp) |
| 94 | + @tar --directory=.. \ |
| 95 | + --exclude-vcs \ |
| 96 | + --exclude-vcs-ignores \ |
| 97 | + --exclude-tag-all=.nobackup \ |
| 98 | + --numeric-owner \ |
| 99 | + --owner=:1000 \ |
| 100 | + --group=:1000 \ |
| 101 | + --gzip \ |
| 102 | + --create \ |
| 103 | + --transform="s#^zentool#zentool-$(VERSION)#" \ |
| 104 | + --file=$${tmpfile} \ |
| 105 | + $(notdir $(abspath .)) |
| 106 | + @mv $${tmpfile} zentool-$(VERSION).tar.gz |
| 107 | + @ls -l zentool-$(VERSION).tar.gz |
0 commit comments