* Make the ksym table built-in with kernel image, thus remove the need
[lunaix-os.git] / lunaix-os / scripts / gen_ksymtable.sh
1 #!/bin/bash
2
3 sym_types=$1
4 bin=$2
5
6 nm_out=$(nm -nfbsd "$bin")
7 allsyms=($nm_out)
8 allsyms_len=${#allsyms[@]}
9
10 syms_idx=()
11
12 for (( i=0; i<allsyms_len; i+=3));
13 do
14     type=${allsyms[$i + 1]}
15
16     if [[ "$sym_types" == *"$type"* ]]; then
17         syms_idx+=($i)
18     fi
19 done
20
21 syms_len=${#syms_idx[@]}
22 declare -A assoc_array
23
24 echo '.section .ksymtable, "a", @progbits'
25 echo "    .global __lunaix_ksymtable"
26 echo "    __lunaix_ksymtable:"
27 echo "        .long $syms_len"
28 echo "        .align 8"
29
30 for i in "${syms_idx[@]}"
31 do
32     addr=${allsyms[$i]}
33     type=${allsyms[$i + 1]}
34     sym=${allsyms[$i + 2]}
35
36     echo "$(cat <<EOF
37         .long 0x$addr
38         .long __S$sym
39         .align 8
40
41 EOF
42 )"
43     assoc_array["$sym"]=1
44 done
45
46 for sym_str in "${!assoc_array[@]}"
47 do
48     echo "$(cat <<EOF
49     __S$sym_str:
50         .asciz "$sym_str"
51         .align 8
52 EOF
53 )"
54 done