From owner-freebsd-chat Fri Jun 22 14: 3:34 2001 Delivered-To: freebsd-chat@freebsd.org Received: from smtp04.primenet.com (smtp04.primenet.com [64.211.219.53]) by hub.freebsd.org (Postfix) with ESMTP id BE94837B401 for ; Fri, 22 Jun 2001 14:03:25 -0700 (PDT) (envelope-from tlambert@usr06.primenet.com) Received: (from daemon@localhost) by smtp04.primenet.com (8.9.3/8.9.3) id OAA08707; Fri, 22 Jun 2001 14:03:22 -0700 (MST) Received: from usr06.primenet.com(206.165.6.206) via SMTP by smtp04.primenet.com, id smtpdAAAT_a48q; Fri Jun 22 14:03:19 2001 Received: (from tlambert@localhost) by usr06.primenet.com (8.8.5/8.8.5) id OAA28366; Fri, 22 Jun 2001 14:07:24 -0700 (MST) From: Terry Lambert Message-Id: <200106222107.OAA28366@usr06.primenet.com> Subject: Re: most complex code in BSD? To: jcm@FreeBSD-uk.eu.org (j mckitrick) Date: Fri, 22 Jun 2001 21:06:59 +0000 (GMT) Cc: freebsd-chat@FreeBSD.ORG In-Reply-To: <20010621233210.A37804@dogma.freebsd-uk.eu.org> from "j mckitrick" at Jun 21, 2001 11:32:10 PM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > 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