mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[panic] Add separate kernel-mode panic handler
Created the framework for using different loadable panic handlers, loaded by the bootloader. Initial panic handler is panic.serial, which contains its own serial driver and stacktrace code. Other related changes: - Asserts are now based on the NMI handler - panic handlers get installed as the NMI interrupt handler - Changed symbol table generation: now use nm's own demangling and sorting, and include symbol size in the table - Move the linker script argument out of the kernel target, and into the kernel's specific module, so that other programs (ie, panic handlers) can use the kernel target as well - Some asm changes to boot.s to help GDB see stack frames - but this might not actually be all that useful - Renamed user_rsp to just rsp in cpu_state - everything in there is describing the 'user' state
This commit is contained in:
@@ -4,37 +4,37 @@
|
||||
# is as follows:
|
||||
#
|
||||
# <num_entires> : 8 bytes
|
||||
# <index> : 16 * N bytes
|
||||
# <index> : 24 * N bytes
|
||||
# <name data> : variable
|
||||
#
|
||||
# Each index entry has the format
|
||||
# <symbol address> : 8 bytes
|
||||
# <symbol size> : 8 bytes
|
||||
# <offset of name> : 8 bytes
|
||||
#
|
||||
# Name offsets are from the start of the symbol table as a whole. (ie,
|
||||
# where <num_entries> is located.)
|
||||
|
||||
import re
|
||||
|
||||
sym_re = re.compile(r'([0-9a-fA-F]{16}) ([0-9a-fA-F]{16}) [tTvVwW] (.*)')
|
||||
|
||||
def parse_syms(infile):
|
||||
"""Take the output of the `nm` command, and parse it into a tuple
|
||||
representing the symbols in the text segment of the binary. Returns
|
||||
a list of (address, symbol_name)."""
|
||||
|
||||
from cxxfilt import demangle, InvalidName
|
||||
|
||||
syms = []
|
||||
for line in sys.stdin:
|
||||
addr, t, mangled = line.split()
|
||||
if t not in "tTvVwW": continue
|
||||
match = sym_re.match(line)
|
||||
if not match: continue
|
||||
|
||||
try:
|
||||
name = demangle(mangled)
|
||||
except InvalidName:
|
||||
continue
|
||||
addr = int(match.group(1), base=16)
|
||||
size = int(match.group(2), base=16)
|
||||
name = match.group(3)
|
||||
syms.append([addr, size, name, 0])
|
||||
|
||||
addr = int(addr, base=16)
|
||||
syms.append((addr, name))
|
||||
|
||||
return sorted(syms)
|
||||
return syms
|
||||
|
||||
|
||||
def write_table(syms, outfile):
|
||||
@@ -46,29 +46,26 @@ def write_table(syms, outfile):
|
||||
outfile.write(struct.pack("@Q", len(syms)))
|
||||
index_pos = outfile.tell()
|
||||
|
||||
outfile.seek(struct.calcsize("@QQ") * len(syms), 1)
|
||||
outfile.seek(struct.calcsize("@QQQ") * len(syms), 1)
|
||||
nul = b'\0'
|
||||
|
||||
positions = {}
|
||||
for s in syms:
|
||||
addr, name = s
|
||||
positions[addr] = outfile.tell()
|
||||
|
||||
data = name.encode('utf-8')
|
||||
outfile.write(name.encode('utf-8'))
|
||||
s[3] = outfile.tell()
|
||||
outfile.write(s[2].encode('utf-8'))
|
||||
outfile.write(nul)
|
||||
|
||||
outfile.seek(index_pos)
|
||||
for s in syms:
|
||||
addr = s[0]
|
||||
pos = positions[addr]
|
||||
outfile.write(struct.pack("@QQ", addr, pos))
|
||||
size = s[1]
|
||||
pos = s[3]
|
||||
outfile.write(struct.pack("@QQQ", addr, size, pos))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) != 2:
|
||||
print(f"Usage: {sys.argv[0]} <output>")
|
||||
print(f"Usage: nm -n -S --demangle | {sys.argv[0]} <output>")
|
||||
sys.exit(1)
|
||||
|
||||
outfile = open(sys.argv[1], "wb")
|
||||
|
||||
Reference in New Issue
Block a user