Changeset 4c3433b in rtems-libbsd for libbsd.txt


Ignore:
Timestamp:
01/24/14 15:37:21 (10 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, 5-freebsd-12, 6-freebsd-12, freebsd-9.3, master
Children:
821ae67
Parents:
bc78466
git-author:
Sebastian Huber <sebastian.huber@…> (01/24/14 15:37:21)
git-committer:
Sebastian Huber <sebastian.huber@…> (01/30/14 15:23:05)
Message:

Documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libbsd.txt

    rbc78466 r4c3433b  
    1 RTEMS BSD USB and TCP/IP Developers Guide
    2 =========================================
    3 Joel Sherrill <joel.sherrill@oarcorp.com>
    4 :Author Initials: JRS
     1RTEMS BSD Library Guide
     2=======================
    53:toc:
    64:icons:
     
    86:website: http://www.rtems.org/
    97
    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
     8RTEMS uses FreeBSD 9.2 as the source of its TCP/IP and USB stacks.
     9This is a guide which captures information on the
    1210process of merging code from FreeBSD, building this library,
    1311RTEMS specific support files, and general guidelines on what
    1412modifications to the FreeBSD source are permitted.
    1513
    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
     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
    2321by both RTEMS and FreeBSD. This is the foundation of the port.
    2422
     
    2624and minimize changes required at each update point.
    2725
    28 **************************************************************
     26*******************************************************************************
    2927This is a work in progress and is very likely to be incomplete.
    3028Please help by adding to it.
    31 **************************************************************
    32 
    33 == Source Code Version Information
    34 
    35 * FreeBSD 8.2 SVN r255967
    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 
    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
    47 
    48 == Issues and To Do
     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=== Board Support Package Requirements ===
     46
     47The RTEMS version must be at least 4.11.  The Board Support Package (BSP)
     48should support the
     49http://www.rtems.org/onlinedocs/doxygen/cpukit/html/group__rtems__interrupt__extension.html[Interrupt Manager Extension]
     50to make use of generic FreeBSD based drivers.
     51
     52The linker command file of the BSP must contain the following sections:
     53
     54-------------------------------------------------------------------------------
     55.rtemsroset : {
     56        KEEP (*(SORT(.rtemsroset.*)))
     57}
     58
     59.rtemsrwset : {
     60        KEEP (*(SORT(.rtemsrwset.*)))
     61}
     62-------------------------------------------------------------------------------
     63
     64The first section can be placed in read-only memory.  The section section must
     65be placed in read-write memory.
     66
     67=== Board Support Package Configuration and Build ===
     68
     69You need to configure RTEMS for the desired BSP and install it.  The BSP should
     70be configured with a disabled network stack.  The BSD library containing the
     71new network stack is a separate package.  Using a BSP installation containing
     72the old network stack may lead to confusion and unpredictable results.
     73
     74The following script is used to build the `arm/realview_pbx_a9_qemu` BSP for
     75our internal testing purposes:
     76
     77-------------------------------------------------------------------------------
     78#!/bin/sh
     79
     80cd ${HOME}/sandbox
     81rm -rf b-realview_pbx_a9_qemu
     82mkdir b-realview_pbx_a9_qemu
     83cd b-realview_pbx_a9_qemu
     84${HOME}/git-rtems/configure \
     85        --prefix=${HOME}/sandbox/install \
     86        --target=arm-rtems4.11 \
     87        --enable-rtemsbsp=realview_pbx_a9_qemu \
     88        --disable-networking && \
     89        make && \
     90        make install
     91-------------------------------------------------------------------------------
     92
     93The `arm/realview_pbx_a9_qemu` BSP running on the Qemu simulator has some
     94benefits for development and test of the BSD library
     95
     96* it offers a NULL pointer read and write protection,
     97* Qemu is a fast simulator,
     98* Qemu provides support for GDB watchpoints,
     99* Qemu provides support for virtual Ethernet networks, e.g. TUN and bridge
     100devices (you can run multiple test instances on one virtual network).
     101
     102=== BSD Library Configuration and Build ===
     103
     104In the BSD library source directory edit the file 'config.inc'.  Continuing on
     105the above, the 'config.inc' used to match the above is:
     106
     107-------------------------------------------------------------------------------
     108# Mandatory: Select your BSP and installation prefix
     109TARGET = arm-rtems4.11
     110BSP = realview_pbx_a9_qemu
     111PREFIX = $(HOME)/sandbox/install
     112
     113# Optional: Separate installation base directory
     114INSTALL_BASE = $(PREFIX)/$(TARGET)/$(BSP)
     115
     116# Optional: Network test configuration
     117TEST_RUNNER = $(BSP)
     118NET_CFG_SELF_IP = 10.0.0.2
     119NET_CFG_NETMASK = 255.255.0.0
     120NET_CFG_PEER_IP = 10.0.0.1
     121NET_CFG_GATEWAY_IP = 10.0.0.1
     122NET_TAP_INTERFACE = tap0
     123-------------------------------------------------------------------------------
     124
     125Now you can build the BSD library and run the tests:
     126
     127-------------------------------------------------------------------------------
     128make clean
     129make
     130make run_tests
     131-------------------------------------------------------------------------------
     132
     133To install the BSD library use this:
     134
     135-------------------------------------------------------------------------------
     136make install
     137-------------------------------------------------------------------------------
     138
     139=== BSD Library Initialization ===
     140
     141Use the following code to initialize the BSD library:
     142
     143-------------------------------------------------------------------------------
     144#include <assert.h>
     145
     146#include <rtems/bsd/bsd.h>
     147
     148void do_init(void)
     149{
     150        rtems_status_code sc;
     151
     152        sc = rtems_bsd_initialize();
     153        assert(sc == RTEMS_SUCCESSFUL);
     154}
     155-------------------------------------------------------------------------------
     156
     157== Network Stack Features
     158
     159http://roy.marples.name/projects/dhcpcd/index[DHCPCD(8)]:: DHCP client
     160
     161https://developer.apple.com/library/mac/documentation/Networking/Reference/DNSServiceDiscovery_CRef/Reference/reference.html[dns_sd.h]:: DNS Service Discovery
     162
     163http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-320.10/mDNSCore/mDNSEmbeddedAPI.h[mDNS]:: Multi-Cast DNS
     164
     165http://www.freebsd.org/cgi/man.cgi?query=unix&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[UNIX(4)]:: UNIX-domain protocol family
     166
     167http://www.freebsd.org/cgi/man.cgi?query=inet&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[INET(4)]:: Internet protocol family
     168
     169http://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
     170
     171http://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
     172
     173http://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
     174
     175http://www.freebsd.org/cgi/man.cgi?query=route&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[ROUTE(4)]:: Kernel packet forwarding database
     176
     177http://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
     178
     179http://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
     180
     181http://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
     182
     183http://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
     184
     185http://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
     186
     187http://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
     188
     189http://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
     190
     191http://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
     192
     193http://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
     194
     195http://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
     196
     197http://www.freebsd.org/cgi/man.cgi?query=sysctl&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[SYSCTL(3)]:: Get or set system information
     198
     199http://www.freebsd.org/cgi/man.cgi?query=resolver&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[RESOLVER(3)]:: Resolver routines
     200
     201http://www.freebsd.org/cgi/man.cgi?query=gethostbyname&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[GETHOSTBYNAME(3)]:: Get network host entry
     202
     203== Issues and TODO
     204
    49205* Per-CPU data should be enabled once the new stack is ready for SMP.
    50206
     
    65221  - cr_canseeinpcb().
    66222
    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.
     223* A basic USB functionality test that is known to work on Qemu is desirable.
    69224
    70225* Adapt generic IRQ PIC interface code to Simple Vectored Interrupt Model
     
    80235  not originate from FreeBSD and are populated via the script.
    81236
    82 * linker section issues: I have undefined symbols for
    83   `_bsd__start_set_sysinit_set` and `_bsd__stop_set_sysinit_set`.
    84   Is this the only type of new section magic?  What about the old sysctl_set?
    85   I added this to my linkcmds. 
    86 
    87237* MAC support functions are not thread-safe ("freebsd/lib/libc/posix1e/mac.c").
    88238
     
    118268* PRINTF(9): Add support for log(), the %D format specifier is missing in the
    119269  normal printf() family.
    120 
    121 [listing]
    122 ----
    123     /* sysinit section? */
    124     . = ALIGN (16);
    125     _bsd__start_set_sysinit_set = .;
    126     *(set_sys_init_*);
    127     _bsd__stop_set_sysinit_set = .;
    128 
    129 ----
    130270
    131271* Why is the interrupt server used?  The BSD interrupt handlers can block on
     
    144284easier to insert.
    145285
    146 * rtems-bsd-init-with-irq.c:
    147   rtems_bsd_initialize_with_interrupt_server() has reference to
    148     rtems_interrupt_server_initialize() and this method is unimplemented
    149     - XXX BSP implements pieces
    150     - BSPs using this software stack must support it apparently.
    151     - What about Simple Vectored architectures?
    152 
    153 * We carried over use of notepad 0 for per task information. This should
    154 be changed.
    155 
    156 * maxproc variable referenced by rtems-bsd-resource.c.  What should it
    157 be set to?
    158 
    159 * ngroups_max variable referenced by rtems-bsd-prot.c.  - What should
    160 it be set to?
    161 
    162286* NIC Device Drivers
    163287- Only common PCI NIC drivers have been included in the initial set. These
     
    177301=== Automatically Generated FreeBSD Files
    178302
    179 The FreeBSD source tarball includes a file named Makefile.rtems which
    180 has stanzas to automatically generate some files using awk. For details
    181 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
    182 
    183 XXX This needs more detail.
     303Some source and header files are automatically generated during the FreeBSD
     304build process.  The `Makefile.todo` file performs this manually.  The should be
     305included in `freebsd-to-rtems.py` script some time in the future.  For details,
     306see also
     307http://www.freebsd.org/cgi/man.cgi?query=kobj&sektion=9&apropos=0&manpath=FreeBSD+9.2-RELEASE[KOBJ(9)].
    184308
    185309=== Rules for Modifying FreeBSD Source
    186310
    187 * Only add lines.  Subtract code by added "ifndef __rtems__". This makes
    188 merging easier in the future.
    189 
    190 == libbsd Source
    191 
    192 === What is in git
    193 
    194 The git source is a self-contained kit with FreeBSD and RTEMS components
    195 pre-merged. The Makefile in this kit is automatically generated.
    196 
    197 Any changes to sources in the freebsd or contrib directories will need to
    198 be merged upstream into our master FreeBSD svn checkout.
    199 
    200 The FreeBSD sources managed in the rtems-libbsd git repository (e.g. contrib
    201 and freebsd directories) contain the "managed" version of the
    202 FreeBSD source.  The FreeBSD SVN source is the "master" version. The
    203 freebsd-to-rtems.py script is used to transfer files between the two
    204 trees. In general terms, if you have modified FreeBSD (i.e. anything in the
    205 freebsd directory) in the rtems-libbsd tree, you will need to run the script
    206 in "revert" or "reverse" mode using the -R switch. This will copy the source
    207 back to your local copy of the FreeBSD source so you can run "svn diff" against
    208 the upstream FreeBSD source. If you want to transfer source files from the
    209 FreeBSD SVN checkout to the rtems-libbsd tree, then you must run the script in
    210 "forward" mode (the default).
    211 
    212 === Building rtems-libbsd source
    213 
    214 You need to configure RTEMS for the desired BSP and install it. The
    215 following is the script used to build the powerpc/psim BSP for our
    216 internal testing purposes:
    217 
    218 [listing]
    219 ----
    220 #! /bin/sh
    221 
    222 cd ${HOME}/newbsd
    223 rm -rf b-psim
    224 mkdir b-psim
    225 cd b-psim
    226 ../git/rtems/configure --target=powerpc-rtems4.11 \
    227   --enable-rtemsbsp=psim --disable-networking \
    228   --enable-tests=samples \
    229   --prefix=${HOME}/newbsd/bsp-install >c.log 2>&1 && \
    230   make >b.log 2>&1 && \
    231   make install >i.log 2>&1
    232 echo $?
    233 ----
    234 
    235 Then edit the file config.inc to set RTEMS_MAKEFILE_PATH appropriately
    236 to indicate the ${prefix}/${target}/${BSP}.  Continuing on the above,
    237 the config.inc used to match the above is:
    238 
    239 [listing]
    240 ----
    241 RTEMS_MAKEFILE_PATH = ${HOME}/newbsd/bsp-install/powerpc-rtems4.11/psim/
    242 INSTALL_BASE = ${HOME}/newbsd/install
    243 ----
    244 
    245 The above installs the rtems-libbsd kit into a separate place from
    246 RTEMS and the BSP. The rtems-libbsd tests are built against an installed
    247 image of the rtems-libbsd. By keeping it in a separate installation point
    248 from RTEMS itself, this makes it easier to remove a libbsd installation
    249 and have a clean test point.
    250 
    251 [listing]
    252 ----
    253 make
    254 make install
    255 make -C testsuite
    256 ----
    257 
    258 At this point, we expect multiple linker errors. That is what we are
    259 currently working on.
     311Only add lines.  Subtract code by added `#ifndef __rtems__`.  This makes
     312merging easier in the future.  For example:
     313
     314-------------------------------------------------------------------------------
     315/* Global variables for the kernel. */
     316
     317#ifndef __rtems__
     318/* 1.1 */
     319extern char kernelname[MAXPATHLEN];
     320#endif /* __rtems__ */
     321
     322extern int tick;                        /* usec per tick (1000000 / hz) */
     323-------------------------------------------------------------------------------
     324
     325-------------------------------------------------------------------------------
     326#if defined(_KERNEL) || defined(_WANT_FILE)
     327#ifdef __rtems__
     328#include <rtems/libio_.h>
     329#include <sys/fcntl.h>
     330#endif /* __rtems__ */
     331/*
     332 * Kernel descriptor table.
     333 * One entry for each open kernel vnode and socket.
     334 *
     335 * Below is the list of locks that protects members in struct file.
     336 *
     337 * (f) protected with mtx_lock(mtx_pool_find(fp))
     338 * (d) cdevpriv_mtx
     339 * none not locked
     340 */
     341-------------------------------------------------------------------------------
     342
     343-------------------------------------------------------------------------------
     344extern int profprocs;                   /* number of process's profiling */
     345#ifndef __rtems__
     346extern volatile int ticks;
     347#else /* __rtems__ */
     348#include <rtems/score/watchdogimpl.h>
     349#define ticks _Watchdog_Ticks_since_boot
     350#endif /* __rtems__ */
     351
     352#endif /* _KERNEL */
     353-------------------------------------------------------------------------------
     354
     355Add nothing (even blank lines) before or after the `__rtems__` guards.  Always
     356include a `__rtems__` in the guards to make searches easy.
     357
     358== BSD Library Source
     359
     360=== What is in the Git Repository
     361
     362There is a self-contained kit with FreeBSD and RTEMS components pre-merged. The
     363Makefile in this kit is automatically generated.
     364
     365Any changes to source in the `freebsd` directories will need to be merged
     366upstream into our master FreeBSD checkout, the `freebsd-org` submodule.
     367
     368The repository contains two FreeBSD source trees.  In the `freebsd` directory
     369are the so called 'managed' FreeBSD sources used to build the BSD library.  The
     370FreeBSD source in `freebsd-org` is the 'master' version.  The
     371`freebsd-to-rtems.py` script is used to transfer files between the two trees.
     372In general terms, if you have modified managed FreeBSD sources, you will need
     373to run the script in 'revert' or 'reverse' mode using the `-R` switch.  This
     374will copy the source back to your local copy of the master FreeBSD source so
     375you can run `git diff` against the upstream FreeBSD source.  If you want to
     376transfer source files from the master FreeBSD source to the manged FreeBSD
     377sources, then you must run the script in 'forward' mode (the default).
    260378
    261379=== Organization
    262380
    263381The top level directory contains a few directories and files. The following
    264 are important to understand:
    265 
    266 * freebsd-to-rtems.py - script to convert to and free FreeBSD and RTEMS trees
    267 * Makefile - automatically generated
    268 * contrib/ - from FreeBSD by script.
    269 * freebsd/ - from FreeBSD by script.
    270 * rtemsbsd/ - RTEMS specific implementations of FreeBSD kernel support routines.
    271 * testsuite/ - RTEMS specific tests
    272 * libbsd.txt - Documentation in Asciidoc
    273 
    274 == Moving Code Between FreeBSD SVN and rtems-libbsd
    275 
    276 The script freebsd-to-rtems.py is used to copy code from FreeBSD to the
     382are important to understand
     383
     384* `freebsd-to-rtems.py` - script to convert to and free FreeBSD and RTEMS trees,
     385* `Makefile` - automatically generated,
     386* `freebsd/` - from FreeBSD by script,
     387* `rtemsbsd/` - RTEMS specific implementations of FreeBSD kernel support routines,
     388* `testsuite/` - RTEMS specific tests, and
     389* `libbsd.txt` - documentation in Asciidoc.
     390
     391== Moving Code Between Managed and Master FreeBSD Source
     392
     393The script `freebsd-to-rtems.py` is used to copy code from FreeBSD to the
    277394rtems-libbsd tree and to reverse this process. This script attempts to
    278395automate this process as much as possible and performs some transformations
    279396on the FreeBSD code. Its command line arguments are shown below:
    280397
    281 [listing]
    282398----
    283399freebsd-to-rtems.py [args]
     
    311427The following is an example forward run with no changes.
    312428
    313 [listing]
    314429----
    315430$ ~/newbsd/git/libbsd-8.2/freebsd-to-rtems.py \
     
    329444direction.
    330445
    331 == Initialization of rtems-libbsd
    332 
    333 The initialization of the rtems-libbsd is based on the FreeBSD SYSINIT(9)
     446== Initialization of the BSD Library
     447
     448The initialization of the BSD library is based on the FreeBSD SYSINIT(9)
    334449infrastructure.  The key to initializing a system is to ensure that the desired
    335450device drivers are explicitly pulled into the linked application.  This plus
    336 linking against the libbsd library will pull in the necessary FreeBSD
     451linking against the BSD library (`libbsd.a`) will pull in the necessary FreeBSD
    337452infrastructure.
    338453
     
    354469section.  In the linker command file we need this:
    355470
    356 [listing]
    357 ----
    358 .robsdsets : {
    359     _bsd__start_set_modmetadata_set = .;
    360     *(_bsd_set_modmetadata_set);
    361     _bsd__stop_set_modmetadata_set = .;
    362     _bsd__start_set_sysctl_set = .;
    363     *(_bsd_set_sysctl_set);
    364     _bsd__stop_set_sysctl_set = .;
    365 } > REGION_RODATA AT > REGION_RODATA_LOAD
    366 
    367 .rwbsdsets : {
    368     _bsd__start_set_sysinit_set = .;
    369     *(_bsd_set_sysinit_set);
    370     _bsd__stop_set_sysinit_set = .;
    371 } > REGION_DATA AT > REGION_DATA_LOAD
    372 ----
    373 
    374 Here you can see, that these global data structures are collected into
     471-------------------------------------------------------------------------------
     472.rtemsroset : {
     473        KEEP (*(SORT(.rtemsroset.*)))
     474}
     475
     476.rtemsrwset : {
     477        KEEP (*(SORT(.rtemsrwset.*)))
     478}
     479-------------------------------------------------------------------------------
     480
     481This results for example in this executable layout:
     482
     483-------------------------------------------------------------------------------
     484[...]
     485 *(SORT(.rtemsroset.*))
     486 .rtemsroset.bsd.modmetadata_set.begin
     487                0x000000000025fe00        0x0 libbsd.a(rtems-bsd-init.o)
     488                0x000000000025fe00                _bsd__start_set_modmetadata_set
     489 .rtemsroset.bsd.modmetadata_set.content
     490                0x000000000025fe00        0x8 libbsd.a(rtems-bsd-nexus.o)
     491 .rtemsroset.bsd.modmetadata_set.content
     492                0x000000000025fe08        0x4 libbsd.a(kern_module.o)
     493[...]
     494 .rtemsroset.bsd.modmetadata_set.content
     495                0x000000000025fe68        0x4 libbsd.a(mii.o)
     496 .rtemsroset.bsd.modmetadata_set.content
     497                0x000000000025fe6c        0x4 libbsd.a(mii_bitbang.o)
     498 .rtemsroset.bsd.modmetadata_set.end
     499                0x000000000025fe70        0x0 libbsd.a(rtems-bsd-init.o)
     500                0x000000000025fe70                _bsd__stop_set_modmetadata_set
     501[...]
     502.rtemsrwset     0x000000000030bad0      0x290
     503 *(SORT(.rtemsrwset.*))
     504 .rtemsrwset.bsd.sysinit_set.begin
     505                0x000000000030bad0        0x0 libbsd.a(rtems-bsd-init.o)
     506                0x000000000030bad0                _bsd__start_set_sysinit_set
     507 .rtemsrwset.bsd.sysinit_set.content
     508                0x000000000030bad0        0x4 libbsd.a(rtems-bsd-nexus.o)
     509 .rtemsrwset.bsd.sysinit_set.content
     510                0x000000000030bad4        0x8 libbsd.a(rtems-bsd-thread.o)
     511 .rtemsrwset.bsd.sysinit_set.content
     512                0x000000000030badc        0x4 libbsd.a(init_main.o)
     513[...]
     514 .rtemsrwset.bsd.sysinit_set.content
     515                0x000000000030bd54        0x4 libbsd.a(frag6.o)
     516 .rtemsrwset.bsd.sysinit_set.content
     517                0x000000000030bd58        0x8 libbsd.a(uipc_accf.o)
     518 .rtemsrwset.bsd.sysinit_set.end
     519                0x000000000030bd60        0x0 libbsd.a(rtems-bsd-init.o)
     520                0x000000000030bd60                _bsd__stop_set_sysinit_set
     521[...]
     522-------------------------------------------------------------------------------
     523
     524Here you can see, that some global data structures are collected into
    375525continuous memory areas.  This memory area can be identified by start and stop
    376526symbols.  This constructs a table of uniform items.
     
    389539In RTEMS we have a library and not a bunch of object files.  Thus we need a way
    390540to pull-in the desired services out of the libbsd.  Here the
    391 "rtems-bsd-sysinit.h" comes into play.  The SYSINIT(9) macros have been
    392 modified and extended for RTEMS in "sys/kernel.h":
    393 
    394 [listing]
    395 ----
     541`rtems-bsd-sysinit.h` comes into play.  The SYSINIT(9) macros have been
     542modified and extended for RTEMS in `<sys/kernel.h>`:
     543
     544-------------------------------------------------------------------------------
    396545#ifndef __rtems__
    397 #define    C_SYSINIT(uniquifier, subsystem, order, func, ident) \
    398     static struct sysinit uniquifier ## _sys_init = { \
    399         subsystem, \
    400         order, \
    401         func, \
    402         (ident) \
    403     }; \
    404     DATA_SET(sysinit_set,uniquifier ## _sys_init)
     546#define C_SYSINIT(uniquifier, subsystem, order, func, ident)    \
     547        static struct sysinit uniquifier ## _sys_init = {       \
     548                subsystem,                                      \
     549                order,                                          \
     550                func,                                           \
     551                (ident)                                         \
     552        };                                                      \
     553        DATA_SET(sysinit_set,uniquifier ## _sys_init)
    405554#else /* __rtems__ */
    406 #define    SYSINIT_ENTRY_NAME(uniquifier) \
    407     _bsd_ ## uniquifier ## _sys_init
    408 #define    SYSINIT_REFERENCE_NAME(uniquifier) \
    409     _bsd_ ## uniquifier ## _sys_init_ref
    410 #define    C_SYSINIT(uniquifier, subsystem, order, func, ident) \
    411     struct sysinit SYSINIT_ENTRY_NAME(uniquifier) = { \
    412         subsystem, \
    413         order, \
    414         func, \
    415         (ident) \
    416     }; \
    417     DATA_SET(sysinit_set,SYSINIT_ENTRY_NAME(uniquifier))
    418 #define    SYSINIT_REFERENCE(uniquifier) \
    419     extern struct sysinit SYSINIT_ENTRY_NAME(uniquifier); \
    420     static struct sysinit const * const \
    421     SYSINIT_REFERENCE_NAME(uniquifier) __used \
    422     = &SYSINIT_ENTRY_NAME(uniquifier)
    423 #define    SYSINIT_MODULE_REFERENCE(mod) \
    424     SYSINIT_REFERENCE(mod ## module)
    425 #define    SYSINIT_DRIVER_REFERENCE(driver, bus) \
    426     SYSINIT_MODULE_REFERENCE(driver ## _ ## bus)
     555#define SYSINIT_ENTRY_NAME(uniquifier)                          \
     556        _bsd_ ## uniquifier ## _sys_init
     557#define SYSINIT_REFERENCE_NAME(uniquifier)                      \
     558        _bsd_ ## uniquifier ## _sys_init_ref
     559#define C_SYSINIT(uniquifier, subsystem, order, func, ident)    \
     560        struct sysinit SYSINIT_ENTRY_NAME(uniquifier) = {       \
     561                subsystem,                                      \
     562                order,                                          \
     563                func,                                           \
     564                (ident)                                         \
     565        };                                                      \
     566        RWDATA_SET(sysinit_set,SYSINIT_ENTRY_NAME(uniquifier))
     567#define SYSINIT_REFERENCE(uniquifier)                           \
     568        extern struct sysinit SYSINIT_ENTRY_NAME(uniquifier);   \
     569        static struct sysinit const * const                     \
     570        SYSINIT_REFERENCE_NAME(uniquifier) __used               \
     571        = &SYSINIT_ENTRY_NAME(uniquifier)
     572#define SYSINIT_MODULE_REFERENCE(mod)                           \
     573        SYSINIT_REFERENCE(mod ## module)
     574#define SYSINIT_DRIVER_REFERENCE(driver, bus)                   \
     575        SYSINIT_MODULE_REFERENCE(driver ## _ ## bus)
     576#define SYSINIT_DOMAIN_REFERENCE(dom)                           \
     577        SYSINIT_REFERENCE(domain_add_ ## dom)
    427578#endif /* __rtems__ */
    428 ----
     579-------------------------------------------------------------------------------
    429580
    430581Here you see that the SYSINIT(9) entries are no longer static.  The
    431 *_REFERENCE() macros will create references to the corresponding modules which
     582\*_REFERENCE() macros will create references to the corresponding modules which
    432583are later resolved by the linker.  The application has to provide an object
    433584file with references to all required FreeBSD modules.
     
    439590The devices form a tree with the Nexus device at a high-level.  This Nexus
    440591device is architecture specific in FreeBSD.  In RTEMS we have our own Nexus
    441 device, see "rtems-bsd-nexus.c".  It uses a table to add child devices:
    442 
    443 [listing]
    444 ----
    445 const char *const _bsd_nexus_devices [] = {
    446     #ifdef NEED_USB_OHCI
    447         "ohci",
    448     #endif
    449     #ifdef NEED_USB_EHCI
    450         "ehci",
    451     #endif
    452     #ifdef NEED_SDHC
    453         "sdhci",
    454     #endif
    455     NULL
    456 };
    457 ----
    458 
    459 This table must be provided by the application.
     592device, see `rtemsbsd/bsp/bsp-bsd-nexus-devices.c`.
    460593
    461594=== SYSCTL_NODE Example
     
    467600to add the "inet" node to the parent node "_net".
    468601
    469 [listing]
    470602----
    471603SYSCTL_NODE(_net,      PF_INET,         inet,   CTLFLAG_RW, 0,
     
    487619This was all generated by a support macro declaring the node as this:
    488620
    489 [listing]
    490621----
    491622struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name);
     
    495626kern/kern_mib.c
    496627
    497 [listing]
    498628----
    499629SYSCTL_NODE(, CTL_KERN,   kern,   CTLFLAG_RW, 0,
     
    610740are only used by the Nic test are the most suspect.
    611741
    612 [listing]
    613742----
    614743rtems-libbsd File:      rtems-bsd-assert.c
     
    810939== NICs Status ==
    811940
    812 [listing]
    813941----
    814942Driver                  Symbol                          Status
Note: See TracChangeset for help on using the changeset viewer.