source: rtems-libbsd/libbsd.txt @ ead7fdc

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

doc: Clarify initialization

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