Home | History | Annotate | Line # | Download | only in config
TODO revision 1.23
      1 o Call module as module.
      2 
      3   Until now, everything is called as attribute.  Separate module from it:
      4 
      5 	- Module is a collection of code (*.[cSo]), and provides a function.
      6 	  Module can depend on other modules.
      7 
      8 	- Attribute provides metadata for modules.  One module can have
      9 	  multiple attributes.  Attribute doesn't generate a module (*.o,
     10 	  *.ko).
     11 
     12 o Emit everything (ioconf.*, Makefile, ...) per-attribute.
     13 
     14   config(9) related metadata (cfdriver, cfattach, cfdata, ...) should be
     15   collected using linker.  Create ELF sections like
     16   .{rodata,data}.config.{cfdriver,cfattach,cfdata}.  Provide reference
     17   symbols (e.g. cfdriverinit[]) using linker script.  Sort entries by name
     18   to lookup entries by binary search in kernel.
     19 
     20 o Generate modular(9) related information.  Especially module dependency.
     21 
     22   At this moment modular(9) modules hardcode dependency in *.c using the
     23   MODULE() macro:
     24 
     25 	MODULE(MODULE_CLASS_DRIVER, hdaudio, "pci");
     26 
     27   This information already exists in config(5) definitions (files.*).
     28   Extend config(5) to be able to specify module's class.
     29 
     30   Ideally these module metadata are kept somewhere in ELF headers, so that
     31   loaders (e.g. boot(8)) can easily read.  One idea is to abuse DYNAMIC
     32   sections to record dependency, as shared library does.  (Feasibility
     33   unknown.)
     34 
     35 o Rename "interface attribute" to "bus".
     36 
     37   Instead of
     38 
     39 	define	audiobus {}
     40 	attach	audio at audiobus
     41 
     42   Do like this
     43 
     44 	defbus	audiobus {}
     45 	attach	audio at audiobus
     46 
     47   Always provide xxxbusprint() (and xxxbussubmatch if multiple children).
     48   Extend struct cfiattrdata like:
     49 
     50 	struct cfiattrdata {
     51 		const char *ci_name;
     52 		cfprint_t ci_print;
     53 		cfsubmatch_t ci_submatch;
     54 		int ci_loclen;
     55 		const struct cflocdesc ci_locdesc[];
     56 	};
     57 
     58 o Simplify child configuration API
     59 
     60   With said struct cfiattrdata extension, config_found*() can omit
     61   print/submatch args.  If the found child is known (e.g., "pcibus" creating
     62   "pci"):
     63 
     64 	config_found(self, "pcibus");
     65 
     66   If finding unknown children (e.g. "pci" finding pci devices):
     67 
     68 	config_find(self, "pci", locs, aux);
     69 
     70 o Retire "attach foo at bar with foo_bar.c"
     71 
     72   Most of these should be rewritten by defining a common interface attribute
     73   "foobus", instead of writing multiple attachments.  com(4), ld(4), ehci(4)
     74   are typical examples.  For ehci(4), EHCI-capable controller drivers implement
     75   "ehcibus" interface, like:
     76 
     77 	defne	ehcibus {}
     78 	device	imxehci: ehcibus
     79 
     80   These drivers' attach functions call config_found() to attach ehci(4) via
     81   the "ehcibus" interface attribute, instead of calling ehci_init() directly.
     82   Same for com(4) (com_attach_subr()) and ld(4) (ldattach()).
     83 
     84 o Sort objects in more reasonable order.
     85 
     86   Put machdep.ko in the lowest address.  uvm.ko and kern.ko follow.
     87 
     88   Kill alphabetical sort (${OBJS:O} in sys/conf/Makefile.inc.kern.
     89 
     90   Use ldscript.  Do like this
     91 
     92 	.text :
     93 	AT (ADDR(.text) & 0x0fffffff)
     94 	{
     95 	  *(.text.machdep.locore.entry)
     96 	  *(.text.machdep.locore)
     97 	  *(.text.machdep)
     98 	  *(.text)
     99 	  *(.text.*)
    100 	  :
    101 
    102   Kill linker definitions in sys/conf/Makefile.inc.kern.
    103 
    104 o Differentiate "options" and "flags"/"params".
    105 
    106   "options" enables features by adding *.c files (via attributes).
    107 
    108   "flags" and "params" are to change contents of *.c files.  These don't add
    109   *.c files to the result kernel, or don't build attributes (modules).
    110 
    111 o Make flags/params per attributes (modules).
    112 
    113   Basically flags and params are cpp(1) #define's generated in opt_*.h.  Make
    114   them local to one attributes (modules).  Flags/params which affects files
    115   across attributes (modules) are possible, but should be discouraged.
    116 
    117 o Generate things only by definitions.
    118 
    119   In the ideal dynamically modular world, "selection" will be done not at
    120   compile time but at runtime.  Users select their wanted modules, by
    121   dynamically loading them.
    122 
    123   This means that the system provides all choices; that is, build all modules
    124   in the source tree.  Necessary information is defined in the "definition"
    125   part.
    126 
    127 o Split cfdata.
    128 
    129   cfdata is a set of pattern matching rules to enable devices at runtime device
    130   auto-configuration.  It is pure data and can (should) be generated separately
    131   from the code.
    132 
    133 o Allow easier adding and removing of options.
    134 
    135   It should be possible to add or remove options, flags, etc.,
    136   without regard to whether or not they are already defined.
    137   For example, a configuration like this:
    138 
    139 	include GENERIC
    140 	options FOO
    141 	no options BAR
    142 
    143   should work regardless of whether or not options FOO and/or
    144   options BAR were defined in GENERIC.  It should not give
    145   errors like "options BAR was already defined" or "options FOO
    146   was not defined".
    147 
    148 o Introduce "class".
    149 
    150   Every module should be classified as at least one class, as modular(9)
    151   modules already do.  For example, file systems are marked as "vfs", network
    152   protocols are "netproto".
    153 
    154   Consider to merge "devclass" into "class".
    155 
    156   For syntax clarity, class names could be used as a keyword to select the
    157   class's instance module:
    158 
    159 	# Define net80211 module as netproto class
    160 	class netproto
    161 	define net80211: netproto
    162 
    163 	# Select net80211 to be builtin
    164 	netproto net80211
    165 
    166   Accordingly device/attach selection syntax should be revisited.
    167 
    168 o Support kernel constructor/destructor (.kctors/.kdtors)
    169 
    170   Initialization and finalization should be called via constructors and
    171   destructors.  Don't hardcode those sequences as sys/kern/init_main.c:main()
    172   does.
    173 
    174   The order of .kctors/.kdtors is resolved by dependency.  The difference from
    175   userland is that in kernel depended ones are located in lower addresses;
    176   "machdep" module is the lowest.  Thus the lowest entry in .ctors must be
    177   executed the first.
    178 
    179   The .kctors/.kdtors entries are executed by kernel's main() function, unlike
    180   userland where start code executes .ctors/.dtors before main().  The hardcoded
    181   sequence of various subsystem initializations in init_main.c:main() will be
    182   replaced by an array of .kctors invocations, and #ifdef's there will be gone.
    183 
    184 o Hide link-set in the final kernel.
    185 
    186   Link-set is used to collect references (pointers) at link time.  It relys on
    187   the ld(1) behavior that it automatically generates `__start_X' and `__stop_X'
    188   symbols for the section `X' to reduce coding.
    189 
    190   Don't allow kernel subsystems create random ELF sections.
    191 
    192   Pre-define all the available link-set names and pre-generate a linker script
    193   to merge them into .rodata.
    194 
    195   (For modular(9) modules, `link_set_modules' is looked up by kernel loader.
    196   Provide only it.)
    197 
    198   Provide a way for 3rd party modules to declare extra link-set.
    199 
    200 o Shared kernel objects.
    201 
    202   Since NetBSD has not established a clear kernel ABI, every single kernel
    203   has to build all the objects by their own.  As a result, similar kernels
    204   (e.g. evbarm kernels) repeatedly compile similar objects, that is waste of
    205   energy & space.
    206 
    207   Share them if possible.  For evb* ports, ideally everything except machdep.ko
    208   should be shared.
    209 
    210   While leaving optimizations as options (CPU specific optimizations, inlined
    211   bus_space(9) operations, etc.) for users, the official binaries build
    212   provided by TNF should be as portable as possible.
    213 
    214 o Always use explicit kernel linker script.
    215 
    216   ld(1) has an option -T <ldscript> to use a given linker script.  If not
    217   specified, a default, built-in linker script, mainly meant for userland
    218   programs, is used.
    219 
    220   Currently m68k, sh3, and vax don't have kernel linker scripts.  These work
    221   because these have no constraints about page boundary; they map and access
    222   kernel .text/.data in the same way.
    223 
    224 o Control ELF sections using linker script.
    225 
    226   Now kernel is linked and built directly from object files (*.o).  Each port
    227   has an MD linker script, which does everything needed to be done at link
    228   time.  As a result, they do from MI alignment restriction (read_mostly,
    229   cacheline_aligned) to load address specification for external boot loaders.
    230 
    231   Make this into multiple stages to make linkage more structural.  Especially,
    232   reserve the final link for purely MD purpose.  Note that in modular build,
    233   *.ko are shared between build of kernel and modular(9) modules (*.kmod).
    234 
    235 	Monolithic build:
    236 		     *.o  ---> netbsd.ko	Generic MI linkage
    237 		netbsd.ko ---> netbsd.ro	Kernel MI linkage
    238 		netbsd.ro ---> netbsd		Kernel MD linkage
    239 
    240 	Modular build (kernel):
    241 		     *.o  --->      *.ko	Generic + Per-module MI linkage
    242 		     *.ko ---> netbsd.ro	Kernel MI linkage
    243 		netbsd.ro ---> netbsd		Kernel MD linkage
    244 
    245 	Modular build (module):
    246 		     *.o  --->      *.ko	Generic + Per-module MI linkage
    247 		     *.ko --->      *.ro	Modular MI linkage
    248 		     *.ro --->      *.kmod	Modular MD linkage
    249 
    250   Genric MI linkage is for processing MI linkage that can be applied generally.
    251   Data section alignment (.data.read_mostly and .data.cacheline_aligned) is
    252   processed here.
    253 
    254   Per-module MI linkage is for modules that want some ordering.  For example,
    255   machdep.ko wants to put entry code at the top of .text and .data.
    256 
    257   Kernel MI linkage is for collecting kernel global section data, that is what
    258   link-set is used for now.  Once they are collected and symbols to the ranges
    259   are assigned, those sections are merged into the pre-existing sections
    260   (.rodata) because link-set sections in "netbsd" will never be interpreted by
    261   external loaders.
    262 
    263   Kernel MD linkage is used purely for MD purposes, that is, how kernels are
    264   loaded by external loaders.  It might be possible that one kernel relocatable
    265   (netbsd.ro) is linked into multiple final kernel image (netbsd) for diferent
    266   load addresses.
    267 
    268   Modular MI linkage is to prepare a module to be loadable as modular(9).  This
    269   may add some extra sections and/or symbols.
    270 
    271   Modular MD linkage is again for pure MD purposes like kernel MD linkage.
    272   Adjustment and/or optimization may be done.
    273 
    274   Kernel and modular MI linkages may change behavior depending on existence
    275   of debug information.  In the future .symtab will be copied using linker
    276   during this stage.
    277 
    278 o Preprocess and generate linker scripts dynamically.
    279 
    280   Include opt_xxx.h and replace some constant values (e.g. COHERENCY_UNIT,
    281   PAGE_SIZE, KERNEL_BASE_PHYS, KERNEL_BASE_VIRT, ...) with cpp(1).
    282 
    283   Don't unnecessarily define symbols.  Don't use sed(1).
    284 
    285 o Clean up linker scripts.
    286 
    287   o Don't specify OUTPUT_FORMAT()/OUTPUT_ARCH()
    288 
    289     These are basically set in compilers/linkers.  If non-default ABI is used,
    290     command-line arguments should be specified.
    291 
    292   o Remove .rel/.rela handlings.
    293 
    294     These are set in relocatable objects, and handled by dynamic linkers.
    295     Totally irrelefant for kernels.
    296 
    297   o Clean up debug section handlings.
    298 
    299   o Document (section boundary) symbols set in linker scripts.
    300 
    301     There must be a reason why symbols are defined and exported.
    302 
    303     PROVIDE() is to define internal symbols.
    304 
    305   o Clean up load addresses.
    306 
    307   o Program headers.
    308 
    309   o According to matt@, .ARM.extab/.ARM.exidx sections are no longer needed.
    310 
    311 o Redesign swapnetbsd.c (root/swap device specification)
    312 
    313   Don't build a whole kernel only to specify root/swap devices.
    314 
    315   Make these parameter re-configurable afterwards.
    316 
    317 o Namespace.
    318 
    319   Investigate namespace of attributes/modules/options.  Figure out the hidden
    320   design about these, document it, then re-design it.
    321 
    322   At this moment, all of them share the single "selecttab", which means their
    323   namespaces are common, but they also have respective tables (attrtab,
    324   opttab, etc.).
    325 
    326   Selecting an option (addoption()), that is also a module name, works only if
    327   the module doesn't depend on anything, because addoption() doesn't select
    328   module and its dependencies (selectattr()).  In other words, an option is
    329   only safely converted to a module (define), only if it doesn't depend on
    330   anything.  (One example is DDB.)
    331 
    332 o Convert pseudo(dev) attach functions to take (void) (== kernel ctors).
    333 
    334   The pseudo attach function was originally designed to take `int n' as
    335   the number of instances of the pseudo device.  Now most of pseudo
    336   devices have been converted to be `cloneable', meaning that their
    337   instances are dynamically allocated at run-time, because guessing how
    338   much instances are needed for users at compile time is almost impossible.
    339   Restricting such a pure software resource at compile time is senseless,
    340   considering that the rest of the world is dynamic.
    341 
    342   If pseudo attach functions once become (void), config(1) no longer
    343   has to generate iteration to call those functions, by making them part
    344   of kernel constructors, that are a list of (void) functions.
    345 
    346   Some pseudo devices may have dependency/ordering problems, because
    347   pseudo attach functions have no choice when to be called.  This could
    348   be solved by converting to kctors, where functions are called in order
    349   by dependency.
    350 
    351 o Enhance ioconf behavior for pseudo-devices
    352 
    353   See "bin/48571: config(1) ioconf is insufficient for pseudo-devices" for
    354   more details.  In a nutshell, it would be "useful" for config to emit
    355   the necessary stuff in the generated ioconf.[ch] to enable use of
    356   config_{init,fini}_component() for attaching and detaching pseudodev's.
    357 
    358   Currently, you need to manually construct your own data structures, and
    359   manually "attach" them, one at a time.  This leads to duplication of
    360   code (where multiple drivers contain the same basic logic), and doesn't
    361   necessarily handle all of the "frobbing" of the kernel lists.
    362 
    363 o Disallow unknown options.
    364 
    365   Don't accept options that are not defined as either defflag or defparam.
    366   Report them and exit.  Don't set ${IDENT} in the generated Makefile.
    367 
    368 o Kill makeoptions.
    369 
    370   It adds a variable defined in the generated `Makefile'.  While it looks
    371   useful, it is too flexible and easy to abuse.  The `Makefile' should be
    372   kept as simple as possible and have nothing that affects output contents.
    373   Consider to kill `makeoptions' totally, replace existing ones with `options'.
    374 
    375 o Don't use -Ttext ${TEXTADDR}.
    376 
    377   Although ld(1)'s `-Ttext ${TEXTADDR}' is an easy way to specify the virtual
    378   base address of .text at link time, it needs to change command-line; in
    379   kernel build, Makefile needs to change to reflect kernel's configuration.
    380   It is simpler to reflect kenel configuration using linker script via assym.h.
    381 
    382 o Convert ${DIAGNOSTIC} and ${DEBUG} as flags (defflag).
    383 
    384   Probably generate opt_diagnostic.h/opt_debug.h and include them in
    385   sys/param.h.
    386 
    387 o Strictly define DIAGNOSTIC.
    388 
    389   It is possible to make DIAGNOSTIC kernel and modules binary-compatible with
    390   non-DIAGNOSTIC ones.  In that case, debug type informations should match
    391   theoretically (not confirmed).
    392 
    393 o Define genassym(1) symbols per file.
    394 
    395   Have each file define symbols that have to be generated by genassym(1) so
    396   that more accurate dependency is reflected.
    397 
    398   For example, if foo.S needs some symbols, it defines them in foo.assym,
    399   declaring that foo.S depends on foo.assym.h, and includes foo.assym.h.
    400   foo.assym.h is generated by following the suffix rule of .assym -> .assym.h.
    401   When one header is updated, only related *.assym.h files are regenerated,
    402   instead of rebuilding all MD/*.S files that depend on the global, single
    403   assym.h.
    404