#!/usr/bin/env python3 # # Copyright (c) 2017 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 import argparse import sys import struct import os import elftools from distutils.version import LooseVersion from elftools.elf.elffile import ELFFile from elftools.elf.sections import SymbolTableSection if LooseVersion(elftools.__version__) < LooseVersion('0.24'): sys.stderr.write("pyelftools is out of date, need version 0.24 or later\n") sys.exit(1) def debug(text): if not args.verbose: return sys.stdout.write(os.path.basename(sys.argv[0]) + ": " + text + "\n") def error(text): sys.stderr.write(os.path.basename(sys.argv[0]) + ": " + text + "\n") sys.exit(1) gdt_pd_fmt = "> 16) & 0xFF base_hi = (base >> 24) & 0xFF limit_lo = limit & 0xFFFF limit_hi = (limit >> 16) & 0xF return (base_lo, base_mid, base_hi, limit_lo, limit_hi) gdt_ent_fmt = "= 5: main_tss = syms["_main_tss"] df_tss = syms["_df_tss"] # Selector 0x18: main TSS fp.write(create_tss_entry(main_tss, 0x67, 0)) # Selector 0x20: double-fault TSS fp.write(create_tss_entry(df_tss, 0x67, 0)) if num_entries == 7: # Selector 0x28: code descriptor, dpl = 3 fp.write(create_code_data_entry(0, 0xFFFFF, 3, FLAGS_GRAN, ACCESS_EX | ACCESS_RW)) # Selector 0x30: data descriptor, dpl = 3 fp.write(create_code_data_entry(0, 0xFFFFF, 3, FLAGS_GRAN, ACCESS_RW)) if __name__ == "__main__": main()