-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm_compile.sh
executable file
·103 lines (96 loc) · 2.42 KB
/
arm_compile.sh
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
#!/bin/bash
show_help() {
echo "assemble, link, execute, and debug ARM assembly"
echo "author: Ryan Monaghan, Jason Qiu"
echo "version: 1.0 - 10/4/2024"
echo
echo "Usage: asmExec [-h|-e|-d|-l|-g|-p <number>] -f <targetfile>"
echo "e execute after linking"
echo "d debug the program with gdb"
echo "p port number for debugging (default: 4321)"
echo "l link C library when assembling"
echo "g assemble with debug information"
echo "o output executable name"
echo "f specify file to run"
}
# No options
if [ $# -eq 0 ]
then
show_help
exit
fi
# Handle options
gdb=""
lc=""
execute=0
inputfile=""
targetfile=""
port_num="4321"
while getopts ":gledp:o:f:" option; do
case $option in
l)
lc="-lc";;
g)
gdb="-g";;
d)
execute=2;;
e)
execute=1;;
f)
inputfile="$OPTARG";;
p)
port_num="$OPTARG";;
o)
targetfile="$OPTARG"
if [ -z $targetfile ] || [ "$targetfile" == "-f" ] # If targetfile is empty (check if equal to -f becasue if -f is called after it then we get this)
then
echo "you must specify an output file. type ./asmExec -h for help."
exit
fi;;
?)
show_help
exit;;
esac
done
if [ -z $inputfile ] # If inputfile is empty
then
echo "no input file specified"
exit
fi
if [ -z $targetfile ]
then
targetfile=${inputfile%.*}
fi
echo "assembling and linking '$inputfile'..."
aarch64-linux-gnu-as $gdb $inputfile -o $targetfile.o
aarch64-linux-gnu-ld $targetfile.o -o $targetfile $lc
echo "done."
if [ $execute -eq 1 ]
then
echo "executing..."
if [ -n $lc ]
then
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $targetfile
else
qemu-aarch64 $targetfile
fi
echo "done."
elif [ $execute -eq 2 ]
then
echo "executing in debug mode..."
if [ -n $lc ]
then
qemu-aarch64 -L /usr/aarch64-linux-gnu/ -g $port_num $targetfile &
else
qemu-aarch64 -g $port_num $targetfile &
fi
echo "starting debug on port $port_num..." &
gdb-multiarch --nh -q $targetfile \
-ex "set disassemble-next-line on" \
-ex "target remote :$port_num" \
-ex "set solib-search-path/usr/aarch64-linux-gnu-lib/" \
-ex "layout regs"
pkill -9 qemu
echo "done."
exit
fi