TODO revision 1.11
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. 1861.10Suebayasi 1871.10Suebayasio Control ELF sections using linker script. 1881.10Suebayasi 1891.10Suebayasi Now kernel is linked and built directly from object files (*.o). Each port 1901.10Suebayasi has an MD linker script, which does everything needed to be done at link 1911.10Suebayasi time. As a result, they do from MI alignment restriction (read_mostly, 1921.10Suebayasi cacheline_aligned) to load address specification for external boot loaders. 1931.10Suebayasi 1941.10Suebayasi Make this into multiple stages to make linkage more structural. Especially, 1951.11Suebayasi reserve the final link for purely MD purpose. Note that in modular build, 1961.11Suebayasi *.ko are shared between build of kernel and modular(9) modules (*.kmod). 1971.10Suebayasi 1981.10Suebayasi Monolithic build: 1991.10Suebayasi *.o ---> netbsd.ko Generic MI linkage 2001.10Suebayasi netbsd.ko ---> netbsd.ro Kernel MI linkage 2011.10Suebayasi netbsd.ro ---> netbsd Kernel MD linkage 2021.10Suebayasi 2031.10Suebayasi Modular build (kernel): 2041.10Suebayasi *.o ---> *.ko Generic + Per-module MI linkage 2051.10Suebayasi *.ko ---> netbsd.ro Kernel MI linkage 2061.10Suebayasi netbsd.ro ---> netbsd Kernel MD linkage 2071.10Suebayasi 2081.10Suebayasi Modular build (module): 2091.10Suebayasi *.o ---> *.ko Generic + Per-module MI linkage 2101.10Suebayasi *.ko ---> *.ro Modular MI linkage 2111.10Suebayasi *.ro ---> *.kmod Modular MD linkage 2121.10Suebayasi 2131.10Suebayasi Genric MI linkage is for processing MI linkage that can be applied generally. 2141.10Suebayasi Data section alignment (.data.read_mostly and .data.cacheline_aligned) is 2151.10Suebayasi processed here. 2161.10Suebayasi 2171.10Suebayasi Per-module MI linkage is for modules that want some ordering. For example, 2181.10Suebayasi machdep.ko wants to put entry code at the top of .text and .data. 2191.10Suebayasi 2201.10Suebayasi Kernel MI linkage is for collecting kernel global section data, that is what 2211.10Suebayasi link-set is used for now. Once they are collected and symbols to the ranges 2221.10Suebayasi are assigned, those sections are merged into the pre-existing sections 2231.10Suebayasi (.rodata) because link-set sections in "netbsd" will never be interpreted by 2241.10Suebayasi external loaders. 2251.10Suebayasi 2261.10Suebayasi Kernel MD linkage is used purely for MD purposes, that is, how kernels are 2271.10Suebayasi loaded by external loaders. It might be possible that one kernel relocatable 2281.10Suebayasi (netbsd.ro) is linked into multiple final kernel image (netbsd) for diferent 2291.10Suebayasi load addresses. 2301.10Suebayasi 2311.11Suebayasi Modular MI linkage is to prepare a module to be loadable as modular(9). This 2321.11Suebayasi may add some extra sections and/or symbols. 2331.11Suebayasi 2341.11Suebayasi Modular MD linkage is again for pure MD purposes like kernel MD linkage. 2351.11Suebayasi Adjustment and/or optimization may be done. 2361.11Suebayasi 2371.11Suebayasi Kernel and modular MI linkages may change behavior depending on existence 2381.11Suebayasi of debug information. In the future .symtab will be copied using linker 2391.11Suebayasi during this stage. 240