source: rtems-libbsd/libbsd.txt @ 36a16f5

5-freebsd-12freebsd-9.3
Last change on this file since 36a16f5 was 36a16f5, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 30, 2015 at 12:52:57 PM

i386: Quick and dirty hack to get PCI working

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