TODO revision 1.9
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.8Suebayasio Retire "attach foo at bar with foo_bar.c"
481.8Suebayasi
491.8Suebayasi  Most of these should be rewritten by defining a common interface attribute
501.8Suebayasi  "foobus", instead of writing multiple attachments.  com(4), ld(4), ehci(4)
511.8Suebayasi  are typical examples.  For ehci(4), EHCI-capable controller drivers implement
521.8Suebayasi  "ehcibus" interface, like:
531.8Suebayasi
541.8Suebayasi	defne	ehcibus {}
551.8Suebayasi	device	imxehci: ehcibus
561.8Suebayasi
571.8Suebayasi  These drivers' attach functions call config_found() to attach ehci(4) via
581.8Suebayasi  the "ehcibus" interface attribute, instead of calling ehci_init() directly.
591.8Suebayasi  Same for com(4) (com_attach_subr()) and ld(4) (ldattach()).
601.8Suebayasi
611.1Suebayasio Sort objects in more reasonable order.
621.1Suebayasi
631.1Suebayasi  Put machdep.ko in the lowest address.  uvm.ko and kern.ko follow.
641.1Suebayasi
651.1Suebayasi  Kill alphabetical sort (${OBJS:O} in sys/conf/Makefile.inc.kern.
661.1Suebayasi
671.1Suebayasi  Use ldscript.  Do like this
681.1Suebayasi
691.1Suebayasi	.text :
701.1Suebayasi	AT (ADDR(.text) & 0x0fffffff)
711.1Suebayasi	{
721.1Suebayasi	  *(.text.machdep.locore.entry)
731.1Suebayasi	  *(.text.machdep.locore)
741.1Suebayasi	  *(.text.machdep)
751.1Suebayasi	  *(.text)
761.1Suebayasi	  *(.text.*)
771.1Suebayasi	  :
781.1Suebayasi
791.1Suebayasi  Kill linker definitions in sys/conf/Makefile.inc.kern.
801.2Suebayasi
811.3Swizo Differentiate "options" and "flags"/"params".
821.2Suebayasi
831.3Swiz  "options" enables features by adding *.c files (via attributes).
841.2Suebayasi
851.2Suebayasi  "flags" and "params" are to change contents of *.c files.  These don't add
861.3Swiz  *.c files to the result kernel, or don't build attributes (modules).
871.2Suebayasi
881.2Suebayasio Make flags/params per attributes (modules).
891.2Suebayasi
901.2Suebayasi  Basically flags and params are cpp(1) #define's generated in opt_*.h.  Make
911.2Suebayasi  them local to one attributes (modules).  Flags/params which affects files
921.2Suebayasi  across attributes (modules) are possible, but should be discouraged.
931.2Suebayasi
941.2Suebayasio Generate things only by definitions.
951.2Suebayasi
961.2Suebayasi  In the ideal dynamically modular world, "selection" will be done not at
971.2Suebayasi  compile time but at runtime.  Users select their wanted modules, by
981.2Suebayasi  dynamically loading them.
991.2Suebayasi
1001.2Suebayasi  This means that the system provides all choices; that is, build all modules
1011.2Suebayasi  in the source tree.  Necessary information is defined in the "definition"
1021.2Suebayasi  part.
1031.2Suebayasi
1041.2Suebayasio Split cfdata.
1051.2Suebayasi
1061.8Suebayasi  cfdata is a set of pattern matching rules to enable devices at runtime device
1071.3Swiz  auto-configuration.  It is pure data and can (should) be generated separately
1081.2Suebayasi  from the code.
1091.4Sapb
1101.4Sapbo Allow easier adding and removing of options.
1111.4Sapb
1121.4Sapb  It should be possible to add or remove options, flags, etc.,
1131.4Sapb  without regard to whether or not they are already defined.
1141.4Sapb  For example, a configuration like this:
1151.4Sapb
1161.4Sapb	include GENERIC
1171.4Sapb	options FOO
1181.4Sapb	no options BAR
1191.4Sapb
1201.4Sapb  should work regardless of whether or not options FOO and/or
1211.4Sapb  options BAR were defined in GENERIC.  It should not give
1221.4Sapb  errors like "options BAR was already defined" or "options FOO
1231.4Sapb  was not defined".
1241.4Sapb
1251.5Suebayasio Introduce "class".
1261.5Suebayasi
1271.7Swiz  Every module should be classified as at least one class, as modular(9)
1281.7Swiz  modules already do.  For example, file systems are marked as "vfs", network
1291.5Suebayasi  protocols are "netproto".
1301.5Suebayasi
1311.5Suebayasi  Consider to merge "devclass" into "class".
1321.5Suebayasi
1331.5Suebayasi  For syntax clarity, class names could be used as a keyword to select the
1341.5Suebayasi  class's instance module:
1351.5Suebayasi
1361.5Suebayasi	# Define net80211 module as netproto class
1371.5Suebayasi	class netproto
1381.5Suebayasi	define net80211: netproto
1391.5Suebayasi
1401.5Suebayasi	# Select net80211 to be builtin
1411.5Suebayasi	netproto net80211
1421.5Suebayasi
1431.5Suebayasi  Accordingly device/attach selection syntax should be revisited.
1441.5Suebayasi
1451.6Suebayasio Support kernel constructor/destructor (.kctors/.kdtors)
1461.5Suebayasi
1471.5Suebayasi  Initialization and finalization should be called via constructors and
1481.5Suebayasi  destructors.  Don't hardcode those sequences as sys/kern/init_main.c:main()
1491.5Suebayasi  does.
1501.5Suebayasi
1511.6Suebayasi  The order of .kctors/.kdtors is resolved by dependency.  The difference from
1521.5Suebayasi  userland is that in kernel depended ones are located in lower addresses;
1531.5Suebayasi  "machdep" module is the lowest.  Thus the lowest entry in .ctors must be
1541.5Suebayasi  executed the first.
1551.5Suebayasi
1561.6Suebayasi  The .kctors/.kdtors entries are executed by kernel's main() function, unlike
1571.6Suebayasi  userland where start code executes .ctors/.dtors before main().  The hardcoded
1581.6Suebayasi  sequence of various subsystem initializations in init_main.c:main() will be
1591.7Swiz  replaced by an array of .kctors invocations, and #ifdef's there will be gone.
1601.6Suebayasi
1611.5Suebayasio Replace linkset.
1621.5Suebayasi
1631.5Suebayasi  Don't allow kernel subsystems create random ELF sections (with potentially
1641.5Suebayasi  long names) in the final kernel.  To collect some data in statically linked
1651.5Suebayasi  modules, creating intermediate sections (e.g. .data.linkset.sysctl) and
1661.5Suebayasi  exporting the start/end symbols (e.g. _data_linkset_sysctl_{start,end})
1671.5Suebayasi  using linker script should be fine.
1681.5Suebayasi
1691.5Suebayasi  Dynamically loaded modules have to register those entries via constructors
1701.5Suebayasi  (functions).  This means that dynamically loaded modules are flexible but
1711.5Suebayasi  come with overhead.
1721.6Suebayasi
1731.6Suebayasio Shared kernel objects.
1741.6Suebayasi
1751.7Swiz  Since NetBSD has not established a clear kernel ABI, every single kernel
1761.6Suebayasi  has to build all the objects by their own.  As a result, similar kernels
1771.6Suebayasi  (e.g. evbarm kernels) repeatedly compile similar objects, that is waste of
1781.6Suebayasi  energy & space.
1791.6Suebayasi
1801.6Suebayasi  Share them if possible.  For evb* ports, ideally everything except machdep.ko
1811.6Suebayasi  should be shared.
1821.6Suebayasi
1831.6Suebayasi  While leaving optimizations as options (CPU specific optimizations, inlined
1841.6Suebayasi  bus_space(9) operations, etc.) for users, the official binaries build
1851.6Suebayasi  provided by TNF should be as portable as possible.
186