source: rtems-libbsd/libbsd.txt @ 14ba206

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 14ba206 was 14ba206, checked in by Sebastian Huber <sebastian.huber@…>, on 05/16/14 at 11:10:03

doc: Clarify test run

  • Property mode set to 100644
File size: 34.7 KB
Line 
1RTEMS BSD Library Guide
2=======================
3:toc:
4:icons:
5:numbered:
6:website: http://www.rtems.org/
7
8RTEMS uses FreeBSD 9.2 as the source of its TCP/IP and USB stacks.
9This is a guide which captures information on the
10process of merging code from FreeBSD, building this library,
11RTEMS specific support files, and general guidelines on what
12modifications to the FreeBSD source are permitted.
13
14Goals of this effort are
15
16* update TCP/IP and provide USB in RTEMS,
17* ease updating to future FreeBSD versions,
18* ease tracking changes in FreeBSD code,
19* minimize manual changes in FreeBSD code, and
20* define stable kernel/device driver API which is implemented
21by both RTEMS and FreeBSD. This is the foundation of the port.
22
23We will work to push our changes upstream to the FreeBSD Project
24and minimize changes required at each update point.
25
26*******************************************************************************
27This is a work in progress and is very likely to be incomplete.
28Please help by adding to it.
29*******************************************************************************
30
31== Getting Started
32
33=== Tool Chain ===
34
35You need a tool chain for RTEMS based on at least
36
37* Binutils 2.24, and
38* Newlib 2.1.0.
39
40The Binutils version is required to ease the handling of linker command files.
41The Newlib version is required since some standard files like `<sys/types.h>`
42must be compatible enough for the files provided by the FreeBSD sources, e.g.
43`<sys/socket.h>`.
44
45=== Installation Overview ===
46
47. You must configure your BSP with the +--disable-networking+ option to disable
48the old network stack.  Make sure no header files of the old network stack are
49installed.
50. Clone the Git repository +git clone git://git.rtems.org/rtems-libbsd.git+.
51. Change into the RTEMS BSD library root directory.
52. Edit the 'config.inc' Makefile configuration file and adjust it to your environment.
53. Run +make clean+.
54. Run +make install+.
55
56=== Board Support Package Requirements ===
57
58The RTEMS version must be at least 4.11.  The Board Support Package (BSP)
59should support the
60http://www.rtems.org/onlinedocs/doxygen/cpukit/html/group\__rtems\__interrupt__extension.html[Interrupt Manager Extension]
61// The first underscores have to be masked to stop asciidoc interpreting them
62to make use of generic FreeBSD based drivers.
63
64The linker command file of the BSP must contain the following section
65definitions:
66
67-------------------------------------------------------------------------------
68.rtemsroset : {
69        KEEP (*(SORT(.rtemsroset.*)))
70}
71
72.rtemsrwset : {
73        KEEP (*(SORT(.rtemsrwset.*)))
74}
75-------------------------------------------------------------------------------
76
77The first output section can be placed in read-only memory.  The second output
78section must be placed in read-write memory.  The output section name is not
79relevant.  The output sections may also contain other input sections.
80
81=== Board Support Package Configuration and Build ===
82
83You need to configure RTEMS for the desired BSP and install it.  The BSP should
84be configured with a disabled network stack.  The BSD library containing the
85new network stack is a separate package.  Using a BSP installation containing
86the old network stack may lead to confusion and unpredictable results.
87
88The following script is used to build the `arm/realview_pbx_a9_qemu` BSP for
89our internal testing purposes:
90
91-------------------------------------------------------------------------------
92#!/bin/sh
93
94cd ${HOME}/sandbox
95rm -rf b-realview_pbx_a9_qemu
96mkdir b-realview_pbx_a9_qemu
97cd b-realview_pbx_a9_qemu
98${HOME}/git-rtems/configure \
99        --prefix=${HOME}/sandbox/install \
100        --target=arm-rtems4.11 \
101        --enable-rtemsbsp=realview_pbx_a9_qemu \
102        --disable-networking && \
103        make && \
104        make install
105-------------------------------------------------------------------------------
106
107The `arm/realview_pbx_a9_qemu` BSP running on the Qemu simulator has some
108benefits for development and test of the BSD library
109
110* it offers a NULL pointer read and write protection,
111* Qemu is a fast simulator,
112* Qemu provides support for GDB watchpoints,
113* Qemu provides support for virtual Ethernet networks, e.g. TUN and bridge
114devices (you can run multiple test instances on one virtual network).
115
116=== BSD Library Configuration and Build ===
117
118In the BSD library source directory edit the file 'config.inc'.  Continuing on
119the above, the 'config.inc' used to match the above is:
120
121-------------------------------------------------------------------------------
122# Mandatory: Select your BSP and installation prefix
123TARGET = arm-rtems4.11
124BSP = realview_pbx_a9_qemu
125PREFIX = $(HOME)/sandbox/install
126
127# Optional: Separate installation base directory
128INSTALL_BASE = $(PREFIX)/$(TARGET)/$(BSP)
129
130# Optional: Network test configuration
131TEST_RUNNER = $(BSP)
132NET_CFG_SELF_IP = 10.0.0.2
133NET_CFG_NETMASK = 255.255.0.0
134NET_CFG_PEER_IP = 10.0.0.1
135NET_CFG_GATEWAY_IP = 10.0.0.1
136NET_TAP_INTERFACE = tap0
137-------------------------------------------------------------------------------
138
139Now you can build the BSD library and run the tests:
140
141-------------------------------------------------------------------------------
142make clean
143make
144make run_tests
145-------------------------------------------------------------------------------
146
147You can only run the tests directly in case a test runner is available.  The
148following tests run without an external network.  It is strongly advised to run
149them.
150
151* commands01
152* init01
153* loopback01
154* rwlock01
155* selectpollkqueue01
156* sleep01
157* swi01
158* syscalls01
159* thread01
160* timeout01
161* unix01
162
163To install the BSD library use this:
164
165-------------------------------------------------------------------------------
166make install
167-------------------------------------------------------------------------------
168
169=== BSD Library Initialization ===
170
171Use the following code to initialize the BSD library:
172
173-------------------------------------------------------------------------------
174#include <assert.h>
175
176#include <rtems/bsd/bsd.h>
177
178void do_init(void)
179{
180        rtems_status_code sc;
181
182        sc = rtems_bsd_initialize();
183        assert(sc == RTEMS_SUCCESSFUL);
184}
185-------------------------------------------------------------------------------
186
187== Network Stack Features
188
189http://roy.marples.name/projects/dhcpcd/index[DHCPCD(8)]:: DHCP client
190
191https://developer.apple.com/library/mac/documentation/Networking/Reference/DNSServiceDiscovery_CRef/Reference/reference.html[dns_sd.h]:: DNS Service Discovery
192
193http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-320.10/mDNSCore/mDNSEmbeddedAPI.h[mDNS]:: Multi-Cast DNS
194
195http://www.freebsd.org/cgi/man.cgi?query=unix&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[UNIX(4)]:: UNIX-domain protocol family
196
197http://www.freebsd.org/cgi/man.cgi?query=inet&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[INET(4)]:: Internet protocol family
198
199http://www.freebsd.org/cgi/man.cgi?query=inet6&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[INET6(4)]:: Internet protocol version 6 family
200
201http://www.freebsd.org/cgi/man.cgi?query=tcp&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[TCP(4)]:: Internet Transmission Control Protocol
202
203http://www.freebsd.org/cgi/man.cgi?query=udp&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[UDP(4)]:: Internet User Datagram Protocol
204
205http://www.freebsd.org/cgi/man.cgi?query=route&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[ROUTE(4)]:: Kernel packet forwarding database
206
207http://www.freebsd.org/cgi/man.cgi?query=bpf&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[BPF(4)]:: Berkeley Packet Filter
208
209http://www.freebsd.org/cgi/man.cgi?query=socket&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[SOCKET(2)]:: Create an endpoint for communication
210
211http://www.freebsd.org/cgi/man.cgi?query=kqueue&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[KQUEUE(2)]:: Kernel event notification mechanism
212
213http://www.freebsd.org/cgi/man.cgi?query=select&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[SELECT(2)]:: Synchronous I/O multiplexing
214
215http://www.freebsd.org/cgi/man.cgi?query=poll&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[POLL(2)]:: Synchronous I/O multiplexing
216
217http://www.freebsd.org/cgi/man.cgi?query=route&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[ROUTE(8)]:: Manually manipulate the routing tables
218
219http://www.freebsd.org/cgi/man.cgi?query=ifconfig&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[IFCONFIG(8)]:: Configure network interface parameters
220
221http://www.freebsd.org/cgi/man.cgi?query=netstat&apropos=0&sektion=1&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[NETSTAT(1)]:: Show network status
222
223http://www.freebsd.org/cgi/man.cgi?query=ping&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[PING(8)]:: Send ICMP ECHO_REQUEST packets to network hosts
224
225http://www.freebsd.org/cgi/man.cgi?query=ping6&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[PING6(8)]:: Send ICMPv6 ECHO_REQUEST packets to network hosts
226
227http://www.freebsd.org/cgi/man.cgi?query=sysctl&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[SYSCTL(3)]:: Get or set system information
228
229http://www.freebsd.org/cgi/man.cgi?query=resolver&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[RESOLVER(3)]:: Resolver routines
230
231http://www.freebsd.org/cgi/man.cgi?query=gethostbyname&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[GETHOSTBYNAME(3)]:: Get network host entry
232
233== Issues and TODO
234
235* Per-CPU data should be enabled once the new stack is ready for SMP.
236
237* Per-CPU NETISR(9) should be enabled onece the new stack is ready for SMP.
238
239* Multiple routing tables are not supported.  Every FIB value is set to zero
240  (= BSD_DEFAULT_FIB).
241
242* Process identifiers are not supported.  Every PID value is set to zero
243  (= BSD_DEFAULT_PID).
244
245* User credentials are not supported.  The following functions allow the
246  operation for everyone
247  - prison_equal_ip4(),
248  - chgsbsize(),
249  - cr_cansee(),
250  - cr_canseesocket() and
251  - cr_canseeinpcb().
252
253* A basic USB functionality test that is known to work on Qemu is desirable.
254
255* Adapt generic IRQ PIC interface code to Simple Vectored Interrupt Model
256  so that those architectures can use new TCP/IP and USB code.
257
258* freebsd-userspace/rtems/include/sys/syslog.h is a copy from the old
259  RTEMS TCP/IP stack. For some reason, the __printflike markers do not
260  compile in this environment. We may want to use the FreeBSD syslog.h
261  and get this addressed.
262
263* in_cksum implementations for architectures not supported by FreeBSD.
264  This will require figuring out where to put implementations that do
265  not originate from FreeBSD and are populated via the script.
266
267* MAC support functions are not thread-safe ("freebsd/lib/libc/posix1e/mac.c").
268
269* IFCONFIG(8): IEEE80211 support is disabled.  This module depends on a XML
270  parser and mmap().
271
272* get_cyclecount(): The implementation is a security problem.
273
274* What to do with the priority parameter present in the FreeBSD synchronization
275  primitives and the thread creation functions?
276
277* TASKQUEUE(9): Support spin mutexes.
278
279* ZONE(9): Review allocator lock usage in rtems-bsd-chunk.c.
280
281* KQUEUE(2): Choose proper lock for global kqueue list.
282
283* TIMEOUT(9): Maybe use special task instead of timer server to call
284  callout_tick().
285
286* sysctl_handle_opaque(): Implement reliable snapshots.
287
288* PING6(8): What to do with SIGALARM?
289
290* <sys/param.h>: Update Newlib to use a MSIZE of 256.
291
292* BPF(4): Add support for zero-copy buffers.
293
294* UNIX(4): Fix race conditions in the area of socket object and file node
295  destruction.  Add support for file descriptor transmission via control
296  messages.
297
298* PRINTF(9): Add support for log(), the %D format specifier is missing in the
299  normal printf() family.
300
301* Why is the interrupt server used?  The BSD interrupt handlers can block on
302synchronization primitives like mutexes.  This is in contrast to RTEMS
303interrupt service routines.  The BSPs using the generic interrupt support must
304implement the `bsp_interrupt_vector_enable()` and
305`bsp_interrupt_vector_disable()` routines.  They normally enable/disable a
306particular interrupt source at the interrupt controller.  This can be used to
307implement the interrupt server.  The interrupt server is a task that wakes-up
308in case an associated interrupt happens.  The interrupt source is disabled in
309a generic interrupt handler that wakes-up the interrupt server task.   Once the
310postponed interrupt processing is performed in the interrupt server the
311interrupt source is enabled again.
312
313* Convert all BSP linkcmds to use a linkcmds.base so the sections are
314easier to insert.
315
316* NIC Device Drivers
317- Only common PCI NIC drivers have been included in the initial set. These
318do not include any system on chip or ISA drivers.
319- PCI configuration probe does not appear to happen to determine if a
320NIC is in I/O or memory space. We have worked around this by using a
321static hint to tell the fxp driver the correct mode. But this needs to
322be addressed.
323- The ISA drivers require more BSD infrastructure to be addressed. This was
324outside the scope of the initial porting effort.
325
326== FreeBSD Source
327
328You should be able to rely on FreebSD manual pages and documentation
329for details on the code itself.
330
331=== Automatically Generated FreeBSD Files
332
333Some source and header files are automatically generated during the FreeBSD
334build process.  The `Makefile.todo` file performs this manually.  The should be
335included in `freebsd-to-rtems.py` script some time in the future.  For details,
336see also
337http://www.freebsd.org/cgi/man.cgi?query=kobj&sektion=9&apropos=0&manpath=FreeBSD+9.2-RELEASE[KOBJ(9)].
338
339=== Rules for Modifying FreeBSD Source
340
341Only add lines.  Subtract code by added `#ifndef __rtems__`.  This makes
342merging easier in the future.  For example:
343
344-------------------------------------------------------------------------------
345/* Global variables for the kernel. */
346
347#ifndef __rtems__
348/* 1.1 */
349extern char kernelname[MAXPATHLEN];
350#endif /* __rtems__ */
351
352extern int tick;                        /* usec per tick (1000000 / hz) */
353-------------------------------------------------------------------------------
354
355-------------------------------------------------------------------------------
356#if defined(_KERNEL) || defined(_WANT_FILE)
357#ifdef __rtems__
358#include <rtems/libio_.h>
359#include <sys/fcntl.h>
360#endif /* __rtems__ */
361/*
362 * Kernel descriptor table.
363 * One entry for each open kernel vnode and socket.
364 *
365 * Below is the list of locks that protects members in struct file.
366 *
367 * (f) protected with mtx_lock(mtx_pool_find(fp))
368 * (d) cdevpriv_mtx
369 * none not locked
370 */
371-------------------------------------------------------------------------------
372
373-------------------------------------------------------------------------------
374extern int profprocs;                   /* number of process's profiling */
375#ifndef __rtems__
376extern volatile int ticks;
377#else /* __rtems__ */
378#include <rtems/score/watchdogimpl.h>
379#define ticks _Watchdog_Ticks_since_boot
380#endif /* __rtems__ */
381
382#endif /* _KERNEL */
383-------------------------------------------------------------------------------
384
385Add nothing (even blank lines) before or after the `__rtems__` guards.  Always
386include a `__rtems__` in the guards to make searches easy.
387
388== BSD Library Source
389
390=== What is in the Git Repository
391
392There is a self-contained kit with FreeBSD and RTEMS components pre-merged. The
393Makefile in this kit is automatically generated.
394
395Any changes to source in the `freebsd` directories will need to be merged
396upstream into our master FreeBSD checkout, the `freebsd-org` submodule.
397
398The repository contains two FreeBSD source trees.  In the `freebsd` directory
399are the so called 'managed' FreeBSD sources used to build the BSD library.  The
400FreeBSD source in `freebsd-org` is the 'master' version.  The
401`freebsd-to-rtems.py` script is used to transfer files between the two trees.
402In general terms, if you have modified managed FreeBSD sources, you will need
403to run the script in 'revert' or 'reverse' mode using the `-R` switch.  This
404will copy the source back to your local copy of the master FreeBSD source so
405you can run `git diff` against the upstream FreeBSD source.  If you want to
406transfer source files from the master FreeBSD source to the manged FreeBSD
407sources, then you must run the script in 'forward' mode (the default).
408
409=== Organization
410
411The top level directory contains a few directories and files. The following
412are important to understand
413
414* `freebsd-to-rtems.py` - script to convert to and free FreeBSD and RTEMS trees,
415* `Makefile` - automatically generated,
416* `freebsd/` - from FreeBSD by script,
417* `rtemsbsd/` - RTEMS specific implementations of FreeBSD kernel support routines,
418* `testsuite/` - RTEMS specific tests, and
419* `libbsd.txt` - documentation in Asciidoc.
420
421== Moving Code Between Managed and Master FreeBSD Source
422
423The script `freebsd-to-rtems.py` is used to copy code from FreeBSD to the
424rtems-libbsd tree and to reverse this process. This script attempts to
425automate this process as much as possible and performs some transformations
426on the FreeBSD code. Its command line arguments are shown below:
427
428----
429freebsd-to-rtems.py [args]
430  -?|-h|--help     print this and exit
431  -d|--dry-run     run program but no modifications
432  -D|--diff        provide diff of files between trees
433  -e|--early-exit  evaluate arguments, print results, and exit
434  -m|--makefile    just generate Makefile
435  -R|--reverse     default FreeBSD -> RTEMS, reverse that
436  -r|--rtems       RTEMS directory
437  -f|--freebsd     FreeBSD directory
438  -v|--verbose     enable verbose output mode
439----
440
441In its default mode of operation, freebsd-to-rtems.py is used to copy code
442from FreeBSD to the rtems-libbsd tree and perform transformations.  In forward
443mode, the script may be requested to just generate the Makefile.
444
445In "reverse mode", this script undoes those transformations and copies
446the source code back to the FreeBSD SVN tree. This allows us to do
447'svn diff', evaluate changes made by the RTEMS Project, and report changes
448back to FreeBSD upstream.
449
450In either mode, the script may be asked to perform a dry-run or be verbose.
451Also, in either mode, the script is also smart enough to avoid copying over
452files which have not changed. This means that the timestamps of files are
453not changed unless the contents change. The script will also report the
454number of files which changed. In verbose mode, the script will print
455the name of the files which are changed.
456
457The following is an example forward run with no changes.
458
459----
460$ ~/newbsd/git/libbsd-8.2/freebsd-to-rtems.py \
461    -r /home/joel/newbsd/git/libbsd-8.2 \
462    -f /home/joel/newbsd/libbsd/freebsd-8.2 -v
463Verbose:                yes
464Dry Run:                no
465Only Generate Makefile: no
466RTEMS Directory:        /home/joel/newbsd/git/libbsd-8.2
467FreeBSD Directory:      /home/joel/newbsd/libbsd/freebsd-8.2
468Direction:              forward
469Generating into /home/joel/newbsd/git/libbsd-8.2
4700 files were changed.
471----
472
473The script may also be used to generate a diff in either forward or reverse
474direction.
475
476== Initialization of the BSD Library
477
478The initialization of the BSD library is based on the FreeBSD SYSINIT(9)
479infrastructure.  The key to initializing a system is to ensure that the desired
480device drivers are explicitly pulled into the linked application.  This plus
481linking against the BSD library (`libbsd.a`) will pull in the necessary FreeBSD
482infrastructure.
483
484The FreeBSD kernel is not a library like the RTEMS kernel.  It is a bunch of
485object files linked together.  If we have a library, then creating the
486executable is simple.  We begin with a start symbol and recursively resolve all
487references.  With a bunch of object files linked together we need a different
488mechanism.  Most object files don't know each other.  Lets say we have a driver
489module.  The rest of the system has no references to this driver module.  The
490driver module needs a way to tell the rest of the system: Hey, kernel I am
491here, please use my services!
492
493This registration of independent components is performed by SYSINIT(9) and
494specializations:
495
496http://www.freebsd.org/cgi/man.cgi?query=SYSINIT
497
498The SYSINIT(9) uses some global data structures that are placed in a certain
499section.  In the linker command file we need this:
500
501-------------------------------------------------------------------------------
502.rtemsroset : {
503        KEEP (*(SORT(.rtemsroset.*)))
504}
505
506.rtemsrwset : {
507        KEEP (*(SORT(.rtemsrwset.*)))
508}
509-------------------------------------------------------------------------------
510
511This results for example in this executable layout:
512
513-------------------------------------------------------------------------------
514[...]
515 *(SORT(.rtemsroset.*))
516 .rtemsroset.bsd.modmetadata_set.begin
517                0x000000000025fe00        0x0 libbsd.a(rtems-bsd-init.o)
518                0x000000000025fe00                _bsd__start_set_modmetadata_set
519 .rtemsroset.bsd.modmetadata_set.content
520                0x000000000025fe00        0x8 libbsd.a(rtems-bsd-nexus.o)
521 .rtemsroset.bsd.modmetadata_set.content
522                0x000000000025fe08        0x4 libbsd.a(kern_module.o)
523[...]
524 .rtemsroset.bsd.modmetadata_set.content
525                0x000000000025fe68        0x4 libbsd.a(mii.o)
526 .rtemsroset.bsd.modmetadata_set.content
527                0x000000000025fe6c        0x4 libbsd.a(mii_bitbang.o)
528 .rtemsroset.bsd.modmetadata_set.end
529                0x000000000025fe70        0x0 libbsd.a(rtems-bsd-init.o)
530                0x000000000025fe70                _bsd__stop_set_modmetadata_set
531[...]
532.rtemsrwset     0x000000000030bad0      0x290
533 *(SORT(.rtemsrwset.*))
534 .rtemsrwset.bsd.sysinit_set.begin
535                0x000000000030bad0        0x0 libbsd.a(rtems-bsd-init.o)
536                0x000000000030bad0                _bsd__start_set_sysinit_set
537 .rtemsrwset.bsd.sysinit_set.content
538                0x000000000030bad0        0x4 libbsd.a(rtems-bsd-nexus.o)
539 .rtemsrwset.bsd.sysinit_set.content
540                0x000000000030bad4        0x8 libbsd.a(rtems-bsd-thread.o)
541 .rtemsrwset.bsd.sysinit_set.content
542                0x000000000030badc        0x4 libbsd.a(init_main.o)
543[...]
544 .rtemsrwset.bsd.sysinit_set.content
545                0x000000000030bd54        0x4 libbsd.a(frag6.o)
546 .rtemsrwset.bsd.sysinit_set.content
547                0x000000000030bd58        0x8 libbsd.a(uipc_accf.o)
548 .rtemsrwset.bsd.sysinit_set.end
549                0x000000000030bd60        0x0 libbsd.a(rtems-bsd-init.o)
550                0x000000000030bd60                _bsd__stop_set_sysinit_set
551[...]
552-------------------------------------------------------------------------------
553
554Here you can see, that some global data structures are collected into
555continuous memory areas.  This memory area can be identified by start and stop
556symbols.  This constructs a table of uniform items.
557
558The low level FreeBSD code calls at some time during the initialization the
559mi_startup() function (machine independent startup).  This function will sort
560the SYSINIT(9) set and call handler functions which perform further
561initialization.  The last step is the scheduler invocation.
562
563The SYSINIT(9) routines are run in mi_startup() which is called by
564rtems_bsd_initialize().
565
566This is also explained in "The Design and Implementation of the FreeBSD
567Operating System" section 14.3 "Kernel Initialization".
568
569In RTEMS we have a library and not a bunch of object files.  Thus we need a way
570to pull-in the desired services out of the libbsd.  Here the
571`rtems-bsd-sysinit.h` comes into play.  The SYSINIT(9) macros have been
572modified and extended for RTEMS in `<sys/kernel.h>`:
573
574-------------------------------------------------------------------------------
575#ifndef __rtems__
576#define C_SYSINIT(uniquifier, subsystem, order, func, ident)    \
577        static struct sysinit uniquifier ## _sys_init = {       \
578                subsystem,                                      \
579                order,                                          \
580                func,                                           \
581                (ident)                                         \
582        };                                                      \
583        DATA_SET(sysinit_set,uniquifier ## _sys_init)
584#else /* __rtems__ */
585#define SYSINIT_ENTRY_NAME(uniquifier)                          \
586        _bsd_ ## uniquifier ## _sys_init
587#define SYSINIT_REFERENCE_NAME(uniquifier)                      \
588        _bsd_ ## uniquifier ## _sys_init_ref
589#define C_SYSINIT(uniquifier, subsystem, order, func, ident)    \
590        struct sysinit SYSINIT_ENTRY_NAME(uniquifier) = {       \
591                subsystem,                                      \
592                order,                                          \
593                func,                                           \
594                (ident)                                         \
595        };                                                      \
596        RWDATA_SET(sysinit_set,SYSINIT_ENTRY_NAME(uniquifier))
597#define SYSINIT_REFERENCE(uniquifier)                           \
598        extern struct sysinit SYSINIT_ENTRY_NAME(uniquifier);   \
599        static struct sysinit const * const                     \
600        SYSINIT_REFERENCE_NAME(uniquifier) __used               \
601        = &SYSINIT_ENTRY_NAME(uniquifier)
602#define SYSINIT_MODULE_REFERENCE(mod)                           \
603        SYSINIT_REFERENCE(mod ## module)
604#define SYSINIT_DRIVER_REFERENCE(driver, bus)                   \
605        SYSINIT_MODULE_REFERENCE(driver ## _ ## bus)
606#define SYSINIT_DOMAIN_REFERENCE(dom)                           \
607        SYSINIT_REFERENCE(domain_add_ ## dom)
608#endif /* __rtems__ */
609-------------------------------------------------------------------------------
610
611Here you see that the SYSINIT(9) entries are no longer static.  The
612\*_REFERENCE() macros will create references to the corresponding modules which
613are later resolved by the linker.  The application has to provide an object
614file with references to all required FreeBSD modules.
615
616The FreeBSD device model is quite elaborated (with follow-ups):
617
618http://www.freebsd.org/cgi/man.cgi?query=driver
619
620The devices form a tree with the Nexus device at a high-level.  This Nexus
621device is architecture specific in FreeBSD.  In RTEMS we have our own Nexus
622device, see `rtemsbsd/bsp/bsp-bsd-nexus-devices.c`.
623
624=== SYSCTL_NODE Example
625
626During development, we had an undefined reference to
627_bsd_sysctl__net_children that we had trouble tracking down. Thanks to
628Chris Johns, we located it. He explained how to read SYSCTL_NODE
629definitions. This line from freebsd/netinet/in_proto.c is attempting
630to add the "inet" node to the parent node "_net".
631
632----
633SYSCTL_NODE(_net,      PF_INET,         inet,   CTLFLAG_RW, 0,
634        "Internet Family");
635----
636
637Our problem was that we could not find where _bsd_sysctl__net_children
638was defined. Chris suggested that when in doubt compile with -save-temps
639and look at the preprocessed .i files. But he did not need that. He
640explained that this the symbol name _bsd_sysctl__net_children was
641automatically generated by a SYSCTL_NODE as follows:
642
643* _bsd_ - added by RTEMS modifications to SYSCTL_NODE macro
644* sysctl_ - boilerplace added by SYSCTL_NODE macro
645* "" - empty string for parent node
646* net - name of SYSCTL_NODE
647* children - added by SYSCTL macros
648 
649This was all generated by a support macro declaring the node as this:
650
651----
652struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name);
653----
654
655Given this information, we located this SYSCTL_NODE declaration in
656kern/kern_mib.c
657
658----
659SYSCTL_NODE(, CTL_KERN,   kern,   CTLFLAG_RW, 0,
660        "High kernel, proc, limits &c");
661----
662
663== Core FreeBSD APIs and RTEMS Replacements ==
664
665=== SX(9) (Shared/exclusive locks) ===
666
667http://www.freebsd.org/cgi/man.cgi?query=sx
668
669Binary semaphores (this neglects the ability to allow shared access).
670
671=== MUTEX(9) (Mutual exclusion) ===
672
673http://www.freebsd.org/cgi/man.cgi?query=mutex
674
675Binary semaphores (not recursive mutexes are not supported this way).
676
677=== RWLOCK(9) (Reader/writer lock) ===
678
679http://www.freebsd.org/cgi/man.cgi?query=rwlock
680
681POSIX r/w lock.
682
683=== RMLOCK(9) (Reader/writer lock optimized for mostly read access patterns) ===
684
685Note:  This object was implemented as a wrapper for RWLOCK in the rm_lock header file.
686
687http://www.freebsd.org/cgi/man.cgi?query=rmlock
688
689POSIX r/w lock.
690
691=== CONDVAR(9) (Condition variables) ===
692
693http://www.freebsd.org/cgi/man.cgi?query=condvar
694
695POSIX condition variables with modifications (hack).
696
697=== CALLOUT(9) (Timer functions) ===
698
699http://www.freebsd.org/cgi/man.cgi?query=callout
700
701Timer server.
702
703=== TASKQUEUE(9) (Asynchronous task execution) ===
704
705http://www.freebsd.org/cgi/man.cgi?query=taskqueue
706
707TBD.
708
709=== KTHREAD(9), KPROC(9) (Tasks) ===
710
711http://www.freebsd.org/cgi/man.cgi?query=kthread
712
713http://www.freebsd.org/cgi/man.cgi?query=kproc
714
715Tasks.
716
717=== ZONE(9) (Zone allocator) ===
718
719http://www.freebsd.org/cgi/man.cgi?query=zone
720
721TBD.
722
723=== devfs (Device file system) ===
724
725Dummy, IMFS or new implementation (currently dummy).
726
727=== psignal (Signals) ===
728
729TBD.  Seems to be not needed.
730
731=== poll, select ===
732
733TBD.  Seems to be not needed.
734
735=== RMAN(9) (Resource management) ===
736
737http://www.freebsd.org/cgi/man.cgi?query=rman
738
739TBD.  Seems to be not needed.
740
741=== DEVCLASS(9), DEVICE(9), DRIVER(9), MAKE_DEV(9) (Device management) ===
742
743http://www.freebsd.org/cgi/man.cgi?query=devclass
744
745http://www.freebsd.org/cgi/man.cgi?query=device
746
747http://www.freebsd.org/cgi/man.cgi?query=driver
748
749http://www.freebsd.org/cgi/man.cgi?query=make_dev
750
751Use FreeBSD implementation as far as possible.  FreeBSD has a nice API for
752dynamic device handling.  It may be interesting for RTEMS to use this API
753internally in the future.
754
755=== BUS_SPACE(9), BUS_DMA(9) (Bus and DMA access) ===
756
757http://www.freebsd.org/cgi/man.cgi?query=bus_space
758
759http://www.freebsd.org/cgi/man.cgi?query=bus_dma
760
761Likely BSP dependent.  A default implementation for memory mapped linear access
762is easy to provide.  The current heap implementation supports all properties
763demanded by bus_dma (including the boundary constraint).
764
765== RTEMS Replacements by File Description ==
766
767Note:  Files with a status of USB are used by the USB test and have at least
768been partially tested.  If they contain both USB and Nic, then they are used
769by both and MAY contain methods that have not been tested yet.  Files that
770are only used by the Nic test are the most suspect.
771
772----
773rtems-libbsd File:      rtems-bsd-assert.c
774FreeBSD File:           rtems-bsd-config.h redefines BSD_ASSERT.
775Description:            This file contains the support method rtems_bsd_assert_func().
776Status:                 USB, Nic
777
778rtems-libbsd File:      rtems-bsd-autoconf.c
779FreeBSD File:           FreeBSD has BSP specific autoconf.c
780Description:            This file contains configuration methods that are used to setup the system.
781Status:                 USB
782
783rtems-libbsd File:      rtems-bsd-bus-dma.c
784FreeBSD File:           FreeBSD has BSP specific busdma_machdep.c
785Description:           
786Status:                 USB, Nic
787
788rtems-libbsd File:      rtems-bsd-bus-dma-mbuf.c       
789FreeBSD File:           FreeBSD has BSP specific busdma_machdep.c
790Description:           
791Status:                 Nic
792
793rtems-libbsd File:      rtems-bsd-callout.c             
794FreeBSD File:           kern/kern_timeout.c
795Description:           
796Status:                 USB, Nic
797
798rtems-libbsd File:      rtems-bsd-cam.c
799FreeBSD File:           cam/cam_sim.c
800Description:           
801Status:                 USB
802
803rtems-libbsd File:      rtems-bsd-condvar.c             
804FreeBSD File:           kern/kern_condvar.c
805Description:           
806Status:                 USB
807
808rtems-libbsd File:      rtems-bsd-copyinout.c
809FreeBSD File:           bsp specific copyinout.c )
810Description:            Note: The FreeBSD file is split with some methods being in rtems-bsd-support
811Status:                 Nic
812
813rtems-libbsd File:      rtems-bsd-delay.c
814FreeBSD File:           bsp specific file with multiple names
815Description:           
816Status:                 USB, Nic
817
818rtems-libbsd File:      rtems-bsd-descrip.c
819FreeBSD File:           kern/kern_descrip.c
820Description:           
821Status:                 Nic
822
823rtems-libbsd File:      rtems-bsd-generic.c             
824FreeBSD File:           kern/sys_generic.c
825Description:           
826Status:                 Nic
827
828rtems-libbsd File:      rtems-bsd-init.c
829FreeBSD File:           N/A
830Description:           
831Status:                 USB, Nic
832
833rtems-libbsd File:      rtems-bsd-init-with-irq.c
834FreeBSD File:           N/A
835Description:           
836Status:                 USB, Nic
837
838rtems-libbsd File:      rtems-bsd-jail.c
839FreeBSD File:           kern/kern_jail.c
840Description:           
841Status:                 USB, Nic
842
843rtems-libbsd File:      rtems-bsd-lock.c
844FreeBSD File:           kern/subr_lock.c
845Description:           
846Status:                 USB, Nic
847
848rtems-libbsd File:      rtems-bsd-log.c         
849FreeBSD File:           kern/subr_prf.c
850Description:           
851Status:                 Nic
852
853rtems-libbsd File:      rtems-bsd-malloc.c
854FreeBSD File:           kern/kern_malloc.c
855Description:           
856Status:                 USB, Nic
857
858rtems-libbsd File:      rtems-bsd-mutex.c
859FreeBSD File:           kern/kern_mutex.c
860Description:           
861Status:                 USB, Nic
862
863rtems-libbsd File:      rtems-bsd-newproc.c
864FreeBSD File:           N/A
865Description:           
866Status:                 Nic
867
868rtems-libbsd File:      rtems-bsd-nexus.c
869FreeBSD File:           bsp specific nexus.c
870Description:           
871Status:                 USB
872
873rtems-libbsd File:      rtems-bsd-panic.c               
874FreeBSD File:           boot/common/panic.c
875Description:           
876Status:                 USB, Nic
877
878rtems-libbsd File:      rtems-bsd-rwlock.c             
879FreeBSD File:           kern_rwlock.c
880Description:           
881Status:                 USB, Nic
882
883rtems-libbsd File:      rtems-bsd-shell.c               
884FreeBSD File:           N/A
885Description:           
886Status:                 USB
887
888rtems-libbsd File:      rtems-bsd-signal.c             
889FreeBSD File:           kern/kern_sig.c
890Description:           
891Status:                 Nic
892
893rtems-libbsd File:      rtems-bsd-smp.c                 
894FreeBSD File:           N/A
895Description:           
896Status:                 Nic
897
898rtems-libbsd File:      rtems-bsd-support.c             
899FreeBSD File:           bsp specific copyinout.c
900Description:            Note: the FreeBSD file is split with some methods being in rtems-bsd-copyinout.
901Status:                 USB, Nic
902
903rtems-libbsd File:      rtems-bsd-sx.c                 
904FreeBSD File:           kern/kern_sx.c
905Description:            Status: USB, Nic
906
907rtems-libbsd File:      rtems-bsd-synch.c               
908FreeBSD File:           kern/kern_synch.c
909Description:           
910Status:                 USB, Nic
911
912rtems-libbsd File:      rtems-bsd-syscalls.c           
913FreeBSD File:           User API for kern/uipc_syscalls.c
914Description:           
915Status:                 Nic
916
917rtems-libbsd File:      rtems-bsd-sysctlbyname.c       
918FreeBSD File:           User API for sysctlbyname(3)
919Description:           
920Status:
921
922rtems-libbsd File:      rtems-bsd-sysctl.c             
923FreeBSD File:           User API for sysctl(8)
924Description:           
925Status:
926
927rtems-libbsd File:      rtems-bsd-sysctlnametomib.c     
928FreeBSD File:           User API for sysctlnametomib
929Description:           
930Status:
931
932rtems-libbsd File:      rtems-bsd-taskqueue.c           
933FreeBSD File:           kern/subr_taskqueue.c
934Description:           
935Status:                 Nic
936
937rtems-libbsd File:      rtems-bsd-thread.c                     
938FreeBSD File:           kern/kern_kthread.c
939Description:           
940Status:                 USB, Nic
941
942rtems-libbsd File:      rtems-bsd-timeout.c             
943FreeBSD File:           kern/kern_timeout.c
944Description:           
945Status:                 Nic
946
947rtems-libbsd File:      rtems-bsd-timesupport.c         
948FreeBSD File:           kern/kern_clock.c
949Description:           
950Status:                 Nic
951
952rtems-libbsd File:      rtems-bsd-vm_glue.c             
953FreeBSD File:           vm/vm_glue.c
954Description:           
955Status:                 USB, Nic
956----
957
958== Notes by File ==
959
960altq_subr.c - Arbitrary choices were made in this file that RTEMS would
961not support tsc frequency change.  Additionally, the clock frequency
962for machclk_freq is always measured for RTEMS.
963
964conf.h - In order to add make_dev and destroy_dev, variables in the cdev
965structure that were not being used were conditionally compiled out. The
966capability of supporting children did not appear to be needed and was
967not implemented in the rtems version of these routines.
968 
969== NICs Status ==
970
971----
972Driver                  Symbol                          Status
973======                  ======                          ======
974RealTek                 _bsd_re_pcimodule_sys_init      Links
975EtherExpress            _bsd_fxp_pcimodule_sys_init     Links
976DEC tulip               _bsd_dc_pcimodule_sys_init      Links
977Broadcom BCM57xxx       _bsd_bce_pcimodule_sys_init     Links
978Broadcom BCM4401        _bsd_bfe_pcimodule_sys_init     Links
979Broadcom BCM570x        _bsd_bge_pcimodule_sys_init     Needs Symbols (A)
980E1000 IGB               _bsd_igb_pcimodule_sys_init     Links
981E1000 EM                _bsd_em_pcimodule_sys_init      Links
982----
983
984
985Symbols (A)
986         pci_get_vpd_ident
987 
988== Problems to report to FreeBSD ==
989
990The MMAP_NOT_AVAILABLE define is inverted on its usage.  When it is
991defined the mmap method is called. Additionally, it is not used
992thoroughly. It is not used in the unmap portion of the source.
993The file rec_open.c uses the define MMAP_NOT_AVAILABLE to wrap
994the call to mmap and file rec_close.c uses the munmap method.
995
996
997
Note: See TracBrowser for help on using the repository browser.