TODO revision 1.11
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
47o Retire "attach foo at bar with foo_bar.c"
48
49  Most of these should be rewritten by defining a common interface attribute
50  "foobus", instead of writing multiple attachments.  com(4), ld(4), ehci(4)
51  are typical examples.  For ehci(4), EHCI-capable controller drivers implement
52  "ehcibus" interface, like:
53
54	defne	ehcibus {}
55	device	imxehci: ehcibus
56
57  These drivers' attach functions call config_found() to attach ehci(4) via
58  the "ehcibus" interface attribute, instead of calling ehci_init() directly.
59  Same for com(4) (com_attach_subr()) and ld(4) (ldattach()).
60
61o Sort objects in more reasonable order.
62
63  Put machdep.ko in the lowest address.  uvm.ko and kern.ko follow.
64
65  Kill alphabetical sort (${OBJS:O} in sys/conf/Makefile.inc.kern.
66
67  Use ldscript.  Do like this
68
69	.text :
70	AT (ADDR(.text) & 0x0fffffff)
71	{
72	  *(.text.machdep.locore.entry)
73	  *(.text.machdep.locore)
74	  *(.text.machdep)
75	  *(.text)
76	  *(.text.*)
77	  :
78
79  Kill linker definitions in sys/conf/Makefile.inc.kern.
80
81o Differentiate "options" and "flags"/"params".
82
83  "options" enables features by adding *.c files (via attributes).
84
85  "flags" and "params" are to change contents of *.c files.  These don't add
86  *.c files to the result kernel, or don't build attributes (modules).
87
88o Make flags/params per attributes (modules).
89
90  Basically flags and params are cpp(1) #define's generated in opt_*.h.  Make
91  them local to one attributes (modules).  Flags/params which affects files
92  across attributes (modules) are possible, but should be discouraged.
93
94o Generate things only by definitions.
95
96  In the ideal dynamically modular world, "selection" will be done not at
97  compile time but at runtime.  Users select their wanted modules, by
98  dynamically loading them.
99
100  This means that the system provides all choices; that is, build all modules
101  in the source tree.  Necessary information is defined in the "definition"
102  part.
103
104o Split cfdata.
105
106  cfdata is a set of pattern matching rules to enable devices at runtime device
107  auto-configuration.  It is pure data and can (should) be generated separately
108  from the code.
109
110o Allow easier adding and removing of options.
111
112  It should be possible to add or remove options, flags, etc.,
113  without regard to whether or not they are already defined.
114  For example, a configuration like this:
115
116	include GENERIC
117	options FOO
118	no options BAR
119
120  should work regardless of whether or not options FOO and/or
121  options BAR were defined in GENERIC.  It should not give
122  errors like "options BAR was already defined" or "options FOO
123  was not defined".
124
125o Introduce "class".
126
127  Every module should be classified as at least one class, as modular(9)
128  modules already do.  For example, file systems are marked as "vfs", network
129  protocols are "netproto".
130
131  Consider to merge "devclass" into "class".
132
133  For syntax clarity, class names could be used as a keyword to select the
134  class's instance module:
135
136	# Define net80211 module as netproto class
137	class netproto
138	define net80211: netproto
139
140	# Select net80211 to be builtin
141	netproto net80211
142
143  Accordingly device/attach selection syntax should be revisited.
144
145o Support kernel constructor/destructor (.kctors/.kdtors)
146
147  Initialization and finalization should be called via constructors and
148  destructors.  Don't hardcode those sequences as sys/kern/init_main.c:main()
149  does.
150
151  The order of .kctors/.kdtors is resolved by dependency.  The difference from
152  userland is that in kernel depended ones are located in lower addresses;
153  "machdep" module is the lowest.  Thus the lowest entry in .ctors must be
154  executed the first.
155
156  The .kctors/.kdtors entries are executed by kernel's main() function, unlike
157  userland where start code executes .ctors/.dtors before main().  The hardcoded
158  sequence of various subsystem initializations in init_main.c:main() will be
159  replaced by an array of .kctors invocations, and #ifdef's there will be gone.
160
161o Replace linkset.
162
163  Don't allow kernel subsystems create random ELF sections (with potentially
164  long names) in the final kernel.  To collect some data in statically linked
165  modules, creating intermediate sections (e.g. .data.linkset.sysctl) and
166  exporting the start/end symbols (e.g. _data_linkset_sysctl_{start,end})
167  using linker script should be fine.
168
169  Dynamically loaded modules have to register those entries via constructors
170  (functions).  This means that dynamically loaded modules are flexible but
171  come with overhead.
172
173o Shared kernel objects.
174
175  Since NetBSD has not established a clear kernel ABI, every single kernel
176  has to build all the objects by their own.  As a result, similar kernels
177  (e.g. evbarm kernels) repeatedly compile similar objects, that is waste of
178  energy & space.
179
180  Share them if possible.  For evb* ports, ideally everything except machdep.ko
181  should be shared.
182
183  While leaving optimizations as options (CPU specific optimizations, inlined
184  bus_space(9) operations, etc.) for users, the official binaries build
185  provided by TNF should be as portable as possible.
186
187o Control ELF sections using linker script.
188
189  Now kernel is linked and built directly from object files (*.o).  Each port
190  has an MD linker script, which does everything needed to be done at link
191  time.  As a result, they do from MI alignment restriction (read_mostly,
192  cacheline_aligned) to load address specification for external boot loaders.
193
194  Make this into multiple stages to make linkage more structural.  Especially,
195  reserve the final link for purely MD purpose.  Note that in modular build,
196  *.ko are shared between build of kernel and modular(9) modules (*.kmod).
197
198	Monolithic build:
199		     *.o  ---> netbsd.ko	Generic MI linkage
200		netbsd.ko ---> netbsd.ro	Kernel MI linkage
201		netbsd.ro ---> netbsd		Kernel MD linkage
202
203	Modular build (kernel):
204		     *.o  --->      *.ko	Generic + Per-module MI linkage
205		     *.ko ---> netbsd.ro	Kernel MI linkage
206		netbsd.ro ---> netbsd		Kernel MD linkage
207
208	Modular build (module):
209		     *.o  --->      *.ko	Generic + Per-module MI linkage
210		     *.ko --->      *.ro	Modular MI linkage
211		     *.ro --->      *.kmod	Modular MD linkage
212
213  Genric MI linkage is for processing MI linkage that can be applied generally.
214  Data section alignment (.data.read_mostly and .data.cacheline_aligned) is
215  processed here.
216
217  Per-module MI linkage is for modules that want some ordering.  For example,
218  machdep.ko wants to put entry code at the top of .text and .data.
219
220  Kernel MI linkage is for collecting kernel global section data, that is what
221  link-set is used for now.  Once they are collected and symbols to the ranges
222  are assigned, those sections are merged into the pre-existing sections
223  (.rodata) because link-set sections in "netbsd" will never be interpreted by
224  external loaders.
225
226  Kernel MD linkage is used purely for MD purposes, that is, how kernels are
227  loaded by external loaders.  It might be possible that one kernel relocatable
228  (netbsd.ro) is linked into multiple final kernel image (netbsd) for diferent
229  load addresses.
230
231  Modular MI linkage is to prepare a module to be loadable as modular(9).  This
232  may add some extra sections and/or symbols.
233
234  Modular MD linkage is again for pure MD purposes like kernel MD linkage.
235  Adjustment and/or optimization may be done.
236
237  Kernel and modular MI linkages may change behavior depending on existence
238  of debug information.  In the future .symtab will be copied using linker
239  during this stage.
240