[8f5adbc] | 1 | RTEMS BSD USB and TCP/IP Developers Guide |
---|
| 2 | ========================================= |
---|
| 3 | Joel Sherrill <joel.sherrill@oarcorp.com> |
---|
| 4 | :Author Initials: JRS |
---|
| 5 | :toc: |
---|
| 6 | :icons: |
---|
| 7 | :numbered: |
---|
| 8 | :website: http://www.rtems.org/ |
---|
| 9 | |
---|
| 10 | RTEMS uses FreeBSD as the source of its TCP/IP and USB stacks. |
---|
| 11 | This is a developers guide which captures information on the |
---|
| 12 | process of merging code from FreeBSD, building this library, |
---|
| 13 | RTEMS specific support files, and general guidelines on what |
---|
| 14 | modifications to the FreeBSD source are permitted. |
---|
| 15 | |
---|
[e392fdb7] | 16 | Goals of this effort are: |
---|
| 17 | |
---|
| 18 | * Update TCP/IP and provide USB in RTEMS |
---|
| 19 | * Ease updating to future FreeBSD versions |
---|
| 20 | * Ease tracking changes in FreeBSD code |
---|
| 21 | * Minimize manual changes in FreeBSD code |
---|
| 22 | * Define stable kernel/device driver API which is implemented |
---|
| 23 | by both RTEMS and FreeBSD. This is the foundation of the port. |
---|
| 24 | |
---|
| 25 | We will work to push our changes upstream to the FreeBSD Project |
---|
| 26 | and minimize changes required at each update point. |
---|
| 27 | |
---|
[8f5adbc] | 28 | ************************************************************** |
---|
| 29 | This is a work in progress and is very likely to be incomplete. |
---|
| 30 | Please help by adding to it. |
---|
| 31 | ************************************************************** |
---|
| 32 | |
---|
| 33 | == Source Code Version Information |
---|
| 34 | |
---|
[e8b7066] | 35 | * FreeBSD 8.2 SVN r255967 |
---|
[8f5adbc] | 36 | * RTEMS 4.11 |
---|
| 37 | - BSP must have support for all new BSD sys sections |
---|
| 38 | - It is preferable if the BSP uses linkcmds.base. |
---|
| 39 | - BSP must be from an architecture with Programmable Interrupt Controller |
---|
| 40 | interrupt model. |
---|
| 41 | |
---|
[e8b7066] | 42 | The latest port uses the FreeBSD sources as a Git submodule which will |
---|
| 43 | generally be referred to as the FreeBSD source in this document. Previously a |
---|
| 44 | FreeBSD 8.2 SVN checkout was used. The SVN checkout command corresponding to |
---|
| 45 | the current Git submodule commit is this |
---|
| 46 | svn co http://svn.freebsd.org/base/releng/8.2 -r255967 freebsd-8.2 |
---|
[e392fdb7] | 47 | |
---|
[560eccf] | 48 | == Issues and To Do |
---|
[d652c3b] | 49 | * Per-CPU data should be enabled once the new stack is ready for SMP. |
---|
| 50 | |
---|
| 51 | * Per-CPU NETISR(9) should be enabled onece the new stack is ready for SMP. |
---|
| 52 | |
---|
[549488b] | 53 | * Multiple routing tables are not supported. Every FIB value is set to zero |
---|
| 54 | (= BSD_DEFAULT_FIB). |
---|
| 55 | |
---|
[cc5f4b2] | 56 | * Process identifiers are not supported. Every PID value is set to zero |
---|
| 57 | (= BSD_DEFAULT_PID). |
---|
| 58 | |
---|
[69b29a0] | 59 | * User credentials are not supported. The following functions allow the |
---|
| 60 | operation for everyone |
---|
| 61 | - prison_equal_ip4(), |
---|
| 62 | - chgsbsize(), |
---|
| 63 | - cr_cansee(), |
---|
| 64 | - cr_canseesocket() and |
---|
| 65 | - cr_canseeinpcb(). |
---|
| 66 | |
---|
[560eccf] | 67 | * Sebastian Huber and Joel Sherrill discussed the need for a a basic USB |
---|
| 68 | functionality test that is known to work on qemu pc. |
---|
| 69 | |
---|
[8f5adbc] | 70 | * Adapt generic IRQ PIC interface code to Simple Vectored Interrupt Model |
---|
| 71 | so that those architectures can use new TCP/IP and USB code. |
---|
[560eccf] | 72 | |
---|
[78e3181] | 73 | * freebsd-userspace/rtems/include/sys/syslog.h is a copy from the old |
---|
| 74 | RTEMS TCP/IP stack. For some reason, the __printflike markers do not |
---|
| 75 | compile in this environment. We may want to use the FreeBSD syslog.h |
---|
| 76 | and get this addressed. |
---|
| 77 | |
---|
[8f5adbc] | 78 | * in_cksum implementations for architectures not supported by FreeBSD. |
---|
| 79 | This will require figuring out where to put implementations that do |
---|
| 80 | not originate from FreeBSD and are populated via the script. |
---|
[560eccf] | 81 | |
---|
| 82 | * linker section issues: I have undefined symbols for |
---|
[362782e] | 83 | `_bsd__start_set_sysinit_set` and `_bsd__stop_set_sysinit_set`. |
---|
[560eccf] | 84 | Is this the only type of new section magic? What about the old sysctl_set? |
---|
| 85 | I added this to my linkcmds. |
---|
| 86 | |
---|
[cdf6024] | 87 | * MAC support functions are not thread-safe ("freebsd/lib/libc/posix1e/mac.c"). |
---|
| 88 | |
---|
[c14bb23] | 89 | * IFCONFIG(8): IEEE80211 support is disabled. This module depends on a XML |
---|
| 90 | parser and mmap(). |
---|
| 91 | |
---|
[1bc2756] | 92 | * get_cyclecount(): The implementation is a security problem. |
---|
| 93 | |
---|
[e859231] | 94 | * What to do with the priority parameter present in the FreeBSD synchronization |
---|
[ea87228] | 95 | primitives and the thread creation functions? |
---|
| 96 | |
---|
| 97 | * TASKQUEUE(9): Support spin mutexes. |
---|
[e859231] | 98 | |
---|
[3e29388] | 99 | * ZONE(9): Review allocator lock usage in rtems-bsd-chunk.c. |
---|
| 100 | |
---|
[0c9f27b] | 101 | * KQUEUE(2): Choose proper lock for global kqueue list. |
---|
| 102 | |
---|
[a9e26f5] | 103 | * TIMEOUT(9): Maybe use special task instead of timer server to call |
---|
| 104 | callout_tick(). |
---|
| 105 | |
---|
[c99816e] | 106 | * sysctl_handle_opaque(): Implement reliable snapshots. |
---|
| 107 | |
---|
[cae4d0a] | 108 | * PING6(8): What to do with SIGALARM? |
---|
| 109 | |
---|
[560eccf] | 110 | [listing] |
---|
| 111 | ---- |
---|
| 112 | /* sysinit section? */ |
---|
| 113 | . = ALIGN (16); |
---|
| 114 | _bsd__start_set_sysinit_set = .; |
---|
| 115 | *(set_sys_init_*); |
---|
| 116 | _bsd__stop_set_sysinit_set = .; |
---|
| 117 | |
---|
| 118 | ---- |
---|
| 119 | |
---|
[362782e] | 120 | * Why is the interrupt server used? The BSD interrupt handlers can block on |
---|
| 121 | synchronization primitives like mutexes. This is in contrast to RTEMS |
---|
| 122 | interrupt service routines. The BSPs using the generic interrupt support must |
---|
| 123 | implement the `bsp_interrupt_vector_enable()` and |
---|
| 124 | `bsp_interrupt_vector_disable()` routines. They normally enable/disable a |
---|
| 125 | particular interrupt source at the interrupt controller. This can be used to |
---|
| 126 | implement the interrupt server. The interrupt server is a task that wakes-up |
---|
| 127 | in case an associated interrupt happens. The interrupt source is disabled in |
---|
| 128 | a generic interrupt handler that wakes-up the interrupt server task. Once the |
---|
| 129 | postponed interrupt processing is performed in the interrupt server the |
---|
| 130 | interrupt source is enabled again. |
---|
| 131 | |
---|
[560eccf] | 132 | * Convert all BSP linkcmds to use a linkcmds.base so the sections are |
---|
| 133 | easier to insert. |
---|
| 134 | |
---|
| 135 | * rtems-bsd-init-with-irq.c: |
---|
| 136 | rtems_bsd_initialize_with_interrupt_server() has reference to |
---|
| 137 | rtems_interrupt_server_initialize() and this method is unimplemented |
---|
| 138 | - XXX BSP implements pieces |
---|
| 139 | - BSPs using this software stack must support it apparently. |
---|
| 140 | - What about Simple Vectored architectures? |
---|
| 141 | |
---|
[78e3181] | 142 | * We carried over use of notepad 0 for per task information. This should |
---|
| 143 | be changed. |
---|
| 144 | |
---|
[560eccf] | 145 | * maxproc variable referenced by rtems-bsd-resource.c. What should it |
---|
| 146 | be set to? |
---|
| 147 | |
---|
| 148 | * ngroups_max variable referenced by rtems-bsd-prot.c. - What should |
---|
| 149 | it be set to? |
---|
[8f5adbc] | 150 | |
---|
[86bc9a7] | 151 | * NIC Device Drivers |
---|
[78e3181] | 152 | - Only common PCI NIC drivers have been included in the initial set. These |
---|
| 153 | do not include any system on chip or ISA drivers. |
---|
| 154 | - PCI configuration probe does not appear to happen to determine if a |
---|
| 155 | NIC is in I/O or memory space. We have worked around this by using a |
---|
| 156 | static hint to tell the fxp driver the correct mode. But this needs to |
---|
| 157 | be addressed. |
---|
[86bc9a7] | 158 | - The ISA drivers require more BSD infrastructure to be addressed. This was |
---|
| 159 | outside the scope of the initial porting effort. |
---|
| 160 | |
---|
[8f5adbc] | 161 | == FreeBSD Source |
---|
| 162 | |
---|
| 163 | You should be able to rely on FreebSD manual pages and documentation |
---|
| 164 | for details on the code itself. |
---|
| 165 | |
---|
| 166 | === Automatically Generated FreeBSD Files |
---|
| 167 | |
---|
| 168 | The FreeBSD source tarball includes a file named Makefile.rtems which |
---|
[455aa3a] | 169 | has stanzas to automatically generate some files using awk. For details |
---|
| 170 | on this, see http://www.freebsd.org/cgi/man.cgi?query=kobj&apropos=0&sektion=0&manpath=FreeBSD+9.0-RELEASE&arch=default&format=html |
---|
[8f5adbc] | 171 | |
---|
[455aa3a] | 172 | XXX This needs more detail. |
---|
[8f5adbc] | 173 | |
---|
| 174 | === Rules for Modifying FreeBSD Source |
---|
| 175 | |
---|
| 176 | * Only add lines. Subtract code by added "ifndef __rtems__". This makes |
---|
| 177 | merging easier in the future. |
---|
| 178 | |
---|
| 179 | == libbsd Source |
---|
| 180 | |
---|
| 181 | === What is in git |
---|
| 182 | |
---|
| 183 | The git source is a self-contained kit with FreeBSD and RTEMS components |
---|
| 184 | pre-merged. The Makefile in this kit is automatically generated. |
---|
| 185 | |
---|
| 186 | Any changes to sources in the freebsd or contrib directories will need to |
---|
| 187 | be merged upstream into our master FreeBSD svn checkout. |
---|
| 188 | |
---|
[c90c212] | 189 | The FreeBSD sources managed in the rtems-libbsd git repository (e.g. contrib |
---|
[560eccf] | 190 | and freebsd directories) contain the "managed" version of the |
---|
| 191 | FreeBSD source. The FreeBSD SVN source is the "master" version. The |
---|
| 192 | freebsd-to-rtems.py script is used to transfer files between the two |
---|
[c90c212] | 193 | trees. In general terms, if you have modified FreeBSD (i.e. anything in the |
---|
| 194 | freebsd directory) in the rtems-libbsd tree, you will need to run the script |
---|
| 195 | in "revert" or "reverse" mode using the -R switch. This will copy the source |
---|
| 196 | back to your local copy of the FreeBSD source so you can run "svn diff" against |
---|
| 197 | the upstream FreeBSD source. If you want to transfer source files from the |
---|
| 198 | FreeBSD SVN checkout to the rtems-libbsd tree, then you must run the script in |
---|
| 199 | "forward" mode (the default). |
---|
[560eccf] | 200 | |
---|
[c90c212] | 201 | === Building rtems-libbsd source |
---|
[8f5adbc] | 202 | |
---|
[455aa3a] | 203 | You need to configure RTEMS for the desired BSP and install it. The |
---|
| 204 | following is the script used to build the powerpc/psim BSP for our |
---|
| 205 | internal testing purposes: |
---|
| 206 | |
---|
| 207 | [listing] |
---|
| 208 | ---- |
---|
| 209 | #! /bin/sh |
---|
| 210 | |
---|
| 211 | cd ${HOME}/newbsd |
---|
| 212 | rm -rf b-psim |
---|
| 213 | mkdir b-psim |
---|
| 214 | cd b-psim |
---|
| 215 | ../git/rtems/configure --target=powerpc-rtems4.11 \ |
---|
| 216 | --enable-rtemsbsp=psim --disable-networking \ |
---|
| 217 | --enable-tests=samples \ |
---|
| 218 | --prefix=${HOME}/newbsd/bsp-install >c.log 2>&1 && \ |
---|
| 219 | make >b.log 2>&1 && \ |
---|
| 220 | make install >i.log 2>&1 |
---|
| 221 | echo $? |
---|
| 222 | ---- |
---|
| 223 | |
---|
| 224 | Then edit the file config.inc to set RTEMS_MAKEFILE_PATH appropriately |
---|
| 225 | to indicate the ${prefix}/${target}/${BSP}. Continuing on the above, |
---|
| 226 | the config.inc used to match the above is: |
---|
| 227 | |
---|
| 228 | [listing] |
---|
| 229 | ---- |
---|
| 230 | RTEMS_MAKEFILE_PATH = ${HOME}/newbsd/bsp-install/powerpc-rtems4.11/psim/ |
---|
| 231 | INSTALL_BASE = ${HOME}/newbsd/install |
---|
| 232 | ---- |
---|
| 233 | |
---|
[c90c212] | 234 | The above installs the rtems-libbsd kit into a separate place from |
---|
| 235 | RTEMS and the BSP. The rtems-libbsd tests are built against an installed |
---|
| 236 | image of the rtems-libbsd. By keeping it in a separate installation point |
---|
[455aa3a] | 237 | from RTEMS itself, this makes it easier to remove a libbsd installation |
---|
| 238 | and have a clean test point. |
---|
[8f5adbc] | 239 | |
---|
| 240 | [listing] |
---|
| 241 | ---- |
---|
| 242 | make |
---|
| 243 | make install |
---|
| 244 | make -C testsuite |
---|
| 245 | ---- |
---|
| 246 | |
---|
| 247 | At this point, we expect multiple linker errors. That is what we are |
---|
| 248 | currently working on. |
---|
| 249 | |
---|
| 250 | === Organization |
---|
| 251 | |
---|
| 252 | The top level directory contains a few directories and files. The following |
---|
| 253 | are important to understand: |
---|
| 254 | |
---|
| 255 | * freebsd-to-rtems.py - script to convert to and free FreeBSD and RTEMS trees |
---|
| 256 | * Makefile - automatically generated |
---|
| 257 | * contrib/ - from FreeBSD by script. |
---|
| 258 | * freebsd/ - from FreeBSD by script. |
---|
| 259 | * rtemsbsd/ - RTEMS specific implementations of FreeBSD kernel support routines. |
---|
| 260 | * testsuite/ - RTEMS specific tests |
---|
| 261 | * libbsd.txt - Documentation in Asciidoc |
---|
| 262 | |
---|
[c90c212] | 263 | == Moving Code Between FreeBSD SVN and rtems-libbsd |
---|
[e392fdb7] | 264 | |
---|
| 265 | The script freebsd-to-rtems.py is used to copy code from FreeBSD to the |
---|
[c90c212] | 266 | rtems-libbsd tree and to reverse this process. This script attempts to |
---|
[e392fdb7] | 267 | automate this process as much as possible and performs some transformations |
---|
| 268 | on the FreeBSD code. Its command line arguments are shown below: |
---|
| 269 | |
---|
| 270 | [listing] |
---|
| 271 | ---- |
---|
| 272 | freebsd-to-rtems.py [args] |
---|
| 273 | -?|-h|--help print this and exit |
---|
| 274 | -d|--dry-run run program but no modifications |
---|
[7326d96] | 275 | -D|--diff provide diff of files between trees |
---|
[e392fdb7] | 276 | -e|--early-exit evaluate arguments, print results, and exit |
---|
| 277 | -m|--makefile just generate Makefile |
---|
| 278 | -R|--reverse default FreeBSD -> RTEMS, reverse that |
---|
| 279 | -r|--rtems RTEMS directory |
---|
| 280 | -f|--freebsd FreeBSD directory |
---|
| 281 | -v|--verbose enable verbose output mode |
---|
| 282 | ---- |
---|
| 283 | |
---|
| 284 | In its default mode of operation, freebsd-to-rtems.py is used to copy code |
---|
[c90c212] | 285 | from FreeBSD to the rtems-libbsd tree and perform transformations. In forward |
---|
[e392fdb7] | 286 | mode, the script may be requested to just generate the Makefile. |
---|
| 287 | |
---|
| 288 | In "reverse mode", this script undoes those transformations and copies |
---|
| 289 | the source code back to the FreeBSD SVN tree. This allows us to do |
---|
| 290 | 'svn diff', evaluate changes made by the RTEMS Project, and report changes |
---|
| 291 | back to FreeBSD upstream. |
---|
| 292 | |
---|
| 293 | In either mode, the script may be asked to perform a dry-run or be verbose. |
---|
| 294 | Also, in either mode, the script is also smart enough to avoid copying over |
---|
| 295 | files which have not changed. This means that the timestamps of files are |
---|
| 296 | not changed unless the contents change. The script will also report the |
---|
| 297 | number of files which changed. In verbose mode, the script will print |
---|
| 298 | the name of the files which are changed. |
---|
| 299 | |
---|
| 300 | The following is an example forward run with no changes. |
---|
| 301 | |
---|
| 302 | [listing] |
---|
| 303 | ---- |
---|
| 304 | $ ~/newbsd/git/libbsd-8.2/freebsd-to-rtems.py \ |
---|
| 305 | -r /home/joel/newbsd/git/libbsd-8.2 \ |
---|
| 306 | -f /home/joel/newbsd/libbsd/freebsd-8.2 -v |
---|
| 307 | Verbose: yes |
---|
| 308 | Dry Run: no |
---|
| 309 | Only Generate Makefile: no |
---|
| 310 | RTEMS Directory: /home/joel/newbsd/git/libbsd-8.2 |
---|
| 311 | FreeBSD Directory: /home/joel/newbsd/libbsd/freebsd-8.2 |
---|
| 312 | Direction: forward |
---|
| 313 | Generating into /home/joel/newbsd/git/libbsd-8.2 |
---|
| 314 | 0 files were changed. |
---|
| 315 | ---- |
---|
| 316 | |
---|
[7326d96] | 317 | The script may also be used to generate a diff in either forward or reverse |
---|
| 318 | direction. |
---|
| 319 | |
---|
[c90c212] | 320 | == Initialization of rtems-libbsd |
---|
[455aa3a] | 321 | |
---|
[c90c212] | 322 | The initialization of the rtems-libbsd is based on the FreeBSD SYSINIT(9) |
---|
[8a4f070] | 323 | infrastructure. The key to initializing a system is to ensure that the desired |
---|
| 324 | device drivers are explicitly pulled into the linked application. This plus |
---|
| 325 | linking against the libbsd library will pull in the necessary FreeBSD |
---|
| 326 | infrastructure. |
---|
[455aa3a] | 327 | |
---|
[8a4f070] | 328 | The FreeBSD kernel is not a library like the RTEMS kernel. It is a bunch of |
---|
| 329 | object files linked together. If we have a library, then creating the |
---|
| 330 | executable is simple. We begin with a start symbol and recursively resolve all |
---|
| 331 | references. With a bunch of object files linked together we need a different |
---|
| 332 | mechanism. Most object files don't know each other. Lets say we have a driver |
---|
| 333 | module. The rest of the system has no references to this driver module. The |
---|
| 334 | driver module needs a way to tell the rest of the system: Hey, kernel I am |
---|
| 335 | here, please use my services! |
---|
[455aa3a] | 336 | |
---|
[8a4f070] | 337 | This registration of independent components is performed by SYSINIT(9) and |
---|
| 338 | specializations: |
---|
| 339 | |
---|
| 340 | http://www.freebsd.org/cgi/man.cgi?query=SYSINIT |
---|
| 341 | |
---|
| 342 | The SYSINIT(9) uses some global data structures that are placed in a certain |
---|
| 343 | section. In the linker command file we need this: |
---|
| 344 | |
---|
| 345 | [listing] |
---|
| 346 | ---- |
---|
| 347 | .robsdsets : { |
---|
| 348 | _bsd__start_set_modmetadata_set = .; |
---|
| 349 | *(_bsd_set_modmetadata_set); |
---|
| 350 | _bsd__stop_set_modmetadata_set = .; |
---|
| 351 | _bsd__start_set_sysctl_set = .; |
---|
| 352 | *(_bsd_set_sysctl_set); |
---|
| 353 | _bsd__stop_set_sysctl_set = .; |
---|
| 354 | } > REGION_RODATA AT > REGION_RODATA_LOAD |
---|
| 355 | |
---|
| 356 | .rwbsdsets : { |
---|
| 357 | _bsd__start_set_sysinit_set = .; |
---|
| 358 | *(_bsd_set_sysinit_set); |
---|
| 359 | _bsd__stop_set_sysinit_set = .; |
---|
| 360 | } > REGION_DATA AT > REGION_DATA_LOAD |
---|
| 361 | ---- |
---|
| 362 | |
---|
| 363 | Here you can see, that these global data structures are collected into |
---|
| 364 | continuous memory areas. This memory area can be identified by start and stop |
---|
| 365 | symbols. This constructs a table of uniform items. |
---|
| 366 | |
---|
| 367 | The low level FreeBSD code calls at some time during the initialization the |
---|
| 368 | mi_startup() function (machine independent startup). This function will sort |
---|
| 369 | the SYSINIT(9) set and call handler functions which perform further |
---|
| 370 | initialization. The last step is the scheduler invocation. |
---|
| 371 | |
---|
| 372 | The SYSINIT(9) routines are run in mi_startup() which is called by |
---|
| 373 | rtems_bsd_initialize(). |
---|
| 374 | |
---|
| 375 | This is also explained in "The Design and Implementation of the FreeBSD |
---|
| 376 | Operating System" section 14.3 "Kernel Initialization". |
---|
| 377 | |
---|
| 378 | In RTEMS we have a library and not a bunch of object files. Thus we need a way |
---|
| 379 | to pull-in the desired services out of the libbsd. Here the |
---|
| 380 | "rtems-bsd-sysinit.h" comes into play. The SYSINIT(9) macros have been |
---|
| 381 | modified and extended for RTEMS in "sys/kernel.h": |
---|
| 382 | |
---|
| 383 | [listing] |
---|
| 384 | ---- |
---|
| 385 | #ifndef __rtems__ |
---|
| 386 | #define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ |
---|
| 387 | static struct sysinit uniquifier ## _sys_init = { \ |
---|
| 388 | subsystem, \ |
---|
| 389 | order, \ |
---|
| 390 | func, \ |
---|
| 391 | (ident) \ |
---|
| 392 | }; \ |
---|
| 393 | DATA_SET(sysinit_set,uniquifier ## _sys_init) |
---|
| 394 | #else /* __rtems__ */ |
---|
| 395 | #define SYSINIT_ENTRY_NAME(uniquifier) \ |
---|
| 396 | _bsd_ ## uniquifier ## _sys_init |
---|
| 397 | #define SYSINIT_REFERENCE_NAME(uniquifier) \ |
---|
| 398 | _bsd_ ## uniquifier ## _sys_init_ref |
---|
| 399 | #define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ |
---|
| 400 | struct sysinit SYSINIT_ENTRY_NAME(uniquifier) = { \ |
---|
| 401 | subsystem, \ |
---|
| 402 | order, \ |
---|
| 403 | func, \ |
---|
| 404 | (ident) \ |
---|
| 405 | }; \ |
---|
| 406 | DATA_SET(sysinit_set,SYSINIT_ENTRY_NAME(uniquifier)) |
---|
| 407 | #define SYSINIT_REFERENCE(uniquifier) \ |
---|
| 408 | extern struct sysinit SYSINIT_ENTRY_NAME(uniquifier); \ |
---|
| 409 | static struct sysinit const * const \ |
---|
| 410 | SYSINIT_REFERENCE_NAME(uniquifier) __used \ |
---|
| 411 | = &SYSINIT_ENTRY_NAME(uniquifier) |
---|
| 412 | #define SYSINIT_MODULE_REFERENCE(mod) \ |
---|
| 413 | SYSINIT_REFERENCE(mod ## module) |
---|
| 414 | #define SYSINIT_DRIVER_REFERENCE(driver, bus) \ |
---|
| 415 | SYSINIT_MODULE_REFERENCE(driver ## _ ## bus) |
---|
| 416 | #endif /* __rtems__ */ |
---|
| 417 | ---- |
---|
| 418 | |
---|
| 419 | Here you see that the SYSINIT(9) entries are no longer static. The |
---|
| 420 | *_REFERENCE() macros will create references to the corresponding modules which |
---|
| 421 | are later resolved by the linker. The application has to provide an object |
---|
| 422 | file with references to all required FreeBSD modules. |
---|
| 423 | |
---|
| 424 | The FreeBSD device model is quite elaborated (with follow-ups): |
---|
| 425 | |
---|
| 426 | http://www.freebsd.org/cgi/man.cgi?query=driver |
---|
| 427 | |
---|
| 428 | The devices form a tree with the Nexus device at a high-level. This Nexus |
---|
| 429 | device is architecture specific in FreeBSD. In RTEMS we have our own Nexus |
---|
| 430 | device, see "rtems-bsd-nexus.c". It uses a table to add child devices: |
---|
| 431 | |
---|
| 432 | [listing] |
---|
| 433 | ---- |
---|
| 434 | const char *const _bsd_nexus_devices [] = { |
---|
| 435 | #ifdef NEED_USB_OHCI |
---|
| 436 | "ohci", |
---|
| 437 | #endif |
---|
| 438 | #ifdef NEED_USB_EHCI |
---|
| 439 | "ehci", |
---|
| 440 | #endif |
---|
| 441 | #ifdef NEED_SDHC |
---|
| 442 | "sdhci", |
---|
| 443 | #endif |
---|
| 444 | NULL |
---|
| 445 | }; |
---|
| 446 | ---- |
---|
| 447 | |
---|
| 448 | This table must be provided by the application. |
---|
[00ee241] | 449 | |
---|
| 450 | === SYSCTL_NODE Example |
---|
| 451 | |
---|
| 452 | During development, we had an undefined reference to |
---|
| 453 | _bsd_sysctl__net_children that we had trouble tracking down. Thanks to |
---|
| 454 | Chris Johns, we located it. He explained how to read SYSCTL_NODE |
---|
| 455 | definitions. This line from freebsd/netinet/in_proto.c is attempting |
---|
| 456 | to add the "inet" node to the parent node "_net". |
---|
| 457 | |
---|
| 458 | [listing] |
---|
| 459 | ---- |
---|
| 460 | SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0, |
---|
| 461 | "Internet Family"); |
---|
| 462 | ---- |
---|
| 463 | |
---|
| 464 | Our problem was that we could not find where _bsd_sysctl__net_children |
---|
| 465 | was defined. Chris suggested that when in doubt compile with -save-temps |
---|
| 466 | and look at the preprocessed .i files. But he did not need that. He |
---|
| 467 | explained that this the symbol name _bsd_sysctl__net_children was |
---|
| 468 | automatically generated by a SYSCTL_NODE as follows: |
---|
| 469 | |
---|
| 470 | * _bsd_ - added by RTEMS modifications to SYSCTL_NODE macro |
---|
| 471 | * sysctl_ - boilerplace added by SYSCTL_NODE macro |
---|
| 472 | * "" - empty string for parent node |
---|
| 473 | * net - name of SYSCTL_NODE |
---|
| 474 | * children - added by SYSCTL macros |
---|
| 475 | |
---|
| 476 | This was all generated by a support macro declaring the node as this: |
---|
| 477 | |
---|
| 478 | [listing] |
---|
| 479 | ---- |
---|
| 480 | struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name); |
---|
| 481 | ---- |
---|
| 482 | |
---|
| 483 | Given this information, we located this SYSCTL_NODE declaration in |
---|
| 484 | kern/kern_mib.c |
---|
| 485 | |
---|
| 486 | [listing] |
---|
| 487 | ---- |
---|
| 488 | SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0, |
---|
| 489 | "High kernel, proc, limits &c"); |
---|
| 490 | ---- |
---|
| 491 | |
---|
[c03e095] | 492 | == Core FreeBSD APIs and RTEMS Replacements == |
---|
| 493 | |
---|
| 494 | === SX(9) (Shared/exclusive locks) === |
---|
| 495 | |
---|
| 496 | http://www.freebsd.org/cgi/man.cgi?query=sx |
---|
| 497 | |
---|
| 498 | Binary semaphores (this neglects the ability to allow shared access). |
---|
| 499 | |
---|
| 500 | === MUTEX(9) (Mutual exclusion) === |
---|
| 501 | |
---|
| 502 | http://www.freebsd.org/cgi/man.cgi?query=mutex |
---|
| 503 | |
---|
| 504 | Binary semaphores (not recursive mutexes are not supported this way). |
---|
| 505 | |
---|
| 506 | === RWLOCK(9) (Reader/writer lock) === |
---|
| 507 | |
---|
| 508 | http://www.freebsd.org/cgi/man.cgi?query=rwlock |
---|
| 509 | |
---|
| 510 | POSIX r/w lock. |
---|
| 511 | |
---|
| 512 | === RMLOCK(9) (Reader/writer lock optimized for mostly read access patterns) === |
---|
| 513 | |
---|
[5ab1e1d] | 514 | Note: This object was implemented as a wrapper for RWLOCK in the rm_lock header file. |
---|
| 515 | |
---|
[c03e095] | 516 | http://www.freebsd.org/cgi/man.cgi?query=rmlock |
---|
| 517 | |
---|
| 518 | POSIX r/w lock. |
---|
| 519 | |
---|
| 520 | === CONDVAR(9) (Condition variables) === |
---|
| 521 | |
---|
| 522 | http://www.freebsd.org/cgi/man.cgi?query=condvar |
---|
| 523 | |
---|
| 524 | POSIX condition variables with modifications (hack). |
---|
| 525 | |
---|
| 526 | === CALLOUT(9) (Timer functions) === |
---|
| 527 | |
---|
| 528 | http://www.freebsd.org/cgi/man.cgi?query=callout |
---|
| 529 | |
---|
| 530 | Timer server. |
---|
| 531 | |
---|
| 532 | === TASKQUEUE(9) (Asynchronous task execution) === |
---|
| 533 | |
---|
| 534 | http://www.freebsd.org/cgi/man.cgi?query=taskqueue |
---|
| 535 | |
---|
| 536 | TBD. |
---|
| 537 | |
---|
| 538 | === KTHREAD(9), KPROC(9) (Tasks) === |
---|
| 539 | |
---|
| 540 | http://www.freebsd.org/cgi/man.cgi?query=kthread |
---|
| 541 | |
---|
| 542 | http://www.freebsd.org/cgi/man.cgi?query=kproc |
---|
| 543 | |
---|
| 544 | Tasks. |
---|
| 545 | |
---|
| 546 | === ZONE(9) (Zone allocator) === |
---|
| 547 | |
---|
| 548 | http://www.freebsd.org/cgi/man.cgi?query=zone |
---|
| 549 | |
---|
| 550 | TBD. |
---|
| 551 | |
---|
| 552 | === devfs (Device file system) === |
---|
| 553 | |
---|
| 554 | Dummy, IMFS or new implementation (currently dummy). |
---|
| 555 | |
---|
| 556 | === psignal (Signals) === |
---|
| 557 | |
---|
| 558 | TBD. Seems to be not needed. |
---|
| 559 | |
---|
| 560 | === poll, select === |
---|
| 561 | |
---|
| 562 | TBD. Seems to be not needed. |
---|
| 563 | |
---|
| 564 | === RMAN(9) (Resource management) === |
---|
| 565 | |
---|
| 566 | http://www.freebsd.org/cgi/man.cgi?query=rman |
---|
| 567 | |
---|
| 568 | TBD. Seems to be not needed. |
---|
| 569 | |
---|
| 570 | === DEVCLASS(9), DEVICE(9), DRIVER(9), MAKE_DEV(9) (Device management) === |
---|
| 571 | |
---|
| 572 | http://www.freebsd.org/cgi/man.cgi?query=devclass |
---|
| 573 | |
---|
| 574 | http://www.freebsd.org/cgi/man.cgi?query=device |
---|
| 575 | |
---|
| 576 | http://www.freebsd.org/cgi/man.cgi?query=driver |
---|
| 577 | |
---|
| 578 | http://www.freebsd.org/cgi/man.cgi?query=make_dev |
---|
| 579 | |
---|
| 580 | Use FreeBSD implementation as far as possible. FreeBSD has a nice API for |
---|
| 581 | dynamic device handling. It may be interesting for RTEMS to use this API |
---|
| 582 | internally in the future. |
---|
| 583 | |
---|
| 584 | === BUS_SPACE(9), BUS_DMA(9) (Bus and DMA access) === |
---|
| 585 | |
---|
| 586 | http://www.freebsd.org/cgi/man.cgi?query=bus_space |
---|
| 587 | |
---|
| 588 | http://www.freebsd.org/cgi/man.cgi?query=bus_dma |
---|
| 589 | |
---|
| 590 | Likely BSP dependent. A default implementation for memory mapped linear access |
---|
| 591 | is easy to provide. The current heap implementation supports all properties |
---|
| 592 | demanded by bus_dma (including the boundary constraint). |
---|
[5ab1e1d] | 593 | |
---|
[7586492] | 594 | == RTEMS Replacements by File Description == |
---|
[5ab1e1d] | 595 | |
---|
| 596 | Note: Files with a status of USB are used by the USB test and have at least |
---|
| 597 | been partially tested. If they contain both USB and Nic, then they are used |
---|
| 598 | by both and MAY contain methods that have not been tested yet. Files that |
---|
| 599 | are only used by the Nic test are the most suspect. |
---|
| 600 | |
---|
[fb4c8a9] | 601 | [listing] |
---|
| 602 | ---- |
---|
[5ab1e1d] | 603 | rtems-libbsd File: rtems-bsd-assert.c |
---|
| 604 | FreeBSD File: rtems-bsd-config.h redefines BSD_ASSERT. |
---|
| 605 | Description: This file contains the support method rtems_bsd_assert_func(). |
---|
| 606 | Status: USB, Nic |
---|
| 607 | |
---|
| 608 | rtems-libbsd File: rtems-bsd-autoconf.c |
---|
| 609 | FreeBSD File: FreeBSD has BSP specific autoconf.c |
---|
| 610 | Description: This file contains configuration methods that are used to setup the system. |
---|
| 611 | Status: USB |
---|
| 612 | |
---|
| 613 | rtems-libbsd File: rtems-bsd-bus-dma.c |
---|
| 614 | FreeBSD File: FreeBSD has BSP specific busdma_machdep.c |
---|
| 615 | Description: |
---|
| 616 | Status: USB, Nic |
---|
| 617 | |
---|
| 618 | rtems-libbsd File: rtems-bsd-bus-dma-mbuf.c |
---|
| 619 | FreeBSD File: FreeBSD has BSP specific busdma_machdep.c |
---|
| 620 | Description: |
---|
| 621 | Status: Nic |
---|
| 622 | |
---|
| 623 | rtems-libbsd File: rtems-bsd-callout.c |
---|
| 624 | FreeBSD File: kern/kern_timeout.c |
---|
| 625 | Description: |
---|
| 626 | Status: USB, Nic |
---|
| 627 | |
---|
| 628 | rtems-libbsd File: rtems-bsd-cam.c |
---|
| 629 | FreeBSD File: cam/cam_sim.c |
---|
| 630 | Description: |
---|
| 631 | Status: USB |
---|
| 632 | |
---|
| 633 | rtems-libbsd File: rtems-bsd-condvar.c |
---|
| 634 | FreeBSD File: kern/kern_condvar.c |
---|
| 635 | Description: |
---|
| 636 | Status: USB |
---|
| 637 | |
---|
| 638 | rtems-libbsd File: rtems-bsd-copyinout.c |
---|
| 639 | FreeBSD File: bsp specific copyinout.c ) |
---|
| 640 | Description: Note: The FreeBSD file is split with some methods being in rtems-bsd-support |
---|
| 641 | Status: Nic |
---|
| 642 | |
---|
| 643 | rtems-libbsd File: rtems-bsd-delay.c |
---|
| 644 | FreeBSD File: bsp specific file with multiple names |
---|
| 645 | Description: |
---|
| 646 | Status: USB, Nic |
---|
| 647 | |
---|
| 648 | rtems-libbsd File: rtems-bsd-descrip.c |
---|
| 649 | FreeBSD File: kern/kern_descrip.c |
---|
| 650 | Description: |
---|
| 651 | Status: Nic |
---|
| 652 | |
---|
| 653 | rtems-libbsd File: rtems-bsd-generic.c |
---|
| 654 | FreeBSD File: kern/sys_generic.c |
---|
| 655 | Description: |
---|
| 656 | Status: Nic |
---|
| 657 | |
---|
| 658 | rtems-libbsd File: rtems-bsd-init.c |
---|
| 659 | FreeBSD File: N/A |
---|
| 660 | Description: |
---|
| 661 | Status: USB, Nic |
---|
| 662 | |
---|
| 663 | rtems-libbsd File: rtems-bsd-init-with-irq.c |
---|
| 664 | FreeBSD File: N/A |
---|
| 665 | Description: |
---|
| 666 | Status: USB, Nic |
---|
| 667 | |
---|
| 668 | rtems-libbsd File: rtems-bsd-jail.c |
---|
| 669 | FreeBSD File: kern/kern_jail.c |
---|
| 670 | Description: |
---|
| 671 | Status: USB, Nic |
---|
| 672 | |
---|
| 673 | rtems-libbsd File: rtems-bsd-lock.c |
---|
| 674 | FreeBSD File: kern/subr_lock.c |
---|
| 675 | Description: |
---|
| 676 | Status: USB, Nic |
---|
| 677 | |
---|
| 678 | rtems-libbsd File: rtems-bsd-log.c |
---|
| 679 | FreeBSD File: kern/subr_prf.c |
---|
| 680 | Description: |
---|
| 681 | Status: Nic |
---|
| 682 | |
---|
| 683 | rtems-libbsd File: rtems-bsd-malloc.c |
---|
| 684 | FreeBSD File: kern/kern_malloc.c |
---|
| 685 | Description: |
---|
| 686 | Status: USB, Nic |
---|
| 687 | |
---|
| 688 | rtems-libbsd File: rtems-bsd-mutex.c |
---|
| 689 | FreeBSD File: kern/kern_mutex.c |
---|
| 690 | Description: |
---|
| 691 | Status: USB, Nic |
---|
| 692 | |
---|
| 693 | rtems-libbsd File: rtems-bsd-newproc.c |
---|
| 694 | FreeBSD File: N/A |
---|
| 695 | Description: |
---|
| 696 | Status: Nic |
---|
| 697 | |
---|
| 698 | rtems-libbsd File: rtems-bsd-nexus.c |
---|
| 699 | FreeBSD File: bsp specific nexus.c |
---|
| 700 | Description: |
---|
| 701 | Status: USB |
---|
| 702 | |
---|
| 703 | rtems-libbsd File: rtems-bsd-panic.c |
---|
| 704 | FreeBSD File: boot/common/panic.c |
---|
| 705 | Description: |
---|
| 706 | Status: USB, Nic |
---|
| 707 | |
---|
| 708 | rtems-libbsd File: rtems-bsd-rwlock.c |
---|
| 709 | FreeBSD File: kern_rwlock.c |
---|
| 710 | Description: |
---|
| 711 | Status: USB, Nic |
---|
| 712 | |
---|
| 713 | rtems-libbsd File: rtems-bsd-shell.c |
---|
| 714 | FreeBSD File: N/A |
---|
| 715 | Description: |
---|
| 716 | Status: USB |
---|
| 717 | |
---|
| 718 | rtems-libbsd File: rtems-bsd-signal.c |
---|
| 719 | FreeBSD File: kern/kern_sig.c |
---|
| 720 | Description: |
---|
| 721 | Status: Nic |
---|
| 722 | |
---|
| 723 | rtems-libbsd File: rtems-bsd-smp.c |
---|
| 724 | FreeBSD File: N/A |
---|
| 725 | Description: |
---|
| 726 | Status: Nic |
---|
| 727 | |
---|
| 728 | rtems-libbsd File: rtems-bsd-support.c |
---|
| 729 | FreeBSD File: bsp specific copyinout.c |
---|
| 730 | Description: Note: the FreeBSD file is split with some methods being in rtems-bsd-copyinout. |
---|
| 731 | Status: USB, Nic |
---|
| 732 | |
---|
| 733 | rtems-libbsd File: rtems-bsd-sx.c |
---|
| 734 | FreeBSD File: kern/kern_sx.c |
---|
| 735 | Description: Status: USB, Nic |
---|
| 736 | |
---|
| 737 | rtems-libbsd File: rtems-bsd-synch.c |
---|
| 738 | FreeBSD File: kern/kern_synch.c |
---|
| 739 | Description: |
---|
| 740 | Status: USB, Nic |
---|
| 741 | |
---|
| 742 | rtems-libbsd File: rtems-bsd-syscalls.c |
---|
| 743 | FreeBSD File: User API for kern/uipc_syscalls.c |
---|
| 744 | Description: |
---|
| 745 | Status: Nic |
---|
| 746 | |
---|
| 747 | rtems-libbsd File: rtems-bsd-sysctlbyname.c |
---|
| 748 | FreeBSD File: User API for sysctlbyname(3) |
---|
| 749 | Description: |
---|
| 750 | Status: |
---|
| 751 | |
---|
| 752 | rtems-libbsd File: rtems-bsd-sysctl.c |
---|
| 753 | FreeBSD File: User API for sysctl(8) |
---|
| 754 | Description: |
---|
| 755 | Status: |
---|
| 756 | |
---|
| 757 | rtems-libbsd File: rtems-bsd-sysctlnametomib.c |
---|
| 758 | FreeBSD File: User API for sysctlnametomib |
---|
| 759 | Description: |
---|
| 760 | Status: |
---|
| 761 | |
---|
| 762 | rtems-libbsd File: rtems-bsd-taskqueue.c |
---|
| 763 | FreeBSD File: kern/subr_taskqueue.c |
---|
| 764 | Description: |
---|
| 765 | Status: Nic |
---|
| 766 | |
---|
| 767 | rtems-libbsd File: rtems-bsd-thread.c |
---|
| 768 | FreeBSD File: kern/kern_kthread.c |
---|
| 769 | Description: |
---|
| 770 | Status: USB, Nic |
---|
| 771 | |
---|
| 772 | rtems-libbsd File: rtems-bsd-timeout.c |
---|
| 773 | FreeBSD File: kern/kern_timeout.c |
---|
| 774 | Description: |
---|
| 775 | Status: Nic |
---|
| 776 | |
---|
| 777 | rtems-libbsd File: rtems-bsd-timesupport.c |
---|
| 778 | FreeBSD File: kern/kern_clock.c |
---|
| 779 | Description: |
---|
| 780 | Status: Nic |
---|
| 781 | |
---|
| 782 | rtems-libbsd File: rtems-bsd-vm_glue.c |
---|
| 783 | FreeBSD File: vm/vm_glue.c |
---|
| 784 | Description: |
---|
| 785 | Status: USB, Nic |
---|
[fb4c8a9] | 786 | ---- |
---|
| 787 | |
---|
| 788 | == Notes by File == |
---|
[7586492] | 789 | |
---|
[fb4c8a9] | 790 | altq_subr.c - Arbitrary choices were made in this file that RTEMS would |
---|
| 791 | not support tsc frequency change. Additionally, the clock frequency |
---|
| 792 | for machclk_freq is always measured for RTEMS. |
---|
| 793 | |
---|
| 794 | conf.h - In order to add make_dev and destroy_dev, variables in the cdev |
---|
| 795 | structure that were not being used were conditionally compiled out. The |
---|
| 796 | capability of supporting children did not appear to be needed and was |
---|
| 797 | not implemented in the rtems version of these routines. |
---|
| 798 | |
---|
[7586492] | 799 | == NICs Status == |
---|
| 800 | |
---|
[fb4c8a9] | 801 | [listing] |
---|
| 802 | ---- |
---|
[7586492] | 803 | Driver Symbol Status |
---|
| 804 | ====== ====== ====== |
---|
| 805 | RealTek _bsd_re_pcimodule_sys_init Links |
---|
| 806 | EtherExpress _bsd_fxp_pcimodule_sys_init Links |
---|
| 807 | DEC tulip _bsd_dc_pcimodule_sys_init Links |
---|
| 808 | Broadcom BCM57xxx _bsd_bce_pcimodule_sys_init Links |
---|
| 809 | Broadcom BCM4401 _bsd_bfe_pcimodule_sys_init Links |
---|
| 810 | Broadcom BCM570x _bsd_bge_pcimodule_sys_init Needs Symbols (A) |
---|
[fb4c8a9] | 811 | E1000 IGB _bsd_igb_pcimodule_sys_init Links |
---|
| 812 | E1000 EM _bsd_em_pcimodule_sys_init Links |
---|
| 813 | ---- |
---|
[7586492] | 814 | |
---|
| 815 | |
---|
| 816 | Symbols (A) |
---|
| 817 | pci_get_vpd_ident |
---|
[99dc0d7] | 818 | |
---|
| 819 | == Problems to report to FreeBSD == |
---|
| 820 | |
---|
| 821 | The MMAP_NOT_AVAILABLE define is inverted on its usage. When it is |
---|
| 822 | defined the mmap method is called. Additionally, it is not used |
---|
| 823 | thoroughly. It is not used in the unmap portion of the source. |
---|
[808a6b2] | 824 | The file rec_open.c uses the define MMAP_NOT_AVAILABLE to wrap |
---|
| 825 | the call to mmap and file rec_close.c uses the munmap method. |
---|
[99dc0d7] | 826 | |
---|
| 827 | |
---|
| 828 | |
---|