summaryrefslogtreecommitdiffstats
path: root/allocate_pages_test/build.sh
blob: 4feccf2cfbbca8c1b2ad38b14caca45faa26f907 (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
191
#!/bin/bash

MAIN_FILE="MemtestEfi"

OBJECT_FILES=(AutoGen.obj OUTPUT/main.o  OUTPUT/test.o OUTPUT/smp.o
	OUTPUT/config.o OUTPUT/screen_buffer.o OUTPUT/lib.o OUTPUT/init.o OUTPUT/controller.o
	OUTPUT/pci.o OUTPUT/spd.o OUTPUT/dmi.o OUTPUT/reloc.o OUTPUT/patn.o OUTPUT/linuxbios.o
	OUTPUT/error.o OUTPUT/vmem.o OUTPUT/cpuid.o OUTPUT/memsize.o OUTPUT/random.o OUTPUT/$MAIN_FILE.obj)

STATIC_LIBRARY_FILES=(OUTPUT/$MAIN_FILE.lib libs/BaseLib.lib
	libs/BaseMemoryLib.lib libs/BasePcdLibNull.lib 
	libs/BaseDebugPrintErrorLevelLib.lib libs/BasePrintLib.lib
	libs/UefiDebugLibStdErr.lib libs/UefiBootServicesTableLib.lib 
	libs/UefiMemoryAllocationLib.lib libs/UefiRuntimeServicesTableLib.lib
	libs/UefiDevicePathLib.lib libs/UefiApplicationEntryPoint.lib libs/UefiLib.lib)

INCLUDE_FILES=(main cpuid test smp config screen_buffer lib init controller pci
	spd dmi reloc patn linuxbios error vmem memsize random)

ADDITIONAL_HEADER=(defs.h linuxbios_tables.h stdin.h io.h stdint.h stddef.h serial.h msr.h jedec_id.h elf.h)

rm -f OUTPUT/*

echo "######################## Create *.o files"
for elem in ${ADDITIONAL_HEADER[@]}
  do
  	cp memtest86+/${elem} OUTPUT/
  done

for elem in ${INCLUDE_FILES[@]}
  do
  	cp memtest86+/${elem}.* OUTPUT/
  done

for elem in ${INCLUDE_FILES[@]}
  do
  	gcc -c \
  	-IInclude \
  	-g \
  	-fno-stack-protector \
  	-fno-common \
  	-fshort-wchar \
  	-fno-builtin \
  	-fno-strict-aliasing \
  	-Wall \
  	-Wno-array-bounds \
  	-ffunction-sections \
  	-fdata-sections \
  	-include Include/AutoGen.h \
  	-m64 \
  	-maccumulate-outgoing-args \
	-mno-red-zone \
	-Wno-address \
	-mcmodel=small \
	-fpie \
	-fno-asynchronous-unwind-tables \
	-Wno-address \
	-flto \
	-DUSING_LTO \
	-Os \
	-D DISABLE_NEW_DEPRECATED_INTERFACES \
  	"-DEFIAPI=__attribute__((ms_abi))" \
  	-o  OUTPUT/${elem}.o \
  	OUTPUT/${elem}.c
    
    if [ $? -ne 0 ]; then exit 1; fi
  done


# -Werror \

if [ $? -ne 0 ]; then exit 1; fi
echo "####################### Create obj file\n"
#-S
#-fverbose-asm
#	-m32 \

#gcc -E -traditional memtest86+/head.S -o memtest86+/head.s
#as --64 -o memtest86+/head.o memtest86+/head.s


#gcc -E -traditional memtest86+/bootsect.S -o memtest86+/bootsect.s
#as -o memtest86+/bootsect.o memtest86+/bootsect.s


#gcc -E -traditional memtest86+/setup.S -o memtest86+/setup.s
#as -o memtest86+/setup.o memtest86+/setup.s


gcc -MMD -MF OUTPUT/$MAIN_FILE.obj.deps \
	-g \
	-fshort-wchar \
	-fno-builtin \
	-fno-strict-aliasing \
	-Wall \
	-Wno-array-bounds \
	-ffunction-sections \
	-fdata-sections \
	-include Include/AutoGen.h \
	-fno-common \
	-DSTRING_ARRAY_NAME=${MAIN_FILE}Strings \
	-m64 \
	-fno-stack-protector \
	"-DEFIAPI=__attribute__((ms_abi))" \
	-maccumulate-outgoing-args \
	-mno-red-zone \
	-Wno-address \
	-mcmodel=small \
	-fpie \
	-fno-asynchronous-unwind-tables \
	-Wno-address \
	-flto \
	-DUSING_LTO \
	-Os \
	-D DISABLE_NEW_DEPRECATED_INTERFACES \
	-c \
	-o OUTPUT/$MAIN_FILE.obj  \
	-I . \
	-IInclude \
	-IOUTPUT \
	$MAIN_FILE.c


if [ $? -ne 0 ]; then exit 1; fi
echo "####################### Create $MAIN_FILE.lib"

echo ${OBJECT_FILES[@]}


gcc-ar crv OUTPUT/$MAIN_FILE.lib  "${OBJECT_FILES[@]}"

if [ $? -ne 0 ]; then exit 1; fi
echo "####################### Create $MAIN_FILE.dll"

echo ${STATIC_LIBRARY_FILES[@]}


gcc 	-o OUTPUT/$MAIN_FILE.dll \
	-nostdlib \
	-Wl,-n,-q,--gc-sections \
	-Wl,--entry,_ModuleEntryPoint \
	-Wl,-Map,OUTPUT/$MAIN_FILE.map,--whole-archive \
	-Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie \
	-Wl,--start-group,@static_library_files.lst,--end-group \
	-Wl,--defsym=PECOFF_HEADER_SIZE=0x228 \
	-Wl,--script=Include/GccBase.lds \
	-z common-page-size=0x40 \
	-u _ModuleEntryPoint \
	-flto \
	-Os \
	-g \
	-fshort-wchar \
	-fno-builtin \
	-fno-strict-aliasing \
	-Wall \
	-Werror \
	-Wno-array-bounds \
	-ffunction-sections \
	-fdata-sections \
	-fno-common \
	-DSTRING_ARRAY_NAME=${MAIN_FILE}Strings \
	-m64 \
	-fno-stack-protector \
	"-DEFIAPI=__attribute__((ms_abi))" \
	-maccumulate-outgoing-args \
	-mno-red-zone \
	-Wno-address \
	-mcmodel=small \
	-fpie \
	-fno-asynchronous-unwind-tables \
	-Wno-address \
	-flto \
	-DUSING_LTO \
	-Os \
	-D DISABLE_NEW_DEPRECATED_INTERFACES \
	-include AutoGen.h \
	-I OUTPUT/ \
	-I Library/ \
	-Wno-error

if [ $? -ne 0 ]; then exit 1; fi
echo "####################### Objcopy strip unneeded"
objcopy --strip-unneeded -R .eh_frame -v OUTPUT/$MAIN_FILE.dll OUTPUT/$MAIN_FILE.dll


if [ $? -ne 0 ]; then exit 1; fi
echo "####################### Run GenFW"

./Include/GenFw -e UEFI_APPLICATION -o OUTPUT/start_$MAIN_FILE.efi OUTPUT/$MAIN_FILE.dll

cp -v OUTPUT/start_$MAIN_FILE.efi ../test_code/hda-contents/