aboutsummaryrefslogtreecommitdiff
path: root/tools/chksize
blob: 6f2c9b8c727bfac9ab9e5115e99303c385133047 (plain)
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
#!/usr/bin/env python3

import sys

# video memory + back buffer (stack in 0x200)
TOP_MEM = 0xc000


def main():
    if len(sys.argv) != 3:
        sys.exit("usage: %s load_addr filename.map" % sys.argv[0])

    load_addr = int(sys.argv[1])

    with open(sys.argv[2], "r") as fd:
        lines = fd.readlines()
        # warnings
        for line in lines:
            if "l__INITIALIZED" in line:
                init_size = int(line.split()[0], base=16)
                if init_size != 0:
                    print("*WARNING* Initialized data found")
        # search for HEAP
        for line in lines:
            if "s__HEAP" in line:
                heap_addr = int(line.split()[0], base=16)
                max_mem = TOP_MEM - load_addr
                cur_mem = heap_addr - load_addr
                left_mem = max_mem - cur_mem
                print("""\
***
      Max: {} bytes
  Current: {} bytes ({} bytes left)
***
""".format(max_mem, cur_mem, left_mem))
                sys.exit(0)

    sys.exit("HEAP size not found")


if __name__ == "__main__":
    main()