TODO revision 1.15
1o 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
12o 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
20o 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
35o 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
58o 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, "xxxbus");
65
66  If finding unknown children (e.g. "pci" finding pci devices):
67
68	config_find(self, "pci", locs, aux);
69
70o 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
84o 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
104o 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
111o 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
117o 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
127o 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
133o 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
148o 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
168o 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
184o 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
200o 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
214o Control ELF sections using linker script.
215
216  Now kernel is linked and built directly from object files (*.o).  Each port
217  has an MD linker script, which does everything needed to be done at link
218  time.  As a result, they do from MI alignment restriction (read_mostly,
219  cacheline_aligned) to load address specification for external boot loaders.
220
221  Make this into multiple stages to make linkage more structural.  Especially,
222  reserve the final link for purely MD purpose.  Note that in modular build,
223  *.ko are shared between build of kernel and modular(9) modules (*.kmod).
224
225	Monolithic build:
226		     *.o  ---> netbsd.ko	Generic MI linkage
227		netbsd.ko ---> netbsd.ro	Kernel MI linkage
228		netbsd.ro ---> netbsd		Kernel MD linkage
229
230	Modular build (kernel):
231		     *.o  --->      *.ko	Generic + Per-module MI linkage
232		     *.ko ---> netbsd.ro	Kernel MI linkage
233		netbsd.ro ---> netbsd		Kernel MD linkage
234
235	Modular build (module):
236		     *.o  --->      *.ko	Generic + Per-module MI linkage
237		     *.ko --->      *.ro	Modular MI linkage
238		     *.ro --->      *.kmod	Modular MD linkage
239
240  Genric MI linkage is for processing MI linkage that can be applied generally.
241  Data section alignment (.data.read_mostly and .data.cacheline_aligned) is
242  processed here.
243
244  Per-module MI linkage is for modules that want some ordering.  For example,
245  machdep.ko wants to put entry code at the top of .text and .data.
246
247  Kernel MI linkage is for collecting kernel global section data, that is what
248  link-set is used for now.  Once they are collected and symbols to the ranges
249  are assigned, those sections are merged into the pre-existing sections
250  (.rodata) because link-set sections in "netbsd" will never be interpreted by
251  external loaders.
252
253  Kernel MD linkage is used purely for MD purposes, that is, how kernels are
254  loaded by external loaders.  It might be possible that one kernel relocatable
255  (netbsd.ro) is linked into multiple final kernel image (netbsd) for diferent
256  load addresses.
257
258  Modular MI linkage is to prepare a module to be loadable as modular(9).  This
259  may add some extra sections and/or symbols.
260
261  Modular MD linkage is again for pure MD purposes like kernel MD linkage.
262  Adjustment and/or optimization may be done.
263
264  Kernel and modular MI linkages may change behavior depending on existence
265  of debug information.  In the future .symtab will be copied using linker
266  during this stage.
267
268o Redesign swapnetbsd.c (root/swap device specification)
269
270  Don't build a whole kernel only to specify root/swap devices.
271
272  Make these parameter re-configurable afterwards.
273
274o Namespace.
275
276  Investigate namespace of attributes/modules/options.  Figure out the hidden
277  design about these, document it, then re-design it.
278
279  At this moment, all of them share the single "selecttab", which means their
280  namespaces are common, but they also have respective tables (attrtab,
281  opttab, etc.).
282
283  Selecting an option (addoption()), that is also a module name, works only if
284  the module doesn't depend on anything, because addoption() doesn't select
285  module and its dependencies (selectattr()).  In other words, an option is
286  only safely converted to a module (define), only if it doesn't depend on
287  anything.  (One example is DDB.)
288