TODO revision 1.18
11.5Suebayasio Call module as module.
21.5Suebayasi
31.5Suebayasi  Until now, everything is called as attribute.  Separate module from it:
41.5Suebayasi
51.5Suebayasi	- Module is a collection of code (*.[cSo]), and provides a function.
61.5Suebayasi	  Module can depend on other modules.
71.5Suebayasi
81.5Suebayasi	- Attribute provides metadata for modules.  One module can have
91.5Suebayasi	  multiple attributes.  Attribute doesn't generate a module (*.o,
101.5Suebayasi	  *.ko).
111.5Suebayasi
121.1Suebayasio Emit everything (ioconf.*, Makefile, ...) per-attribute.
131.1Suebayasi
141.9Suebayasi  config(9) related metadata (cfdriver, cfattach, cfdata, ...) should be
151.9Suebayasi  collected using linker.  Create ELF sections like
161.9Suebayasi  .{rodata,data}.config.{cfdriver,cfattach,cfdata}.  Provide reference
171.9Suebayasi  symbols (e.g. cfdriverinit[]) using linker script.  Sort entries by name
181.9Suebayasi  to lookup entries by binary search in kernel.
191.9Suebayasi
201.1Suebayasio Generate modular(9) related information.  Especially module dependency.
211.1Suebayasi
221.9Suebayasi  At this moment modular(9) modules hardcode dependency in *.c using the
231.9Suebayasi  MODULE() macro:
241.9Suebayasi
251.9Suebayasi	MODULE(MODULE_CLASS_DRIVER, hdaudio, "pci");
261.9Suebayasi
271.9Suebayasi  This information already exists in config(5) definitions (files.*).
281.9Suebayasi  Extend config(5) to be able to specify module's class.
291.9Suebayasi
301.9Suebayasi  Ideally these module metadata are kept somewhere in ELF headers, so that
311.9Suebayasi  loaders (e.g. boot(8)) can easily read.  One idea is to abuse DYNAMIC
321.9Suebayasi  sections to record dependency, as shared library does.  (Feasibility
331.9Suebayasi  unknown.)
341.9Suebayasi
351.1Suebayasio Rename "interface attribute" to "bus".
361.1Suebayasi
371.1Suebayasi  Instead of
381.1Suebayasi
391.1Suebayasi	define	audiobus {}
401.1Suebayasi	attach	audio at audiobus
411.1Suebayasi
421.1Suebayasi  Do like this
431.1Suebayasi
441.1Suebayasi	defbus	audiobus {}
451.1Suebayasi	attach	audio at audiobus
461.1Suebayasi
471.15Suebayasi  Always provide xxxbusprint() (and xxxbussubmatch if multiple children).
481.15Suebayasi  Extend struct cfiattrdata like:
491.15Suebayasi
501.15Suebayasi	struct cfiattrdata {
511.15Suebayasi		const char *ci_name;
521.15Suebayasi		cfprint_t ci_print;
531.15Suebayasi		cfsubmatch_t ci_submatch;
541.15Suebayasi		int ci_loclen;
551.15Suebayasi		const struct cflocdesc ci_locdesc[];
561.15Suebayasi	};
571.15Suebayasi
581.15Suebayasio Simplify child configuration API
591.15Suebayasi
601.15Suebayasi  With said struct cfiattrdata extension, config_found*() can omit
611.15Suebayasi  print/submatch args.  If the found child is known (e.g., "pcibus" creating
621.15Suebayasi  "pci"):
631.15Suebayasi
641.16Suebayasi	config_found(self, "pcibus");
651.15Suebayasi
661.15Suebayasi  If finding unknown children (e.g. "pci" finding pci devices):
671.15Suebayasi
681.15Suebayasi	config_find(self, "pci", locs, aux);
691.15Suebayasi
701.8Suebayasio Retire "attach foo at bar with foo_bar.c"
711.8Suebayasi
721.8Suebayasi  Most of these should be rewritten by defining a common interface attribute
731.8Suebayasi  "foobus", instead of writing multiple attachments.  com(4), ld(4), ehci(4)
741.8Suebayasi  are typical examples.  For ehci(4), EHCI-capable controller drivers implement
751.8Suebayasi  "ehcibus" interface, like:
761.8Suebayasi
771.8Suebayasi	defne	ehcibus {}
781.8Suebayasi	device	imxehci: ehcibus
791.8Suebayasi
801.8Suebayasi  These drivers' attach functions call config_found() to attach ehci(4) via
811.8Suebayasi  the "ehcibus" interface attribute, instead of calling ehci_init() directly.
821.8Suebayasi  Same for com(4) (com_attach_subr()) and ld(4) (ldattach()).
831.8Suebayasi
841.1Suebayasio Sort objects in more reasonable order.
851.1Suebayasi
861.1Suebayasi  Put machdep.ko in the lowest address.  uvm.ko and kern.ko follow.
871.1Suebayasi
881.1Suebayasi  Kill alphabetical sort (${OBJS:O} in sys/conf/Makefile.inc.kern.
891.1Suebayasi
901.1Suebayasi  Use ldscript.  Do like this
911.1Suebayasi
921.1Suebayasi	.text :
931.1Suebayasi	AT (ADDR(.text) & 0x0fffffff)
941.1Suebayasi	{
951.1Suebayasi	  *(.text.machdep.locore.entry)
961.1Suebayasi	  *(.text.machdep.locore)
971.1Suebayasi	  *(.text.machdep)
981.1Suebayasi	  *(.text)
991.1Suebayasi	  *(.text.*)
1001.1Suebayasi	  :
1011.1Suebayasi
1021.1Suebayasi  Kill linker definitions in sys/conf/Makefile.inc.kern.
1031.2Suebayasi
1041.3Swizo Differentiate "options" and "flags"/"params".
1051.2Suebayasi
1061.3Swiz  "options" enables features by adding *.c files (via attributes).
1071.2Suebayasi
1081.2Suebayasi  "flags" and "params" are to change contents of *.c files.  These don't add
1091.3Swiz  *.c files to the result kernel, or don't build attributes (modules).
1101.2Suebayasi
1111.2Suebayasio Make flags/params per attributes (modules).
1121.2Suebayasi
1131.2Suebayasi  Basically flags and params are cpp(1) #define's generated in opt_*.h.  Make
1141.2Suebayasi  them local to one attributes (modules).  Flags/params which affects files
1151.2Suebayasi  across attributes (modules) are possible, but should be discouraged.
1161.2Suebayasi
1171.2Suebayasio Generate things only by definitions.
1181.2Suebayasi
1191.2Suebayasi  In the ideal dynamically modular world, "selection" will be done not at
1201.2Suebayasi  compile time but at runtime.  Users select their wanted modules, by
1211.2Suebayasi  dynamically loading them.
1221.2Suebayasi
1231.2Suebayasi  This means that the system provides all choices; that is, build all modules
1241.2Suebayasi  in the source tree.  Necessary information is defined in the "definition"
1251.2Suebayasi  part.
1261.2Suebayasi
1271.2Suebayasio Split cfdata.
1281.2Suebayasi
1291.8Suebayasi  cfdata is a set of pattern matching rules to enable devices at runtime device
1301.3Swiz  auto-configuration.  It is pure data and can (should) be generated separately
1311.2Suebayasi  from the code.
1321.4Sapb
1331.4Sapbo Allow easier adding and removing of options.
1341.4Sapb
1351.4Sapb  It should be possible to add or remove options, flags, etc.,
1361.4Sapb  without regard to whether or not they are already defined.
1371.4Sapb  For example, a configuration like this:
1381.4Sapb
1391.4Sapb	include GENERIC
1401.4Sapb	options FOO
1411.4Sapb	no options BAR
1421.4Sapb
1431.4Sapb  should work regardless of whether or not options FOO and/or
1441.4Sapb  options BAR were defined in GENERIC.  It should not give
1451.4Sapb  errors like "options BAR was already defined" or "options FOO
1461.4Sapb  was not defined".
1471.4Sapb
1481.5Suebayasio Introduce "class".
1491.5Suebayasi
1501.7Swiz  Every module should be classified as at least one class, as modular(9)
1511.7Swiz  modules already do.  For example, file systems are marked as "vfs", network
1521.5Suebayasi  protocols are "netproto".
1531.5Suebayasi
1541.5Suebayasi  Consider to merge "devclass" into "class".
1551.5Suebayasi
1561.5Suebayasi  For syntax clarity, class names could be used as a keyword to select the
1571.5Suebayasi  class's instance module:
1581.5Suebayasi
1591.5Suebayasi	# Define net80211 module as netproto class
1601.5Suebayasi	class netproto
1611.5Suebayasi	define net80211: netproto
1621.5Suebayasi
1631.5Suebayasi	# Select net80211 to be builtin
1641.5Suebayasi	netproto net80211
1651.5Suebayasi
1661.5Suebayasi  Accordingly device/attach selection syntax should be revisited.
1671.5Suebayasi
1681.6Suebayasio Support kernel constructor/destructor (.kctors/.kdtors)
1691.5Suebayasi
1701.5Suebayasi  Initialization and finalization should be called via constructors and
1711.5Suebayasi  destructors.  Don't hardcode those sequences as sys/kern/init_main.c:main()
1721.5Suebayasi  does.
1731.5Suebayasi
1741.6Suebayasi  The order of .kctors/.kdtors is resolved by dependency.  The difference from
1751.5Suebayasi  userland is that in kernel depended ones are located in lower addresses;
1761.5Suebayasi  "machdep" module is the lowest.  Thus the lowest entry in .ctors must be
1771.5Suebayasi  executed the first.
1781.5Suebayasi
1791.6Suebayasi  The .kctors/.kdtors entries are executed by kernel's main() function, unlike
1801.6Suebayasi  userland where start code executes .ctors/.dtors before main().  The hardcoded
1811.6Suebayasi  sequence of various subsystem initializations in init_main.c:main() will be
1821.7Swiz  replaced by an array of .kctors invocations, and #ifdef's there will be gone.
1831.6Suebayasi
1841.12Suebayasio Hide link-set in the final kernel.
1851.5Suebayasi
1861.12Suebayasi  Link-set is used to collect references (pointers) at link time.  It relys on
1871.12Suebayasi  the ld(1) behavior that it automatically generates `__start_X' and `__stop_X'
1881.12Suebayasi  symbols for the section `X' to reduce coding.
1891.12Suebayasi
1901.12Suebayasi  Don't allow kernel subsystems create random ELF sections.
1911.12Suebayasi
1921.12Suebayasi  Pre-define all the available link-set names and pre-generate a linker script
1931.12Suebayasi  to merge them into .rodata.
1941.12Suebayasi
1951.12Suebayasi  (For modular(9) modules, `link_set_modules' is looked up by kernel loader.
1961.12Suebayasi  Provide only it.)
1971.12Suebayasi
1981.12Suebayasi  Provide a way for 3rd party modules to declare extra link-set.
1991.6Suebayasi
2001.6Suebayasio Shared kernel objects.
2011.6Suebayasi
2021.7Swiz  Since NetBSD has not established a clear kernel ABI, every single kernel
2031.6Suebayasi  has to build all the objects by their own.  As a result, similar kernels
2041.6Suebayasi  (e.g. evbarm kernels) repeatedly compile similar objects, that is waste of
2051.6Suebayasi  energy & space.
2061.6Suebayasi
2071.6Suebayasi  Share them if possible.  For evb* ports, ideally everything except machdep.ko
2081.6Suebayasi  should be shared.
2091.6Suebayasi
2101.6Suebayasi  While leaving optimizations as options (CPU specific optimizations, inlined
2111.6Suebayasi  bus_space(9) operations, etc.) for users, the official binaries build
2121.6Suebayasi  provided by TNF should be as portable as possible.
2131.10Suebayasi
2141.10Suebayasio Control ELF sections using linker script.
2151.10Suebayasi
2161.10Suebayasi  Now kernel is linked and built directly from object files (*.o).  Each port
2171.10Suebayasi  has an MD linker script, which does everything needed to be done at link
2181.10Suebayasi  time.  As a result, they do from MI alignment restriction (read_mostly,
2191.10Suebayasi  cacheline_aligned) to load address specification for external boot loaders.
2201.10Suebayasi
2211.10Suebayasi  Make this into multiple stages to make linkage more structural.  Especially,
2221.11Suebayasi  reserve the final link for purely MD purpose.  Note that in modular build,
2231.11Suebayasi  *.ko are shared between build of kernel and modular(9) modules (*.kmod).
2241.10Suebayasi
2251.10Suebayasi	Monolithic build:
2261.10Suebayasi		     *.o  ---> netbsd.ko	Generic MI linkage
2271.10Suebayasi		netbsd.ko ---> netbsd.ro	Kernel MI linkage
2281.10Suebayasi		netbsd.ro ---> netbsd		Kernel MD linkage
2291.10Suebayasi
2301.10Suebayasi	Modular build (kernel):
2311.10Suebayasi		     *.o  --->      *.ko	Generic + Per-module MI linkage
2321.10Suebayasi		     *.ko ---> netbsd.ro	Kernel MI linkage
2331.10Suebayasi		netbsd.ro ---> netbsd		Kernel MD linkage
2341.10Suebayasi
2351.10Suebayasi	Modular build (module):
2361.10Suebayasi		     *.o  --->      *.ko	Generic + Per-module MI linkage
2371.10Suebayasi		     *.ko --->      *.ro	Modular MI linkage
2381.10Suebayasi		     *.ro --->      *.kmod	Modular MD linkage
2391.10Suebayasi
2401.10Suebayasi  Genric MI linkage is for processing MI linkage that can be applied generally.
2411.10Suebayasi  Data section alignment (.data.read_mostly and .data.cacheline_aligned) is
2421.10Suebayasi  processed here.
2431.10Suebayasi
2441.10Suebayasi  Per-module MI linkage is for modules that want some ordering.  For example,
2451.10Suebayasi  machdep.ko wants to put entry code at the top of .text and .data.
2461.10Suebayasi
2471.10Suebayasi  Kernel MI linkage is for collecting kernel global section data, that is what
2481.10Suebayasi  link-set is used for now.  Once they are collected and symbols to the ranges
2491.10Suebayasi  are assigned, those sections are merged into the pre-existing sections
2501.10Suebayasi  (.rodata) because link-set sections in "netbsd" will never be interpreted by
2511.10Suebayasi  external loaders.
2521.10Suebayasi
2531.10Suebayasi  Kernel MD linkage is used purely for MD purposes, that is, how kernels are
2541.10Suebayasi  loaded by external loaders.  It might be possible that one kernel relocatable
2551.10Suebayasi  (netbsd.ro) is linked into multiple final kernel image (netbsd) for diferent
2561.10Suebayasi  load addresses.
2571.10Suebayasi
2581.11Suebayasi  Modular MI linkage is to prepare a module to be loadable as modular(9).  This
2591.11Suebayasi  may add some extra sections and/or symbols.
2601.11Suebayasi
2611.11Suebayasi  Modular MD linkage is again for pure MD purposes like kernel MD linkage.
2621.11Suebayasi  Adjustment and/or optimization may be done.
2631.11Suebayasi
2641.11Suebayasi  Kernel and modular MI linkages may change behavior depending on existence
2651.11Suebayasi  of debug information.  In the future .symtab will be copied using linker
2661.11Suebayasi  during this stage.
2671.13Suebayasi
2681.13Suebayasio Redesign swapnetbsd.c (root/swap device specification)
2691.13Suebayasi
2701.13Suebayasi  Don't build a whole kernel only to specify root/swap devices.
2711.13Suebayasi
2721.13Suebayasi  Make these parameter re-configurable afterwards.
2731.14Suebayasi
2741.14Suebayasio Namespace.
2751.14Suebayasi
2761.14Suebayasi  Investigate namespace of attributes/modules/options.  Figure out the hidden
2771.14Suebayasi  design about these, document it, then re-design it.
2781.14Suebayasi
2791.14Suebayasi  At this moment, all of them share the single "selecttab", which means their
2801.14Suebayasi  namespaces are common, but they also have respective tables (attrtab,
2811.14Suebayasi  opttab, etc.).
2821.14Suebayasi
2831.14Suebayasi  Selecting an option (addoption()), that is also a module name, works only if
2841.14Suebayasi  the module doesn't depend on anything, because addoption() doesn't select
2851.14Suebayasi  module and its dependencies (selectattr()).  In other words, an option is
2861.14Suebayasi  only safely converted to a module (define), only if it doesn't depend on
2871.14Suebayasi  anything.  (One example is DDB.)
2881.17Suebayasi
2891.17Suebayasio Convert pseudo(dev) attach functions to take (void) (== kernel ctors).
2901.17Suebayasi
2911.17Suebayasi  The pseudo attach function was originally designed to take `int n' as
2921.17Suebayasi  the number of instances of the pseudo device.  Now most of pseudo
2931.17Suebayasi  devices have been converted to be `cloneable', meaning that their
2941.17Suebayasi  instances are dynamically allocated at run-time, because guessing how
2951.17Suebayasi  much instances are needed for users at compile time is almost impossible.
2961.17Suebayasi  Restricting such a pure software resource at compile time is senseless,
2971.17Suebayasi  considering that the rest of the world is dynamic.
2981.17Suebayasi
2991.17Suebayasi  If pseudo attach functions once become (void), config(1) no longer
3001.17Suebayasi  has to generate iteration to call those functions, by making them part
3011.17Suebayasi  of kernel constructors, that are a list of (void) functions.
3021.17Suebayasi
3031.17Suebayasi  Some pseudo devices may have dependency/ordering problems, because
3041.17Suebayasi  pseudo attach functions have no choice when to be called.  This could
3051.17Suebayasi  be solved by converting to kctors, where functions are called in order
3061.17Suebayasi  by dependency.
3071.18Spgoyette
3081.18Spgoyetteo Enhance ioconf behavior for pseudo-devices
3091.18Spgoyette
3101.18Spgoyette  See "bin/48571: config(1) ioconf is insufficient for pseudo-devices" for
3111.18Spgoyette  more details.  In a nutshell, it would be "useful" for config to emit
3121.18Spgoyette  the necessary stuff in the generated ioconf.[ch] to enable use of
3131.18Spgoyette  config_{init,fini}_component() for attaching and detaching pseudodev's.
3141.18Spgoyette
3151.18Spgoyette  Currently, you need to manually construct your own data structures, and
3161.18Spgoyette  manually "attach" them, one at a time.  This leads to duplication of
3171.18Spgoyette  code (where multiple drivers contain the same basic logic), and doesn't
3181.18Spgoyette  necessarily handle all of the "frobbing" of the kernel lists.
319