TODO revision 1.14
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.12Suebayasio Hide link-set in the final kernel.
1621.5Suebayasi
1631.12Suebayasi  Link-set is used to collect references (pointers) at link time.  It relys on
1641.12Suebayasi  the ld(1) behavior that it automatically generates `__start_X' and `__stop_X'
1651.12Suebayasi  symbols for the section `X' to reduce coding.
1661.12Suebayasi
1671.12Suebayasi  Don't allow kernel subsystems create random ELF sections.
1681.12Suebayasi
1691.12Suebayasi  Pre-define all the available link-set names and pre-generate a linker script
1701.12Suebayasi  to merge them into .rodata.
1711.12Suebayasi
1721.12Suebayasi  (For modular(9) modules, `link_set_modules' is looked up by kernel loader.
1731.12Suebayasi  Provide only it.)
1741.12Suebayasi
1751.12Suebayasi  Provide a way for 3rd party modules to declare extra link-set.
1761.6Suebayasi
1771.6Suebayasio Shared kernel objects.
1781.6Suebayasi
1791.7Swiz  Since NetBSD has not established a clear kernel ABI, every single kernel
1801.6Suebayasi  has to build all the objects by their own.  As a result, similar kernels
1811.6Suebayasi  (e.g. evbarm kernels) repeatedly compile similar objects, that is waste of
1821.6Suebayasi  energy & space.
1831.6Suebayasi
1841.6Suebayasi  Share them if possible.  For evb* ports, ideally everything except machdep.ko
1851.6Suebayasi  should be shared.
1861.6Suebayasi
1871.6Suebayasi  While leaving optimizations as options (CPU specific optimizations, inlined
1881.6Suebayasi  bus_space(9) operations, etc.) for users, the official binaries build
1891.6Suebayasi  provided by TNF should be as portable as possible.
1901.10Suebayasi
1911.10Suebayasio Control ELF sections using linker script.
1921.10Suebayasi
1931.10Suebayasi  Now kernel is linked and built directly from object files (*.o).  Each port
1941.10Suebayasi  has an MD linker script, which does everything needed to be done at link
1951.10Suebayasi  time.  As a result, they do from MI alignment restriction (read_mostly,
1961.10Suebayasi  cacheline_aligned) to load address specification for external boot loaders.
1971.10Suebayasi
1981.10Suebayasi  Make this into multiple stages to make linkage more structural.  Especially,
1991.11Suebayasi  reserve the final link for purely MD purpose.  Note that in modular build,
2001.11Suebayasi  *.ko are shared between build of kernel and modular(9) modules (*.kmod).
2011.10Suebayasi
2021.10Suebayasi	Monolithic build:
2031.10Suebayasi		     *.o  ---> netbsd.ko	Generic MI linkage
2041.10Suebayasi		netbsd.ko ---> netbsd.ro	Kernel MI linkage
2051.10Suebayasi		netbsd.ro ---> netbsd		Kernel MD linkage
2061.10Suebayasi
2071.10Suebayasi	Modular build (kernel):
2081.10Suebayasi		     *.o  --->      *.ko	Generic + Per-module MI linkage
2091.10Suebayasi		     *.ko ---> netbsd.ro	Kernel MI linkage
2101.10Suebayasi		netbsd.ro ---> netbsd		Kernel MD linkage
2111.10Suebayasi
2121.10Suebayasi	Modular build (module):
2131.10Suebayasi		     *.o  --->      *.ko	Generic + Per-module MI linkage
2141.10Suebayasi		     *.ko --->      *.ro	Modular MI linkage
2151.10Suebayasi		     *.ro --->      *.kmod	Modular MD linkage
2161.10Suebayasi
2171.10Suebayasi  Genric MI linkage is for processing MI linkage that can be applied generally.
2181.10Suebayasi  Data section alignment (.data.read_mostly and .data.cacheline_aligned) is
2191.10Suebayasi  processed here.
2201.10Suebayasi
2211.10Suebayasi  Per-module MI linkage is for modules that want some ordering.  For example,
2221.10Suebayasi  machdep.ko wants to put entry code at the top of .text and .data.
2231.10Suebayasi
2241.10Suebayasi  Kernel MI linkage is for collecting kernel global section data, that is what
2251.10Suebayasi  link-set is used for now.  Once they are collected and symbols to the ranges
2261.10Suebayasi  are assigned, those sections are merged into the pre-existing sections
2271.10Suebayasi  (.rodata) because link-set sections in "netbsd" will never be interpreted by
2281.10Suebayasi  external loaders.
2291.10Suebayasi
2301.10Suebayasi  Kernel MD linkage is used purely for MD purposes, that is, how kernels are
2311.10Suebayasi  loaded by external loaders.  It might be possible that one kernel relocatable
2321.10Suebayasi  (netbsd.ro) is linked into multiple final kernel image (netbsd) for diferent
2331.10Suebayasi  load addresses.
2341.10Suebayasi
2351.11Suebayasi  Modular MI linkage is to prepare a module to be loadable as modular(9).  This
2361.11Suebayasi  may add some extra sections and/or symbols.
2371.11Suebayasi
2381.11Suebayasi  Modular MD linkage is again for pure MD purposes like kernel MD linkage.
2391.11Suebayasi  Adjustment and/or optimization may be done.
2401.11Suebayasi
2411.11Suebayasi  Kernel and modular MI linkages may change behavior depending on existence
2421.11Suebayasi  of debug information.  In the future .symtab will be copied using linker
2431.11Suebayasi  during this stage.
2441.13Suebayasi
2451.13Suebayasio Redesign swapnetbsd.c (root/swap device specification)
2461.13Suebayasi
2471.13Suebayasi  Don't build a whole kernel only to specify root/swap devices.
2481.13Suebayasi
2491.13Suebayasi  Make these parameter re-configurable afterwards.
2501.14Suebayasi
2511.14Suebayasio Namespace.
2521.14Suebayasi
2531.14Suebayasi  Investigate namespace of attributes/modules/options.  Figure out the hidden
2541.14Suebayasi  design about these, document it, then re-design it.
2551.14Suebayasi
2561.14Suebayasi  At this moment, all of them share the single "selecttab", which means their
2571.14Suebayasi  namespaces are common, but they also have respective tables (attrtab,
2581.14Suebayasi  opttab, etc.).
2591.14Suebayasi
2601.14Suebayasi  Selecting an option (addoption()), that is also a module name, works only if
2611.14Suebayasi  the module doesn't depend on anything, because addoption() doesn't select
2621.14Suebayasi  module and its dependencies (selectattr()).  In other words, an option is
2631.14Suebayasi  only safely converted to a module (define), only if it doesn't depend on
2641.14Suebayasi  anything.  (One example is DDB.)
265