source: rtems-libbsd/libbsd.txt @ 4c3433b

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 4c3433b was 4c3433b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/24/14 at 15:37:21

Documentation

  • Property mode set to 100644
File size: 33.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=== 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
205* Per-CPU data should be enabled once the new stack is ready for SMP.
206
207* Per-CPU NETISR(9) should be enabled onece the new stack is ready for SMP.
208
209* Multiple routing tables are not supported.  Every FIB value is set to zero
210  (= BSD_DEFAULT_FIB).
211
212* Process identifiers are not supported.  Every PID value is set to zero
213  (= BSD_DEFAULT_PID).
214
215* User credentials are not supported.  The following functions allow the
216  operation for everyone
217  - prison_equal_ip4(),
218  - chgsbsize(),
219  - cr_cansee(),
220  - cr_canseesocket() and
221  - cr_canseeinpcb().
222
223* A basic USB functionality test that is known to work on Qemu is desirable.
224
225* Adapt generic IRQ PIC interface code to Simple Vectored Interrupt Model
226  so that those architectures can use new TCP/IP and USB code.
227
228* freebsd-userspace/rtems/include/sys/syslog.h is a copy from the old
229  RTEMS TCP/IP stack. For some reason, the __printflike markers do not
230  compile in this environment. We may want to use the FreeBSD syslog.h
231  and get this addressed.
232
233* in_cksum implementations for architectures not supported by FreeBSD.
234  This will require figuring out where to put implementations that do
235  not originate from FreeBSD and are populated via the script.
236
237* MAC support functions are not thread-safe ("freebsd/lib/libc/posix1e/mac.c").
238
239* IFCONFIG(8): IEEE80211 support is disabled.  This module depends on a XML
240  parser and mmap().
241
242* get_cyclecount(): The implementation is a security problem.
243
244* What to do with the priority parameter present in the FreeBSD synchronization
245  primitives and the thread creation functions?
246
247* TASKQUEUE(9): Support spin mutexes.
248
249* ZONE(9): Review allocator lock usage in rtems-bsd-chunk.c.
250
251* KQUEUE(2): Choose proper lock for global kqueue list.
252
253* TIMEOUT(9): Maybe use special task instead of timer server to call
254  callout_tick().
255
256* sysctl_handle_opaque(): Implement reliable snapshots.
257
258* PING6(8): What to do with SIGALARM?
259
260* <sys/param.h>: Update Newlib to use a MSIZE of 256.
261
262* BPF(4): Add support for zero-copy buffers.
263
264* UNIX(4): Fix race conditions in the area of socket object and file node
265  destruction.  Add support for file descriptor transmission via control
266  messages.
267
268* PRINTF(9): Add support for log(), the %D format specifier is missing in the
269  normal printf() family.
270
271* Why is the interrupt server used?  The BSD interrupt handlers can block on
272synchronization primitives like mutexes.  This is in contrast to RTEMS
273interrupt service routines.  The BSPs using the generic interrupt support must
274implement the `bsp_interrupt_vector_enable()` and
275`bsp_interrupt_vector_disable()` routines.  They normally enable/disable a
276particular interrupt source at the interrupt controller.  This can be used to
277implement the interrupt server.  The interrupt server is a task that wakes-up
278in case an associated interrupt happens.  The interrupt source is disabled in
279a generic interrupt handler that wakes-up the interrupt server task.   Once the
280postponed interrupt processing is performed in the interrupt server the
281interrupt source is enabled again.
282
283* Convert all BSP linkcmds to use a linkcmds.base so the sections are
284easier to insert.
285
286* NIC Device Drivers
287- Only common PCI NIC drivers have been included in the initial set. These
288do not include any system on chip or ISA drivers.
289- PCI configuration probe does not appear to happen to determine if a
290NIC is in I/O or memory space. We have worked around this by using a
291static hint to tell the fxp driver the correct mode. But this needs to
292be addressed.
293- The ISA drivers require more BSD infrastructure to be addressed. This was
294outside the scope of the initial porting effort.
295
296== FreeBSD Source
297
298You should be able to rely on FreebSD manual pages and documentation
299for details on the code itself.
300
301=== Automatically Generated FreeBSD Files
302
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)].
308
309=== Rules for Modifying FreeBSD Source
310
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).
378
379=== Organization
380
381The top level directory contains a few directories and files. The following
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
394rtems-libbsd tree and to reverse this process. This script attempts to
395automate this process as much as possible and performs some transformations
396on the FreeBSD code. Its command line arguments are shown below:
397
398----
399freebsd-to-rtems.py [args]
400  -?|-h|--help     print this and exit
401  -d|--dry-run     run program but no modifications
402  -D|--diff        provide diff of files between trees
403  -e|--early-exit  evaluate arguments, print results, and exit
404  -m|--makefile    just generate Makefile
405  -R|--reverse     default FreeBSD -> RTEMS, reverse that
406  -r|--rtems       RTEMS directory
407  -f|--freebsd     FreeBSD directory
408  -v|--verbose     enable verbose output mode
409----
410
411In its default mode of operation, freebsd-to-rtems.py is used to copy code
412from FreeBSD to the rtems-libbsd tree and perform transformations.  In forward
413mode, the script may be requested to just generate the Makefile.
414
415In "reverse mode", this script undoes those transformations and copies
416the source code back to the FreeBSD SVN tree. This allows us to do
417'svn diff', evaluate changes made by the RTEMS Project, and report changes
418back to FreeBSD upstream.
419
420In either mode, the script may be asked to perform a dry-run or be verbose.
421Also, in either mode, the script is also smart enough to avoid copying over
422files which have not changed. This means that the timestamps of files are
423not changed unless the contents change. The script will also report the
424number of files which changed. In verbose mode, the script will print
425the name of the files which are changed.
426
427The following is an example forward run with no changes.
428
429----
430$ ~/newbsd/git/libbsd-8.2/freebsd-to-rtems.py \
431    -r /home/joel/newbsd/git/libbsd-8.2 \
432    -f /home/joel/newbsd/libbsd/freebsd-8.2 -v
433Verbose:                yes
434Dry Run:                no
435Only Generate Makefile: no
436RTEMS Directory:        /home/joel/newbsd/git/libbsd-8.2
437FreeBSD Directory:      /home/joel/newbsd/libbsd/freebsd-8.2
438Direction:              forward
439Generating into /home/joel/newbsd/git/libbsd-8.2
4400 files were changed.
441----
442
443The script may also be used to generate a diff in either forward or reverse
444direction.
445
446== Initialization of the BSD Library
447
448The initialization of the BSD library is based on the FreeBSD SYSINIT(9)
449infrastructure.  The key to initializing a system is to ensure that the desired
450device drivers are explicitly pulled into the linked application.  This plus
451linking against the BSD library (`libbsd.a`) will pull in the necessary FreeBSD
452infrastructure.
453
454The FreeBSD kernel is not a library like the RTEMS kernel.  It is a bunch of
455object files linked together.  If we have a library, then creating the
456executable is simple.  We begin with a start symbol and recursively resolve all
457references.  With a bunch of object files linked together we need a different
458mechanism.  Most object files don't know each other.  Lets say we have a driver
459module.  The rest of the system has no references to this driver module.  The
460driver module needs a way to tell the rest of the system: Hey, kernel I am
461here, please use my services!
462
463This registration of independent components is performed by SYSINIT(9) and
464specializations:
465
466http://www.freebsd.org/cgi/man.cgi?query=SYSINIT
467
468The SYSINIT(9) uses some global data structures that are placed in a certain
469section.  In the linker command file we need this:
470
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
525continuous memory areas.  This memory area can be identified by start and stop
526symbols.  This constructs a table of uniform items.
527
528The low level FreeBSD code calls at some time during the initialization the
529mi_startup() function (machine independent startup).  This function will sort
530the SYSINIT(9) set and call handler functions which perform further
531initialization.  The last step is the scheduler invocation.
532
533The SYSINIT(9) routines are run in mi_startup() which is called by
534rtems_bsd_initialize().
535
536This is also explained in "The Design and Implementation of the FreeBSD
537Operating System" section 14.3 "Kernel Initialization".
538
539In RTEMS we have a library and not a bunch of object files.  Thus we need a way
540to pull-in the desired services out of the libbsd.  Here the
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-------------------------------------------------------------------------------
545#ifndef __rtems__
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)
554#else /* __rtems__ */
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)
578#endif /* __rtems__ */
579-------------------------------------------------------------------------------
580
581Here you see that the SYSINIT(9) entries are no longer static.  The
582\*_REFERENCE() macros will create references to the corresponding modules which
583are later resolved by the linker.  The application has to provide an object
584file with references to all required FreeBSD modules.
585
586The FreeBSD device model is quite elaborated (with follow-ups):
587
588http://www.freebsd.org/cgi/man.cgi?query=driver
589
590The devices form a tree with the Nexus device at a high-level.  This Nexus
591device is architecture specific in FreeBSD.  In RTEMS we have our own Nexus
592device, see `rtemsbsd/bsp/bsp-bsd-nexus-devices.c`.
593
594=== SYSCTL_NODE Example
595
596During development, we had an undefined reference to
597_bsd_sysctl__net_children that we had trouble tracking down. Thanks to
598Chris Johns, we located it. He explained how to read SYSCTL_NODE
599definitions. This line from freebsd/netinet/in_proto.c is attempting
600to add the "inet" node to the parent node "_net".
601
602----
603SYSCTL_NODE(_net,      PF_INET,         inet,   CTLFLAG_RW, 0,
604        "Internet Family");
605----
606
607Our problem was that we could not find where _bsd_sysctl__net_children
608was defined. Chris suggested that when in doubt compile with -save-temps
609and look at the preprocessed .i files. But he did not need that. He
610explained that this the symbol name _bsd_sysctl__net_children was
611automatically generated by a SYSCTL_NODE as follows:
612
613* _bsd_ - added by RTEMS modifications to SYSCTL_NODE macro
614* sysctl_ - boilerplace added by SYSCTL_NODE macro
615* "" - empty string for parent node
616* net - name of SYSCTL_NODE
617* children - added by SYSCTL macros
618 
619This was all generated by a support macro declaring the node as this:
620
621----
622struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name);
623----
624
625Given this information, we located this SYSCTL_NODE declaration in
626kern/kern_mib.c
627
628----
629SYSCTL_NODE(, CTL_KERN,   kern,   CTLFLAG_RW, 0,
630        "High kernel, proc, limits &c");
631----
632
633== Core FreeBSD APIs and RTEMS Replacements ==
634
635=== SX(9) (Shared/exclusive locks) ===
636
637http://www.freebsd.org/cgi/man.cgi?query=sx
638
639Binary semaphores (this neglects the ability to allow shared access).
640
641=== MUTEX(9) (Mutual exclusion) ===
642
643http://www.freebsd.org/cgi/man.cgi?query=mutex
644
645Binary semaphores (not recursive mutexes are not supported this way).
646
647=== RWLOCK(9) (Reader/writer lock) ===
648
649http://www.freebsd.org/cgi/man.cgi?query=rwlock
650
651POSIX r/w lock.
652
653=== RMLOCK(9) (Reader/writer lock optimized for mostly read access patterns) ===
654
655Note:  This object was implemented as a wrapper for RWLOCK in the rm_lock header file.
656
657http://www.freebsd.org/cgi/man.cgi?query=rmlock
658
659POSIX r/w lock.
660
661=== CONDVAR(9) (Condition variables) ===
662
663http://www.freebsd.org/cgi/man.cgi?query=condvar
664
665POSIX condition variables with modifications (hack).
666
667=== CALLOUT(9) (Timer functions) ===
668
669http://www.freebsd.org/cgi/man.cgi?query=callout
670
671Timer server.
672
673=== TASKQUEUE(9) (Asynchronous task execution) ===
674
675http://www.freebsd.org/cgi/man.cgi?query=taskqueue
676
677TBD.
678
679=== KTHREAD(9), KPROC(9) (Tasks) ===
680
681http://www.freebsd.org/cgi/man.cgi?query=kthread
682
683http://www.freebsd.org/cgi/man.cgi?query=kproc
684
685Tasks.
686
687=== ZONE(9) (Zone allocator) ===
688
689http://www.freebsd.org/cgi/man.cgi?query=zone
690
691TBD.
692
693=== devfs (Device file system) ===
694
695Dummy, IMFS or new implementation (currently dummy).
696
697=== psignal (Signals) ===
698
699TBD.  Seems to be not needed.
700
701=== poll, select ===
702
703TBD.  Seems to be not needed.
704
705=== RMAN(9) (Resource management) ===
706
707http://www.freebsd.org/cgi/man.cgi?query=rman
708
709TBD.  Seems to be not needed.
710
711=== DEVCLASS(9), DEVICE(9), DRIVER(9), MAKE_DEV(9) (Device management) ===
712
713http://www.freebsd.org/cgi/man.cgi?query=devclass
714
715http://www.freebsd.org/cgi/man.cgi?query=device
716
717http://www.freebsd.org/cgi/man.cgi?query=driver
718
719http://www.freebsd.org/cgi/man.cgi?query=make_dev
720
721Use FreeBSD implementation as far as possible.  FreeBSD has a nice API for
722dynamic device handling.  It may be interesting for RTEMS to use this API
723internally in the future.
724
725=== BUS_SPACE(9), BUS_DMA(9) (Bus and DMA access) ===
726
727http://www.freebsd.org/cgi/man.cgi?query=bus_space
728
729http://www.freebsd.org/cgi/man.cgi?query=bus_dma
730
731Likely BSP dependent.  A default implementation for memory mapped linear access
732is easy to provide.  The current heap implementation supports all properties
733demanded by bus_dma (including the boundary constraint).
734
735== RTEMS Replacements by File Description ==
736
737Note:  Files with a status of USB are used by the USB test and have at least
738been partially tested.  If they contain both USB and Nic, then they are used
739by both and MAY contain methods that have not been tested yet.  Files that
740are only used by the Nic test are the most suspect.
741
742----
743rtems-libbsd File:      rtems-bsd-assert.c
744FreeBSD File:           rtems-bsd-config.h redefines BSD_ASSERT.
745Description:            This file contains the support method rtems_bsd_assert_func().
746Status:                 USB, Nic
747
748rtems-libbsd File:      rtems-bsd-autoconf.c
749FreeBSD File:           FreeBSD has BSP specific autoconf.c
750Description:            This file contains configuration methods that are used to setup the system.
751Status:                 USB
752
753rtems-libbsd File:      rtems-bsd-bus-dma.c
754FreeBSD File:           FreeBSD has BSP specific busdma_machdep.c
755Description:           
756Status:                 USB, Nic
757
758rtems-libbsd File:      rtems-bsd-bus-dma-mbuf.c       
759FreeBSD File:           FreeBSD has BSP specific busdma_machdep.c
760Description:           
761Status:                 Nic
762
763rtems-libbsd File:      rtems-bsd-callout.c             
764FreeBSD File:           kern/kern_timeout.c
765Description:           
766Status:                 USB, Nic
767
768rtems-libbsd File:      rtems-bsd-cam.c
769FreeBSD File:           cam/cam_sim.c
770Description:           
771Status:                 USB
772
773rtems-libbsd File:      rtems-bsd-condvar.c             
774FreeBSD File:           kern/kern_condvar.c
775Description:           
776Status:                 USB
777
778rtems-libbsd File:      rtems-bsd-copyinout.c
779FreeBSD File:           bsp specific copyinout.c )
780Description:            Note: The FreeBSD file is split with some methods being in rtems-bsd-support
781Status:                 Nic
782
783rtems-libbsd File:      rtems-bsd-delay.c
784FreeBSD File:           bsp specific file with multiple names
785Description:           
786Status:                 USB, Nic
787
788rtems-libbsd File:      rtems-bsd-descrip.c
789FreeBSD File:           kern/kern_descrip.c
790Description:           
791Status:                 Nic
792
793rtems-libbsd File:      rtems-bsd-generic.c             
794FreeBSD File:           kern/sys_generic.c
795Description:           
796Status:                 Nic
797
798rtems-libbsd File:      rtems-bsd-init.c
799FreeBSD File:           N/A
800Description:           
801Status:                 USB, Nic
802
803rtems-libbsd File:      rtems-bsd-init-with-irq.c
804FreeBSD File:           N/A
805Description:           
806Status:                 USB, Nic
807
808rtems-libbsd File:      rtems-bsd-jail.c
809FreeBSD File:           kern/kern_jail.c
810Description:           
811Status:                 USB, Nic
812
813rtems-libbsd File:      rtems-bsd-lock.c
814FreeBSD File:           kern/subr_lock.c
815Description:           
816Status:                 USB, Nic
817
818rtems-libbsd File:      rtems-bsd-log.c         
819FreeBSD File:           kern/subr_prf.c
820Description:           
821Status:                 Nic
822
823rtems-libbsd File:      rtems-bsd-malloc.c
824FreeBSD File:           kern/kern_malloc.c
825Description:           
826Status:                 USB, Nic
827
828rtems-libbsd File:      rtems-bsd-mutex.c
829FreeBSD File:           kern/kern_mutex.c
830Description:           
831Status:                 USB, Nic
832
833rtems-libbsd File:      rtems-bsd-newproc.c
834FreeBSD File:           N/A
835Description:           
836Status:                 Nic
837
838rtems-libbsd File:      rtems-bsd-nexus.c
839FreeBSD File:           bsp specific nexus.c
840Description:           
841Status:                 USB
842
843rtems-libbsd File:      rtems-bsd-panic.c               
844FreeBSD File:           boot/common/panic.c
845Description:           
846Status:                 USB, Nic
847
848rtems-libbsd File:      rtems-bsd-rwlock.c             
849FreeBSD File:           kern_rwlock.c
850Description:           
851Status:                 USB, Nic
852
853rtems-libbsd File:      rtems-bsd-shell.c               
854FreeBSD File:           N/A
855Description:           
856Status:                 USB
857
858rtems-libbsd File:      rtems-bsd-signal.c             
859FreeBSD File:           kern/kern_sig.c
860Description:           
861Status:                 Nic
862
863rtems-libbsd File:      rtems-bsd-smp.c                 
864FreeBSD File:           N/A
865Description:           
866Status:                 Nic
867
868rtems-libbsd File:      rtems-bsd-support.c             
869FreeBSD File:           bsp specific copyinout.c
870Description:            Note: the FreeBSD file is split with some methods being in rtems-bsd-copyinout.
871Status:                 USB, Nic
872
873rtems-libbsd File:      rtems-bsd-sx.c                 
874FreeBSD File:           kern/kern_sx.c
875Description:            Status: USB, Nic
876
877rtems-libbsd File:      rtems-bsd-synch.c               
878FreeBSD File:           kern/kern_synch.c
879Description:           
880Status:                 USB, Nic
881
882rtems-libbsd File:      rtems-bsd-syscalls.c           
883FreeBSD File:           User API for kern/uipc_syscalls.c
884Description:           
885Status:                 Nic
886
887rtems-libbsd File:      rtems-bsd-sysctlbyname.c       
888FreeBSD File:           User API for sysctlbyname(3)
889Description:           
890Status:
891
892rtems-libbsd File:      rtems-bsd-sysctl.c             
893FreeBSD File:           User API for sysctl(8)
894Description:           
895Status:
896
897rtems-libbsd File:      rtems-bsd-sysctlnametomib.c     
898FreeBSD File:           User API for sysctlnametomib
899Description:           
900Status:
901
902rtems-libbsd File:      rtems-bsd-taskqueue.c           
903FreeBSD File:           kern/subr_taskqueue.c
904Description:           
905Status:                 Nic
906
907rtems-libbsd File:      rtems-bsd-thread.c                     
908FreeBSD File:           kern/kern_kthread.c
909Description:           
910Status:                 USB, Nic
911
912rtems-libbsd File:      rtems-bsd-timeout.c             
913FreeBSD File:           kern/kern_timeout.c
914Description:           
915Status:                 Nic
916
917rtems-libbsd File:      rtems-bsd-timesupport.c         
918FreeBSD File:           kern/kern_clock.c
919Description:           
920Status:                 Nic
921
922rtems-libbsd File:      rtems-bsd-vm_glue.c             
923FreeBSD File:           vm/vm_glue.c
924Description:           
925Status:                 USB, Nic
926----
927
928== Notes by File ==
929
930altq_subr.c - Arbitrary choices were made in this file that RTEMS would
931not support tsc frequency change.  Additionally, the clock frequency
932for machclk_freq is always measured for RTEMS.
933
934conf.h - In order to add make_dev and destroy_dev, variables in the cdev
935structure that were not being used were conditionally compiled out. The
936capability of supporting children did not appear to be needed and was
937not implemented in the rtems version of these routines.
938 
939== NICs Status ==
940
941----
942Driver                  Symbol                          Status
943======                  ======                          ======
944RealTek                 _bsd_re_pcimodule_sys_init      Links
945EtherExpress            _bsd_fxp_pcimodule_sys_init     Links
946DEC tulip               _bsd_dc_pcimodule_sys_init      Links
947Broadcom BCM57xxx       _bsd_bce_pcimodule_sys_init     Links
948Broadcom BCM4401        _bsd_bfe_pcimodule_sys_init     Links
949Broadcom BCM570x        _bsd_bge_pcimodule_sys_init     Needs Symbols (A)
950E1000 IGB               _bsd_igb_pcimodule_sys_init     Links
951E1000 EM                _bsd_em_pcimodule_sys_init      Links
952----
953
954
955Symbols (A)
956         pci_get_vpd_ident
957 
958== Problems to report to FreeBSD ==
959
960The MMAP_NOT_AVAILABLE define is inverted on its usage.  When it is
961defined the mmap method is called. Additionally, it is not used
962thoroughly. It is not used in the unmap portion of the source.
963The file rec_open.c uses the define MMAP_NOT_AVAILABLE to wrap
964the call to mmap and file rec_close.c uses the munmap method.
965
966
967
Note: See TracBrowser for help on using the repository browser.