gen_gdt: add debug statements and simplify logic

This is in preparation for making CONFIG_USERSPACE not
depend on CONFIG_HW_STACK_PROTECTION.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-11-03 10:39:08 -07:00 committed by Andrew Boie
commit a705eae315
2 changed files with 23 additions and 27 deletions

View file

@ -265,16 +265,13 @@ SECTIONS
KEEP(*(gdt_ram_data)) KEEP(*(gdt_ram_data))
#else /* LINKER_PASS2 */ #else /* LINKER_PASS2 */
#ifdef CONFIG_X86_STACK_PROTECTION #ifdef CONFIG_USERSPACE
#ifdef CONFIG_X86_USERSPACE #define GDT_NUM_ENTRIES 7
#define GDT_NUM_ENTRIES 7 #elif defined(CONFIG_HW_STACK_PROTECTION)
#else #define GDT_NUM_ENTRIES 5
#define GDT_NUM_ENTRIES 5 #else
#endif /* CONFIG_X86_USERSPACE */
#else /* CONFIG_X86_STACK_PROTECTION */
#define GDT_NUM_ENTRIES 3 #define GDT_NUM_ENTRIES 3
#endif /* CONFIG_X86_STACK_PROTECTION */ #endif /* CONFIG_X86_USERSPACE */
. += GDT_NUM_ENTRIES * 8; . += GDT_NUM_ENTRIES * 8;
#endif /* LINKER_PASS2 */ #endif /* LINKER_PASS2 */
#endif /* CONFIG_GDT_DYNAMIC */ #endif /* CONFIG_GDT_DYNAMIC */

View file

@ -37,6 +37,7 @@ ACCESS_RW = 1 << 1 # read or write permission
# 6 byte pseudo descriptor, but we're going to actually use this as the # 6 byte pseudo descriptor, but we're going to actually use this as the
# zero descriptor and return 8 bytes # zero descriptor and return 8 bytes
def create_gdt_pseudo_desc(addr, size): def create_gdt_pseudo_desc(addr, size):
debug("create pseudo decriptor: %x %x" % (addr, size))
# ...and take back one byte for the Intel god whose Ark this is... # ...and take back one byte for the Intel god whose Ark this is...
size = size - 1 size = size - 1
return struct.pack(gdt_pd_fmt, size, addr, 0) return struct.pack(gdt_pd_fmt, size, addr, 0)
@ -57,6 +58,9 @@ def chop_base_limit(base, limit):
gdt_ent_fmt = "<HHBBBB" gdt_ent_fmt = "<HHBBBB"
def create_code_data_entry(base, limit, dpl, flags, access): def create_code_data_entry(base, limit, dpl, flags, access):
debug("create code or data entry: %x %x %x %x %x" %
(base, limit, dpl, flags, access))
base_lo, base_mid, base_hi, limit_lo, limit_hi = chop_base_limit(base, base_lo, base_mid, base_hi, limit_lo, limit_hi = chop_base_limit(base,
limit) limit)
@ -82,6 +86,7 @@ def create_code_data_entry(base, limit, dpl, flags, access):
def create_tss_entry(base, limit, dpl): def create_tss_entry(base, limit, dpl):
debug("create TSS entry: %x %x %x" % (base, limit, dpl));
present = 1 present = 1
base_lo, base_mid, base_hi, limit_lo, limit_hi, = chop_base_limit(base, base_lo, base_mid, base_hi, limit_lo, limit_hi, = chop_base_limit(base,
@ -132,17 +137,11 @@ def main():
# code/data segments. If we are doing stack protection, we are going to # code/data segments. If we are doing stack protection, we are going to
# have two TSS to manage the main task and the special task for double # have two TSS to manage the main task and the special task for double
# fault exception handling # fault exception handling
if "CONFIG_USERSPACE" in syms:
if "CONFIG_X86_STACK_PROTECTION" in syms: num_entries = 7
stackprot = True elif "CONFIG_HW_STACK_PROTECTION" in syms:
if "CONFIG_X86_USERSPACE" in syms: num_entries = 5
userspace = True
num_entries = 7
else:
userspace = False
num_entries = 5
else: else:
stackprot = False
num_entries = 3 num_entries = 3
gdt_base = syms["_gdt"] gdt_base = syms["_gdt"]
@ -160,7 +159,7 @@ def main():
fp.write(create_code_data_entry(0, 0xFFFFF, 0, fp.write(create_code_data_entry(0, 0xFFFFF, 0,
FLAGS_GRAN, ACCESS_RW)) FLAGS_GRAN, ACCESS_RW))
if stackprot: if num_entries >= 5:
main_tss = syms["_main_tss"] main_tss = syms["_main_tss"]
df_tss = syms["_df_tss"] df_tss = syms["_df_tss"]
@ -170,14 +169,14 @@ def main():
# Selector 0x20: double-fault TSS # Selector 0x20: double-fault TSS
fp.write(create_tss_entry(df_tss, 0x67, 0)) fp.write(create_tss_entry(df_tss, 0x67, 0))
if userspace: if num_entries == 7:
# Selector 0x28: code descriptor, dpl = 3 # Selector 0x28: code descriptor, dpl = 3
fp.write(create_code_data_entry(0, 0xFFFFF, 3, fp.write(create_code_data_entry(0, 0xFFFFF, 3,
FLAGS_GRAN, ACCESS_EX | ACCESS_RW)) FLAGS_GRAN, ACCESS_EX | ACCESS_RW))
# Selector 0x30: data descriptor, dpl = 3 # Selector 0x30: data descriptor, dpl = 3
fp.write(create_code_data_entry(0, 0xFFFFF, 3, fp.write(create_code_data_entry(0, 0xFFFFF, 3,
FLAGS_GRAN, ACCESS_RW)) FLAGS_GRAN, ACCESS_RW))
if __name__ == "__main__": if __name__ == "__main__":