gen_symtab.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. """
  3. Embedded symbol table generator.
  4. """
  5. import sys
  6. symtab = []
  7. def valid_symbol (parts):
  8. if len (parts) != 4:
  9. return False
  10. sym = parts[3]
  11. if (sym.startswith ("__func__") or sym.startswith ("CSWTCH") or
  12. (parts[2] == 'r' and sym.startswith ("symbol_name_"))):
  13. return False
  14. del parts[2]
  15. return True
  16. for line in sys.stdin:
  17. line = line.strip ()
  18. parts = line.split (' ')
  19. if not valid_symbol (parts):
  20. continue
  21. sym = {'addr': parts[0], 'size': parts[1], 'name': parts[2]}
  22. symtab.append (sym)
  23. print ("#include <kern/symbol.h>")
  24. for index, sym in enumerate (symtab):
  25. print ("static const char symbol_name_%u[] __symbol_table = \"%s\";" %
  26. (index, sym['name']))
  27. print ("const struct symbol symbol_table[] __symbol_table = {")
  28. for index, sym in enumerate (symtab):
  29. print (" { 0x%s, 0x%s, symbol_name_%u }," %
  30. (sym['addr'], sym['size'], index))
  31. print ("};")
  32. print ("const size_t symbol_table_size = %d;" % len (symtab))
  33. print ("const struct symbol *symbol_table_ptr = symbol_table;")