if (x86)
// do ...
else (Power) // do ...
else (PPC) // do ...> Every effort is made to keep everything cleanly split into 'Machine Dependent' (MD) and 'Machine Independent' (MI) areas. For example, an Ethernet chipset would have a single MI core hardware driver, which would be matched with appropriate MD bus attachment code for a given platform. Not all drivers are as clean as we would like for historical reasons, but any new driver will be, and old drivers are in the process of being converted across.
Machine dependent parts are built to a hardware abstraction layer (HAL)[1] interface, so that spec gives a single abstraction that the hardware-dependant code is built against, and can operate w/ the rest of the OS. As I understand it, this is facilitated by the _build system_ (not a mess of if/then in code) like this[2]:
.if ${ARCHSUBDIR} == "mips64"
ARCHSUBDIR= mips
.endif
.if ${ARCHSUBDIR} == "powerpc64"
ARCHSUBDIR= powerpc
.endif
These are also the sorts of problems that are addressed by considering "lots and lots" of targets -- it'd be unmaintainable otherwise.[1]: http://en.wikipedia.org/wiki/NetBSD#Portability
[2]: /usr/src/sys/arch/Makefile
EDIT: ws
s/it's be/it'd be/
s/that spec give/that spec gives/
- then found the existing powerpc pmap (physical memory management) code wasn't very SMP friendly
- also found the PS3 hypervisor layer isn't thread-safe
These are some of the reasons that I care about NetBSD (which runs on some 56 architectures with its single codebase) so much -- the real-world work supporting real-world architectures can pay off everywhere -- it's not just academic work or nostalgia/eccentricity.