summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux')
-rwxr-xr-xbuild-aux/stack.c.gen66
1 files changed, 52 insertions, 14 deletions
diff --git a/build-aux/stack.c.gen b/build-aux/stack.c.gen
index 11c5854..d9d128a 100755
--- a/build-aux/stack.c.gen
+++ b/build-aux/stack.c.gen
@@ -1469,24 +1469,62 @@ def main(
print_group("Threads")
print_group("Interrupt handlers")
print("*/")
- overhead = max(v.nstatic for v in result.groups["Interrupt handlers"].rows.values())
+ intrstack = max(
+ v.nstatic for v in result.groups["Interrupt handlers"].rows.values()
+ )
stack_guard_size = 16 * 2
- rows: list[tuple[str, int, int]] = []
+
+ class CrRow(typing.NamedTuple):
+ name: str
+ cnt: int
+ base: int
+ size: int
+
+ rows: list[CrRow] = []
+ main: CrRow | None = None
for funcname, val in result.groups["Threads"].rows.items():
+ name = str(funcname.base())
base = val.nstatic
- size = next_power_of_2(base + overhead + stack_guard_size) - stack_guard_size
- rows.append((str(funcname.base()), base, size))
- namelen = max(len(r[0]) for r in rows)
- baselen = max(len(str(r[1])) for r in rows)
- sizelen = max(len(str(r[2])) for r in rows)
+ size = base + intrstack
+ if name in ("main", "_reset_handler"):
+ main = CrRow(name=name, cnt=1, base=base, size=size)
+ else:
+ size = next_power_of_2(size + stack_guard_size) - stack_guard_size
+ rows.append(CrRow(name=name, cnt=val.cnt, base=base, size=size))
+ namelen = max(len(r.name) for r in rows)
+ baselen = max(len(str(r.base)) for r in rows)
+ sizesum = sum(r.cnt * (r.size + stack_guard_size) for r in rows)
+ sizelen = len(str(max(sizesum, main.size if main else 0)))
+
+ def print_row(comment: bool, name: str, size: int, eqn: str | None = None) -> None:
+ prefix = "const size_t CONFIG_COROUTINE_STACK_SIZE_"
+ if comment:
+ print(f"/* {name}".ljust(len(prefix) + namelen), end="")
+ else:
+ print(f"{prefix}{name.ljust(namelen)}", end="")
+ print(f" = {str(size).rjust(sizelen)};", end="")
+ if comment:
+ print(" */", end="")
+ elif eqn:
+ print(" ", end="")
+ if eqn:
+ print(f" /* {eqn} */", end="")
+ print()
+
for row in sorted(rows):
- if row[0] in ("main", "_reset_handler"):
- continue
- print("const size_t CONFIG_COROUTINE_STACK_SIZE_", end="")
- print(f"{row[0].ljust(namelen)} =", end="")
- print(f" {str(row[2]).rjust(sizelen)};", end="")
- print(
- f" /* LM_NEXT_POWER_OF_2({str(row[1]).rjust(baselen)}+{overhead}+{stack_guard_size})-{stack_guard_size} */"
+ print_row(
+ False,
+ row.name,
+ row.size,
+ f"LM_NEXT_POWER_OF_2({str(row.base).rjust(baselen)}+{intrstack}+{stack_guard_size})-{stack_guard_size}",
+ )
+ print_row(True, "TOTAL (inc. stack guard)", sizesum)
+ if main:
+ print_row(
+ True,
+ "MAIN/KERNEL",
+ main.size,
+ f" {str(main.base).rjust(baselen)}+{intrstack}",
)
print()
print("/*")