Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jun 2001 21:06:59 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        jcm@FreeBSD-uk.eu.org (j mckitrick)
Cc:        freebsd-chat@FreeBSD.ORG
Subject:   Re: most complex code in BSD?
Message-ID:  <200106222107.OAA28366@usr06.primenet.com>
In-Reply-To: <20010621233210.A37804@dogma.freebsd-uk.eu.org> from "j mckitrick" at Jun 21, 2001 11:32:10 PM

next in thread | previous in thread | raw e-mail | index | archive | help
> In everyone's opinion, what is the most complex code in the BSD codebase?
> Not including asm (unless there is an especialy exemplary example of
> obfuscated code, but it seems compilers are better at that  ;-) what code is
> most likely to turn a newbie's brain to tapioca?

A good candidate for "most magic numbers" is /sys/i386/include/pmap.h:

-----------------------------------------------------------------------------
#ifndef NKPT
#define NKPT                    30      /* actual number of kernel page tables *
/ 
#endif
#ifndef NKPDE
#ifdef SMP
#define NKPDE                   254     /* addressable number of page tables/pde
's */
#else
#define NKPDE                   255     /* addressable number of page tables/pde
's */
#endif  /* SMP */
#endif

/*
 * The *PTDI values control the layout of virtual memory
 *
 * XXX This works for now, but I am not real happy with it, I'll fix it
 * right after I fix locore.s and the magic 28K hole
 *
 * SMP_PRIVPAGES: The per-cpu address space is 0xff80000 -> 0xffbfffff
 */
#define APTDPTDI        (NPDEPG-1)      /* alt ptd entry that points to APTD */
#ifdef SMP
#define MPPTDI          (APTDPTDI-1)    /* per cpu ptd entry */
#define KPTDI           (MPPTDI-NKPDE)  /* start of kernel virtual pde's */
#else
#define KPTDI           (APTDPTDI-NKPDE)/* start of kernel virtual pde's */
#endif  /* SMP */
#define PTDPTDI         (KPTDI-1)       /* ptd entry that points to ptd! */
#define UMAXPTDI        (PTDPTDI-1)     /* ptd entry for user space end */
#define UMAXPTEOFF      (NPTEPG)        /* pte entry for user space end */
-----------------------------------------------------------------------------

A good runner up for code would be in /sys/i386/i386/machdep.c:

-----------------------------------------------------------------------------
static void
f00f_hack(void *unused) {
        struct gate_descriptor *new_idt;
#ifndef SMP
        struct region_descriptor r_idt;
#endif
        vm_offset_t tmp;

        if (!has_f00f_bug)
                return;
        
        printf("Intel Pentium detected, installing workaround for F00F bug\n");
        
        r_idt.rd_limit = sizeof(idt0) - 1;
        
        tmp = kmem_alloc(kernel_map, PAGE_SIZE * 2);
        if (tmp == 0)
                panic("kmem_alloc returned 0");
        if (((unsigned int)tmp & (PAGE_SIZE-1)) != 0)
                panic("kmem_alloc returned non-page-aligned memory");
        /* Put the first seven entries in the lower page */
        new_idt = (struct gate_descriptor*)(tmp + PAGE_SIZE - (7*8));  
        bcopy(idt, new_idt, sizeof(idt0));
        r_idt.rd_base = (int)new_idt;
        lidt(&r_idt);
        idt = new_idt;
        if (vm_map_protect(kernel_map, tmp, tmp + PAGE_SIZE,
                           VM_PROT_READ, FALSE) != KERN_SUCCESS)
                panic("vm_map_protect failed");
        return;
}
-----------------------------------------------------------------------------

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106222107.OAA28366>