blob: 8dd516269838614ce398b98d5b12de22a953c6f7 (
plain) (
blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
MAIN_FILE = MemtestEfi
CC = gcc
# Warnings
CFLAGS = -Werror -Wall -Wno-array-bounds -Wno-address
CFLAGS += -fno-builtin
# EFI requires -fshort-wchar
CFLAGS += -fshort-wchar
CFLAGS += -fno-common
CFLAGS += -fno-strict-aliasing
# Enable debug info generation at compile time
CFLAGS += -g
# EFI uses Microsoft ABI so no red zone is defined
CFLAGS += -mno-red-zone
# use %rip-relative addressing wherever possible?? Or not?
CFLAGS += -fpie
#CFLAGS += -fno-pie -no-pie -static
# the UEFI PE executables must be relocatable
CFLAGS += -fpic
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
# CFLAGS += -flto !!Do not use it. All is written to special ELF sections
# function calls must include the number of arguments passed to the functions
CFLAGS += -maccumulate-outgoing-args
CFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += -nostdlib
CFLAGS += -mcmodel=small
#CFLAGS += -fno-stack-protector e
M64=-m64
M32=-m32
M=$(M64)
PREPROCESSOR=-DUEFI -DUSING_LTO -Os \
-D DISABLE_NEW_DEPRECATED_INTERFACES "-DEFIAPI=__attribute__((ms_abi))"
OBJS=Efi_Defs.o BaseLib.o BaseMemoryLib.o BasePrintLib.o \
UefiDebugLibStdErr.o UefiDevicePathLib2.o UefiLib2.o ApplicationEntryPoint.o \
BaseDebugPrintErrorLevelLib.o UefiMemoryAllocationLib.o BasePcdLibNull.o \
UefiRuntimeServicesTableLib.o UefiBootServicesTableLib.o MemtestEfi.o
BaseMemoryLib_OBJS=CompareMemWrapper.o CopyMem.o CopyMemWrapper.o IsZeroBufferWrapper.o \
MemLibGeneric.o MemLibGuid.o ScanMem16Wrapper.o ScanMem32Wrapper.o ScanMem64Wrapper.o \
ScanMem8Wrapper.o SetMem.o SetMem16Wrapper.o SetMem32Wrapper.o SetMem64Wrapper.o \
SetMemWrapper.o ZeroMemWrapper.o
UefiDevicePathLib_OBJS=DevicePathFromText.o DevicePathToText.o DevicePathUtilities.o \
DevicePathUtilitiesDxeSmm.o DevicePathUtilitiesStandaloneMm.o UefiDevicePathLib.o \
UefiDevicePathLibOptionalDevicePathProtocol.o
BaseLib_OBJS=ARShiftU64.o BitField.o CheckSum.o CpuDeadLoop.o Cpu.o DivU64x64Remainder.o \
DivU64x32Remainder.o DivU64x32.o DivS64x64Remainder.o FilePaths.o GetPowerOfTwo64.o \
GetPowerOfTwo32.o HighBitSet64.o HighBitSet32.o LongJump.o LRotU64.o LowBitSet64.o \
LowBitSet32.o LRotU32.o LShiftU64.o Math64.o ModU64x32.o MultU64x64.o MultU64x32.o MultS64x64.o \
RRotU32.o RRotU64.o RShiftU64.o SafeString.o String.o SetJump.o SwapBytes64.o SwapBytes32.o \
SwapBytes16.o SwitchStack.o Unaligned.o
SECTIONS=.text .sdata .data .dynamic .dynsym .rel .rela .reloc
all: clean MemtestEfi.efi move run
MemtestEfi.efi: MemtestEfi.so
objcopy $(foreach sec,$(SECTIONS), -j $(sec)) --target=pei-x86-64 --subsystem=10 $< $@
$(MAIN_FILE).so: $(OBJS)
ld -shared -Bsymbolic -fuse-linker-plugin -Telf_x86_64_efi.lds -o $@ $^
#rm $^
$(MAIN_FILE).o: $(MAIN_FILE).c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I . \
-I"memtest86+" \
-I"memtest86+/efi/Include"
Efi_Defs.o: memtest86+/efi/Include/Efi_Defs.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
%.o: memtest86+/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi"
%.o: memtest86+/efi/Include/src/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include" \
-I"memtest86+/efi/Include/Library"
%.o: memtest86+/efi/Include/src/UefiLib/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include" \
-I"memtest86+/efi/Include/Protocol" \
-I"memtest86+/efi/Include/Guid"
BasePcdLibNull.o: memtest86+/efi/Include/src/PcdLib.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
UefiMemoryAllocationLib.o: memtest86+/efi/Include/src/MemoryAllocationLib.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
UefiLib2.o: Acpi.o Console.o UefiDriverModel.o UefiLib.o UefiLibPrint.o UefiNotTiano.o
ld -r -o $@ $^
rm $^
%.o: memtest86+/efi/Include/src/UefiDebugLibStdErr/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
UefiDebugLibStdErr.o: DebugLib.o DebugLibConstructor.o
ld -r -o $@ $^
rm $^
%.o: memtest86+/efi/Include/src/BaseMemoryLib/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
BaseMemoryLib.o: $(BaseMemoryLib_OBJS)
ld -r -o $@ $^
rm $^
%.o: memtest86+/efi/Include/src/BasePrintLib/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
BasePrintLib.o: PrintLib.o PrintLibInternal.o
ld -r -o $@ $^
rm $^
%.o: memtest86+/efi/Include/src/UefiDevicePathLib/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) -flto $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
UefiDevicePathLib2.o: $(UefiDevicePathLib_OBJS)
ld -r -o $@ $^
rm $^
%.o: memtest86+/efi/Include/src/BaseLib/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+/efi/Include"
BaseLib.o: $(BaseLib_OBJS)
ld -r -o $@ $^
rm $^
%.o: memtest86+/efi/%.c
$(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \
-I"memtest86+" \
-I"memtest86+/efi" \
-I"memtest86+/efi/Include"
clean:
rm -f memtest86+/*.o
rm -f *.o
rm -f MemtestEfi.o
rm -f MemtestEfi.map
rm -f MemtestEfi.dll
rm -f MemtestEfi.efi
rm -f MemtestEfi.txt
rm -f Efi_Defs.o
move:
cp MemtestEfi.efi ../test_code/hda-contents
run:
sudo ./run.sh
|