Commit a705eae3 authored by Andrew Boie's avatar Andrew Boie Committed by Andrew Boie
Browse files

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: default avatarAndrew Boie <andrew.p.boie@intel.com>
parent 3a0b1b43
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -265,16 +265,13 @@ SECTIONS
	KEEP(*(gdt_ram_data))
#else /* LINKER_PASS2 */

#ifdef CONFIG_X86_STACK_PROTECTION
    #ifdef CONFIG_X86_USERSPACE
#ifdef CONFIG_USERSPACE
    #define GDT_NUM_ENTRIES 7
    #else
#elif defined(CONFIG_HW_STACK_PROTECTION)
    #define GDT_NUM_ENTRIES 5
    #endif /* CONFIG_X86_USERSPACE */
#else /* CONFIG_X86_STACK_PROTECTION */
#else
    #define GDT_NUM_ENTRIES 3
#endif /* CONFIG_X86_STACK_PROTECTION */

#endif /* CONFIG_X86_USERSPACE */
	. += GDT_NUM_ENTRIES * 8;
#endif /* LINKER_PASS2 */
#endif /* CONFIG_GDT_DYNAMIC */
+17 −18
Original line number Diff line number Diff line
@@ -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
# zero descriptor and return 8 bytes
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...
    size = size - 1
    return struct.pack(gdt_pd_fmt, size, addr, 0)
@@ -57,6 +58,9 @@ def chop_base_limit(base, limit):
gdt_ent_fmt = "<HHBBBB"

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,
            limit)

@@ -82,6 +86,7 @@ def create_code_data_entry(base, limit, dpl, flags, access):


def create_tss_entry(base, limit, dpl):
    debug("create TSS entry: %x %x %x" % (base, limit, dpl));
    present = 1

    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
    # have two TSS to manage the main task and the special task for double
    # fault exception handling

    if "CONFIG_X86_STACK_PROTECTION" in syms:
        stackprot = True
        if "CONFIG_X86_USERSPACE" in syms:
            userspace = True
    if "CONFIG_USERSPACE" in syms:
        num_entries = 7
        else:
            userspace = False
    elif "CONFIG_HW_STACK_PROTECTION" in syms:
        num_entries = 5
    else:
        stackprot = False
        num_entries = 3

    gdt_base = syms["_gdt"]
@@ -160,7 +159,7 @@ def main():
        fp.write(create_code_data_entry(0, 0xFFFFF, 0,
                 FLAGS_GRAN, ACCESS_RW))

        if stackprot:
        if num_entries >= 5:
            main_tss = syms["_main_tss"]
            df_tss = syms["_df_tss"]

@@ -170,7 +169,7 @@ def main():
            # Selector 0x20: double-fault TSS
            fp.write(create_tss_entry(df_tss, 0x67, 0))

            if userspace:
        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))