source: rtems-libbsd/libbsd.txt @ 91ea7ea

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 91ea7ea was 91ea7ea, checked in by Sebastian Huber <sebastian.huber@…>, on 01/20/15 at 07:39:06

Add and use rtems_bsd_get_task_priority()

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